2019-04-11 15:49:20 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
Update AIL
|
|
|
|
============================
|
|
|
|
|
2019-04-12 14:07:40 +00:00
|
|
|
Update AIL in the background
|
2019-04-11 15:49:20 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2023-07-12 09:36:47 +00:00
|
|
|
import logging
|
|
|
|
import logging.config
|
2019-04-11 15:49:20 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2019-11-05 14:18:03 +00:00
|
|
|
|
2022-07-08 07:47:47 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2023-07-12 12:37:59 +00:00
|
|
|
from lib import ail_logger
|
2022-07-08 07:47:47 +00:00
|
|
|
from lib import ail_updates
|
2019-04-11 15:49:20 +00:00
|
|
|
|
2023-07-12 09:36:47 +00:00
|
|
|
logging.config.dictConfig(ail_logger.get_config(name='updates'))
|
|
|
|
def launch_background_upgrade(version):
|
|
|
|
logger = logging.getLogger()
|
2023-07-12 12:37:59 +00:00
|
|
|
logger.warning(f'launching background update {version}')
|
2023-07-12 09:36:47 +00:00
|
|
|
update = ail_updates.AILBackgroundUpdate(version)
|
|
|
|
nb_done = update.get_nb_scripts_done()
|
|
|
|
update.start()
|
|
|
|
scripts = update.get_scripts()
|
|
|
|
scripts = scripts[nb_done:]
|
|
|
|
for script in scripts:
|
|
|
|
print('launching background script update', script)
|
|
|
|
# launch script
|
|
|
|
update.start_script(script)
|
|
|
|
script_path = update.get_script_path()
|
|
|
|
if script_path:
|
|
|
|
try:
|
|
|
|
process = subprocess.run(['python', script_path])
|
|
|
|
if process.returncode != 0:
|
|
|
|
stderr = process.stderr
|
|
|
|
if stderr:
|
|
|
|
error = stderr.decode()
|
|
|
|
logger.error(error)
|
|
|
|
update.set_error(error)
|
|
|
|
else:
|
|
|
|
update.set_error('Error Updater Script')
|
|
|
|
logger.error('Error Updater Script')
|
|
|
|
sys.exit(0)
|
|
|
|
except Exception as e:
|
|
|
|
update.set_error(str(e))
|
|
|
|
logger.error(str(e))
|
|
|
|
sys.exit(0)
|
2020-12-11 20:02:07 +00:00
|
|
|
|
2023-07-12 09:36:47 +00:00
|
|
|
if not update.get_error():
|
|
|
|
update.end_script()
|
|
|
|
else:
|
|
|
|
logger.warning('Updater exited on error')
|
|
|
|
sys.exit(0)
|
2022-07-08 07:47:47 +00:00
|
|
|
|
2023-07-12 09:36:47 +00:00
|
|
|
update.end()
|
2023-07-12 12:37:59 +00:00
|
|
|
logger.warning(f'ending background update {version}')
|
2022-11-28 14:01:40 +00:00
|
|
|
|
2021-01-22 16:03:43 +00:00
|
|
|
|
2019-04-11 15:49:20 +00:00
|
|
|
if __name__ == "__main__":
|
2023-07-12 09:36:47 +00:00
|
|
|
if ail_updates.is_update_background_running():
|
|
|
|
v = ail_updates.get_update_background_version()
|
|
|
|
launch_background_upgrade(v)
|
2022-07-08 07:47:47 +00:00
|
|
|
else:
|
2023-07-12 09:36:47 +00:00
|
|
|
for ver in ail_updates.get_update_background_to_launch():
|
|
|
|
launch_background_upgrade(ver)
|