编写limit和system_bus_list脚本

This commit is contained in:
chenxinquan 2024-06-18 11:19:12 +08:00
parent e304e3e6b7
commit 8a955b3958
2 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,91 @@
import subprocess
import os
import sys
import shutil
def remove_file(file_path):
if os.path.exists(file_path):
os.remove(file_path)
#print(f"文件 {file_path} 已被删除")
def copy_file(source_path, backup_path):
try:
shutil.copy2(source_path, backup_path)
#print(f"文件已成功从 {source_path} 复制到 {backup_path}")
except IOError as e:
print(f"文件复制失败: {e}")
def add_limit(limit_file):
data_to_write =f"""[servicecontrol]
status=off
"""
with open(limit_file, 'w') as file:
file.write(data_to_write)
def popen_exec(command):
#print(f"command: {command}")
process = subprocess.Popen(command, stdout=subprocess.PIPE)
stdout, stderr = process.communicate()
stdout_str = stdout.decode('utf-8')
return stdout_str
def calc_verify(limit_file,arch):
calc_prog_path=f"{os.getcwd()}/../data/DBus/SystemBus/calc_verify_{arch}"
absolute_path = os.path.abspath(calc_prog_path)
command = [absolute_path,limit_file]
verify=popen_exec(command)
#print(f"verify:{verify}")
with open(f"{limit_file}.verify", 'w') as file:
file.write(verify)
return
def bakup_limit(dbusname,arch):
try:
limit_file="/etc/dbus-1/conf/"+dbusname+".limit"
bak_limit_file=limit_file+".bak"
verify_file="/etc/dbus-1/conf/"+dbusname+".limit.verify"
bak_verify_file=verify_file+".bak"
tmp_limit_file=limit_file+".tmp"
tmp_verify_file=tmp_limit_file+".verify"
if (not os.path.isfile(bak_limit_file)) and (not os.path.isfile(bak_verify_file)) and os.path.isfile(limit_file) and os.path.isfile(verify_file):
copy_file(limit_file,bak_limit_file)
copy_file(verify_file,bak_verify_file)
#prog_path=os.getcwd()+"/../data/DBus/SystemBus/system_bus_check.py"
#absolute_path = os.path.abspath(prog_path)
#print(f"absolute_path={absolute_path}")
add_limit(tmp_limit_file)
calc_verify(tmp_limit_file,arch)
copy_file(tmp_verify_file,verify_file)
copy_file(tmp_limit_file,limit_file)
remove_file(tmp_verify_file)
remove_file(tmp_limit_file)
except Exception as e:
print(f"bakup_limit failed: {e}")
def restore_limit(dbusname,arch):
try:
limit_file="/etc/dbus-1/conf/"+dbusname+".limit"
bak_limit_file=limit_file+".bak"
verify_file="/etc/dbus-1/conf/"+dbusname+".limit.verify"
bak_verify_file=verify_file+".bak"
if os.path.isfile(bak_limit_file) and os.path.isfile(bak_verify_file):
copy_file(bak_verify_file,verify_file)
copy_file(bak_limit_file,limit_file)
remove_file(bak_limit_file)
remove_file(bak_verify_file)
except Exception as e:
print(f"restore_limit failed: {e}")
if __name__ == '__main__':
if len(sys.argv) <= 3:
print('\n%s -h for help.' % (sys.argv[0]))
exit(0)
if sys.argv[1] == "bakup":
bakup_limit(sys.argv[2],sys.argv[3])
elif sys.argv[1] == "restore":
restore_limit(sys.argv[2],sys.argv[3])

View File

@ -0,0 +1,47 @@
FormatVer: 20240508
ListNames:
- org.ukui.GreeterDaemon
- com.kylin.file.system.fuse
- com.ukui.search.qt.systemdbus
- com.kylin.network.enhancement.optimization
- com.kylin.screen.rotation
- com.settings.daemon.qt.systemdbus
- org.ukui.powermanagement
- com.miracast.uibcctl
- com.kylin.systemupgrade
- com.kylin.daq
- com.ksc.virus
- org.freedesktop.activation
- org.ukui.Biometric
- org.ukui.libinput.proxy
- com.kysec.auth
- com.kylin.software.properties
- com.kylin.secriskbox
- com.kylin.system.proxy
- com.kylin.kydevmonit.domainhook
- com.kylin.UpgradeStrategies
- com.ukui.bluetooth
- com.kylin.backupserver
- com.kylin.backup
- com.kylin.ProcessManagerDaemon
- org.freedesktop.miracle.wifi
- com.kylin-os-manager
- com.ksc.scan
- com.kylin.connectivity.manager
- com.kylin.preinstall
- com.ksc.kysdkinit
- com.kylin.boxmanage
- com.kylin.logview
- com.kylin.network.qt.systemdbus
- com.kylin.os.manager.sessionbus
- com.kylin.os.manager.systembus
- com.kylinusbcreator.systemdbus
- org.ukui.groupmanager
- org.ukui.KSplash
- org.ukui.samba.share.config
- com.kylin.kim.backend
- com.ksc.defender
- com.drivermanager.USBMonitor
- com.control.center.qt.systemdbus
- com.kylin.kydoctor
- com.kylin.kysdk.conf2