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.6.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

plbm_liumou_stable-1.4.6-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: plbm_liumou_stable-1.4.6.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for plbm_liumou_stable-1.4.6.tar.gz
Algorithm Hash digest
SHA256 767f133a9b25b1246d820f5d446c6fb71fa7f1608e4b8fc4d6c6947b8a7cac3e
MD5 02f4ffe3050ea7f71f615ec3493703d6
BLAKE2b-256 55ea92bcbcb8c8bc9e963b6b4e2709bb1946046cd9d9f31e6b64b548221ae5f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for plbm_liumou_stable-1.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fc6adccd21daa64a7ba4d9af29750dfea3a3b72f3949d1907d5061d1c2907792
MD5 361f20017410d394f639424c265539d3
BLAKE2b-256 e289abaecba7b13c611ffb9587d79fb9adf487b1e8324381665a1a8682e1f3f3

See more details on using hashes here.

Supported by

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