Skip to main content

使用Python3进行编写的一个开源系统管理工具, 通过封装Linux系统都软件包管理、磁盘管理、文件管理、网络管理、安全管理、服务管理等内容从而实现快速开发的效果

Project description

PythonLinuxBasicModule

由于工作中需要编写大量的Linux平台管理脚本、而其中大部分代码都是重复的,所以为了更好的开发效率,我决定将日常Linux管理脚本中用到的基础功能集合起来并使用开源都方式共享,同时也希望有更多人能够一起完善。

简介

PythonLinuxBasicModule Gitee项目(Python Linux基础模块: plbm)是使用Python3进行编写的一个开源系统管理工具, 通过封装Linux系统都软件包管理、磁盘管理、文件管理、网络管理、安全管理、服务管理等内容从而实现快速开发的效果。

特色

  • 使用全中文注释,即使小白也能轻松上手
  • 完全使用内置模块进行开发,拿来即用
  • 使用Python基础语法进行编写,兼容新旧版本Python3,告别语法冲突(例如3.5及以下版本无法使用f"{}"语法)
  • 完全开源、永久免费

更新内容

1.4.6

  • 修正新模块异常

使用方法

安装

具体可以访问Pypi项目地址https://pypi.org/project/plbm-liumou-Stable/

安装-作为系统/用户模块

pip3 install --upgrade plbm_liumou_Stable ColorInfo -i https://pypi.tuna.tsinghua.edu.cn/simple

安装-作为项目模块

直接进入你的项目根目录,然后执行下面的命令即可

git clone https://gitee.com/liumou_site/PythonLinuxBasicModule.git
cd PythonLinuxBasicModule
python3 install.py

Demo

包管理

root@l:~/data/git/PythonLinuxBasicModule/demo# cat package.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    :   当前文件作用
"""
from plbm_liumou_Stable import NewPackageManagement
from ColorInfo import ColorLogger



class ServiceManager:
	def __init__(self, pac, password):
		self.package = pac
		self.pac = NewPackageManagement(password=password, package="vsftpd")
		self.logger = ColorLogger(class_name=self.__class__.__name__)

	def remove(self):
		if self.pac.installed():
			self.logger.info(f"已安装: {self.package}")
			if self.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# python3 package.py 
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.12) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
2023-01-06 22:42:31 Jurisdiction.py  line: 79 - Class: Jurisdiction Function: verification - INFO : 已处于root权限
2023-01-06 22:42:31 Cmd.py  line: 188 - Class: ComMand Function: getout - DEBUG : dpkg -s vsftpd
2023-01-06 22:42:31 Package.py  line: 141 - Class: NewPackageManagement Function: installed - INFO : 已安装: vsftpd
2023-01-06 22:42:31 package.py  line: 23 - Class: ServiceManager Function: remove - INFO : 已安装: vsftpd
2023-01-06 22:42:31 Dpkg.py  line: 113 Function: uninstall - INFO : UnInstalling UnInstall vsftpd ...
(Reading database ... 92009 files and directories currently installed.)
Removing vsftpd (3.0.3-12) ...
Purging configuration files for vsftpd (3.0.3-12) ...
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for systemd (241-7~deb10u8) ...
[ UnInstall vsftpd ] 执行成功
2023-01-06 22:42:36 package.py  line: 25 - Class: ServiceManager Function: remove - INFO : 卸载成功: vsftpd

服务管理-Demo

root@l:~/data/git/PythonLinuxBasicModule# cat demo.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    :   当前文件作用
"""
from plbm_liumou_Stable import NewServiceManagement
from ColorInfo import ColorLogger


class ServiceManager:
	def __init__(self, services, password):
		self.services = services
		self.manager = NewServiceManagement(service=services, password=password)
		self.logger = ColorLogger(class_name=self.__class__.__name__)

	def restart(self):
		if self.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# python3 demo.py 
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.12) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
[ 重载服务配置 ] 执行成功
[ Restart vsftpd ] 执行成功
2023-01-06 22:36:41 Service.py  line: 141 - Class: NewServiceManagement Function: restart - INFO : 重启成功: vsftpd
2023-01-06 22:36:41 demo.py  line: 23 - Class: ServiceManager Function: restart - INFO : 服务重启成功
root@l:~/data/git/PythonLinuxBasicModule# 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plbm_liumou_stable-1.4.8.tar.gz (67.8 kB view details)

Uploaded Source

Built Distribution

plbm_liumou_stable-1.4.8-py3-none-any.whl (77.8 kB view details)

Uploaded Python 3

File details

Details for the file plbm_liumou_stable-1.4.8.tar.gz.

File metadata

  • Download URL: plbm_liumou_stable-1.4.8.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for plbm_liumou_stable-1.4.8.tar.gz
Algorithm Hash digest
SHA256 aa9eb165a6d3b94bf720fdcd03f383fc06af2fa41c335d4e43962ff527503b7c
MD5 a995310de5ffa5ee4c2b9f3e6ef7a2ab
BLAKE2b-256 aad1d6d1ead4725e85ef57f4d44eca4b19b97cd941367245b884fae29e150301

See more details on using hashes here.

File details

Details for the file plbm_liumou_stable-1.4.8-py3-none-any.whl.

File metadata

File hashes

Hashes for plbm_liumou_stable-1.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a62db7576dc0b3f156142514fede9c12fe0108dd51fa3f0f942af07c9fc77c90
MD5 37e69502606c9693ff5a7352e8cf81a9
BLAKE2b-256 65fddf67aa2d258ae001a4fa6deda315ba68f95a6f420c5611b39fc396f6cfda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page