adjust timezone of background scheduler;adjust autoupgrade interface

This commit is contained in:
yafeng shen 2023-06-02 11:42:06 +08:00
parent 0cc1ad39e5
commit 9b50a0e0fe
1 changed files with 21 additions and 7 deletions

View File

@ -254,6 +254,7 @@ def FindRuningUnattendedUpgrades():
def ReadValueFromFile(file,section,option):
config=configparser.ConfigParser(allow_no_value=True)
config.optionxform = str
value = ''
try:
config.read(file)
value = config[section][option]
@ -497,7 +498,7 @@ class KylinSystemUpdater:
DBusGMainLoop(set_as_default=True)
self.loop = GLib.MainLoop()
self.system_bus = dbus.SystemBus()
self.update_proxy = self.system_bus.get_object('com.kylin.systemupgrade','/com/kylin/systemupgrade')
self.update_proxy = self.system_bus.get_object('com.kylin.systemupgrade','/com/kylin/systemupgrade',follow_name_owner_changes=True)
self.update_interface = dbus.Interface(self.update_proxy,dbus_interface='com.kylin.systemupgrade.interface')
def GetConfigValue(self,section,value):
@ -685,7 +686,7 @@ class UnattendedUpgradesShutdown():
def get_upgrade_strategy_proxy(self):
if not self.upgrade_strategy_proxy:
bus = dbus.SystemBus()
self.upgrade_strategy_proxy = bus.get_object('com.kylin.UpgradeStrategies','/com/kylin/UpgradeStrategies')
self.upgrade_strategy_proxy = bus.get_object('com.kylin.UpgradeStrategies','/com/kylin/UpgradeStrategies',follow_name_owner_changes=True)
return self.upgrade_strategy_proxy
def get_upgrade_strategy_interface(self):
@ -694,7 +695,7 @@ class UnattendedUpgradesShutdown():
def get_update_proxy(self):
if not self.update_proxy:
bus = dbus.SystemBus()
self.update_proxy = bus.get_object('com.kylin.systemupgrade','/com/kylin/systemupgrade')
self.update_proxy = bus.get_object('com.kylin.systemupgrade','/com/kylin/systemupgrade',follow_name_owner_changes=True)
return self.update_proxy
@ -723,7 +724,7 @@ class UnattendedUpgradesShutdown():
# logind is down
self.inhibit_lock = self.get_inhibit_shutdown_lock()
self.logind_proxy = bus.get_object(
'org.freedesktop.login1', '/org/freedesktop/login1')
'org.freedesktop.login1', '/org/freedesktop/login1',follow_name_owner_changes=True)
return self.logind_proxy
def get_inhibit_shutdown_lock(self):
@ -1026,6 +1027,19 @@ class UnattendedUpgradesShutdown():
else:
logging.debug("unattended-upgrades-policy.conf not exist")
'''
def change_upgrade_policy_handler():
autoUpgrade = ReadValueFromFile(UNATTENDED_UPGRADE_POLICY_FILE_PATH, POLICY_CONF_SECTION_AUTO_UPGRADE_POLICY, AUTO_UPGRADE_POLICY_OPTION_AUTOUPGRADE)
if autoUpgrade == 'on':
background_scheduler.resume_job('download')
background_scheduler.resume_job('install')
elif autoUpgrade == 'off':
background_scheduler.pause_job('download')
background_scheduler.pause_job('install')
joblist = background_scheduler.get_jobs()
for job in joblist:
logging.debug("job:%s,next run time:%s"%(job.id,job.next_run_time))
def upgrade_all_now_handler():
#self._wait_for_unattended_upgrade_finish()
logging.info("upgrade all now sinal received")
@ -1084,7 +1098,7 @@ class UnattendedUpgradesShutdown():
self.upgrade_strategy_proxy.connect_to_signal("PropertyChanged",property_changed_handler)
self.upgrade_strategy_proxy.connect_to_signal("UpgradeAllNow",upgrade_all_now_handler)
#self.update_proxy.connect_to_signal("ChangeUpgradePolicy",change_upgrade_policy_handler)
self.update_proxy.connect_to_signal("ChangeUpgradePolicy",change_upgrade_policy_handler)
#self.update_proxy.connect_to_signal("UpgradeAllNow",upgrade_all_now_handler)
try:
@ -1340,7 +1354,7 @@ if __name__ == "__main__":
# scheduler_logger.setLevel(logging.DEBUG)
# scheduler_logger.addHandler(file_handler)
# scheduler_logger.addHandler(stdout_handler)
os.environ['TZ']= "Asia/Shanghai"
os_release_info = ReadOsRelease('/etc/os-release')
logging.info("project id:%s,sub-project id:%s"%(os_release_info['PROJECT_CODENAME'],os_release_info['SUB_PROJECT_CODENAME']))
'''
@ -1396,7 +1410,7 @@ if __name__ == "__main__":
'''
kylin_system_updater = KylinSystemUpdater()
autoupgradepolicy = AutoUpgradePolicy()
background_scheduler = BackgroundScheduler()
background_scheduler = BackgroundScheduler(timezone="Asia/Shanghai")
background_scheduler_init(background_scheduler)
#executor = ThreadPoolExecutor(max_workers=1)
UnattendedUpgradesShutdown(options).run()