add inhibitshutdownlock
This commit is contained in:
parent
950c64b8f4
commit
86af2d5c58
|
@ -325,7 +325,46 @@ logged_msgs = set() # type: AbstractSet[str]
|
|||
|
||||
NEVER_PIN = -32768
|
||||
|
||||
class InhibitShutdownLock():
|
||||
|
||||
def __init__(self):
|
||||
self.inhibit_lock = None
|
||||
|
||||
#安装时禁止关机 进行加锁
|
||||
def lock(self, caller='Kylin System Updater'):
|
||||
"""
|
||||
Send a dbus signal to logind to not suspend the system, it will be
|
||||
released when the return value drops out of scope
|
||||
"""
|
||||
try:
|
||||
from gi.repository import Gio, GLib
|
||||
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
|
||||
|
||||
var, fdlist = connection.call_with_unix_fd_list_sync(
|
||||
'org.freedesktop.login1', '/org/freedesktop/login1',
|
||||
'org.freedesktop.login1.Manager', 'Inhibit',
|
||||
GLib.Variant('(ssss)',
|
||||
('shutdown',
|
||||
caller, 'Installing Packages',
|
||||
'block')),
|
||||
None, 0, -1, None, None)
|
||||
self.inhibit_lock = Gio.UnixInputStream(fd=fdlist.steal_fds()[var[0]])
|
||||
logging.info("Shutdown Has been locked...")
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
#解锁禁止关机
|
||||
def unlock(self):
|
||||
try:
|
||||
if self.inhibit_lock != None:
|
||||
self.inhibit_lock.close()
|
||||
self.inhibit_lock == None
|
||||
logging.info("Shutdown Has been unlocked...")
|
||||
else:
|
||||
logging.info("Not locked and Quitting ...")
|
||||
except Exception as e:
|
||||
logging.error("unlock failed." + str(e))
|
||||
|
||||
class LoggingDateTime:
|
||||
"""The date/time representation for the dpkg log file timestamps"""
|
||||
LOG_DATE_TIME_FMT = "%Y-%m-%d %H:%M:%S"
|
||||
|
@ -3101,12 +3140,13 @@ def run(options, # type: Options
|
|||
with open(PROGRESS_LOG,'w+') as f:
|
||||
f.write('0')
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.install.notification.InstallStart',shell=True)
|
||||
if LockedPreventShutdown():
|
||||
pass
|
||||
else:
|
||||
logging.error("cannot get shutdown lock,exiting...")
|
||||
WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
sys.exit(1)
|
||||
inhibitshutdownlock.lock()
|
||||
# if LockedPreventShutdown():
|
||||
# pass
|
||||
# else:
|
||||
# logging.error("cannot get shutdown lock,exiting...")
|
||||
# WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","idle")
|
||||
# sys.exit(1)
|
||||
|
||||
logging.debug("InstCount=%i DelCount=%i BrokenCount=%i"
|
||||
% (cache._depcache.inst_count,
|
||||
|
@ -3118,7 +3158,8 @@ def run(options, # type: Options
|
|||
options,
|
||||
logfile_dpkg)
|
||||
|
||||
unLockedEnableShutdown()
|
||||
# unLockedEnableShutdown()
|
||||
inhibitshutdownlock.unlock()
|
||||
subprocess.Popen('dbus-send --system --type=signal / com.kylin.install.notification.InstallFinish',shell=True)
|
||||
if pkg_install_success:
|
||||
clean_downloaded_packages(fetcher)
|
||||
|
@ -3651,6 +3692,7 @@ if __name__ == "__main__":
|
|||
kylin_system_updater.ConnectToSignals()
|
||||
kylin_system_updater.UpdateDetect()
|
||||
kylin_system_updater.RunMainloop()
|
||||
inhibitshutdownlock = InhibitShutdownLock()
|
||||
if options.download_only:
|
||||
WriteValueToFile(UNATTENDED_UPGRADE_CONFIG_FILE_PATH,"UNATTENDED_UPGRADE","autoupdate_run_status","download")
|
||||
elif options.install_only:
|
||||
|
|
Loading…
Reference in New Issue