Package: plbm-liuyi778-Stable
PythonLinuxBasicModule由于工作中需要编写大量的Linux平台管理脚本、而其中大部分代码都是重复的，所以为了更好的开发效率，我决定将日常Linux管理脚本中用到的基础功能集合起来并使用开源都方式共享，同时也希望有更多人能够一起完善。简介PythonLinuxBasicModule Gitee项目（Python Linux基础模块:plbm）是使用Python3进行编写的一个开源系统管理工具，
通过封装Linux系统都软件包管理、磁盘管理、文件管理、网络管理、安全管理、服务管理等内容从而实现快速开发的效果。特色使用全中文注释，即使小白也能轻松上手完全使用内置模块进行开发，拿来即用使用Python基础语法进行编写，兼容新旧版本Python3，告别语法冲突(例如3.5及以下版本无法使用f"{}"语法)完全开源、永久免费更新内容1.2.9默认关闭权限验证文本日志功能使用方法安装具体可以访问Pypi项目地址https://pypi.org/project/plbm安装-作为系统/用户模块pip3install--upgradeplbm_liuyi778_StableColorInfo-ihttps://pypi.tuna.tsinghua.edu.cn/simple安装-作为项目模块直接进入你的项目根目录,然后执行下面的命令即可gitclonehttps://gitee.com/liumou_site/PythonLinuxBasicModule.gitcdPythonLinuxBasicModule
python3install.pyDemo包管理root@l:~/data/git/PythonLinuxBasicModule/demo#catpackage.py# -*- encoding: utf-8 -*-"""@File    :   demo.py@Time    :   2022-10-24 22:45@Author  :   坐公交也用券@Version :   1.0@Contact :   faith01238@hotmail.com@Homepage : https://liumou.site@Desc    :   当前文件作用"""fromplbm_liuyi778_StableimportPackageManagement
fromColorInfoimportColorLogger


classServiceManager:def__init__(self,pac,password):self.package=pacself.pac=PackageManagement(password=password,package="vsftpd")self.logger=ColorLogger(class_name=self.__class__.__name__)defremove(self):ifself.pac.installed():self.logger.info(f"已安装: {self.package}")ifself.pac.uninstall():self.logger.info(f"卸载成功: {self.package}")else:self.logger.error(f"卸载失败: {self.package}")else:self.logger.warning(f"未安装: {self.package}")if__name__=="__main__":demo=ServiceManager(pac="vsftpd",password="demo")demo.remove()root@l:~/data/git/PythonLinuxBasicModule/demo#python3package.py/usr/lib/python3/dist-packages/requests/__init__.py:91:RequestsDependencyWarning:urllib3(1.26.12)orchardet(3.0.4)doesn'tmatchasupportedversion!RequestsDependencyWarning)2023-01-0622:42:31Jurisdiction.pyline:79-Class:JurisdictionFunction:verification-INFO:已处于root权限2023-01-0622:42:31Cmd.pyline:188-Class:ComMandFunction:getout-DEBUG:dpkg-svsftpd2023-01-0622:42:31Package.pyline:141-Class:PackageManagementFunction:installed-INFO:已安装:vsftpd2023-01-0622:42:31package.pyline:23-Class:ServiceManagerFunction:remove-INFO:已安装:vsftpd2023-01-0622:42:31Dpkg.pyline:113Function:uninstall-INFO:UnInstallingUnInstallvsftpd...(Readingdatabase...92009filesanddirectoriescurrentlyinstalled.)Removingvsftpd(3.0.3-12)...
Purgingconfigurationfilesforvsftpd(3.0.3-12)...
locale:CannotsetLC_MESSAGEStodefaultlocale:Nosuchfileordirectory
locale:CannotsetLC_ALLtodefaultlocale:Nosuchfileordirectory
Processingtriggersforman-db(2.8.5-2)...
Processingtriggersforsystemd(241-7~deb10u8)...[UnInstallvsftpd]执行成功2023-01-0622:42:36package.pyline:25-Class:ServiceManagerFunction:remove-INFO:卸载成功:vsftpd服务管理-Demoroot@l:~/data/git/PythonLinuxBasicModule#catdemo.py# -*- encoding: utf-8 -*-"""@File    :   demo.py@Time    :   2022-10-24 22:45@Author  :   坐公交也用券@Version :   1.0@Contact :   faith01238@hotmail.com@Homepage : https://liumou.site@Desc    :   当前文件作用"""fromplbm_liuyi778_StableimportServiceManagement
fromColorInfoimportColorLogger


classServiceManager:def__init__(self,services,password):self.services=servicesself.manager=ServiceManagement(service=services,password=password)self.logger=ColorLogger(class_name=self.__class__.__name__)defrestart(self):ifself.manager.restart(reload=True):self.logger.info("服务重启成功")else:self.logger.warning("服务重启失败")if__name__=="__main__":demo=ServiceManager(services="vsftpd",password="demo")demo.restart()root@l:~/data/git/PythonLinuxBasicModule#python3demo.py/usr/lib/python3/dist-packages/requests/__init__.py:91:RequestsDependencyWarning:urllib3(1.26.12)orchardet(3.0.4)doesn'tmatchasupportedversion!RequestsDependencyWarning)[重载服务配置]执行成功[Restartvsftpd]执行成功2023-01-0622:36:41Service.pyline:141-Class:ServiceManagementFunction:restart-INFO:重启成功:vsftpd2023-01-0622:36:41demo.pyline:23-Class:ServiceManagerFunction:restart-INFO:服务重启成功
root@l:~/data/git/PythonLinuxBasicModule#