update_manager: refactor initialization
We need to be sure that the entire update_manager is correctly configured prior to queueing the callbacks for the initial refresh. Rather than have each updater spawn a "refesh" callback, move them all into a single init method spawned after the module has been fully configured. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
fb3706c54f
commit
e0f4b46364
|
@ -37,8 +37,6 @@ class UpdateManager:
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.config.read_supplemental_config(SUPPLEMENTAL_CFG_PATH)
|
self.config.read_supplemental_config(SUPPLEMENTAL_CFG_PATH)
|
||||||
AsyncHTTPClient.configure(None, defaults=dict(user_agent="Moonraker"))
|
|
||||||
self.http_client = AsyncHTTPClient()
|
|
||||||
self.repo_debug = config.getboolean('enable_repo_debug', False)
|
self.repo_debug = config.getboolean('enable_repo_debug', False)
|
||||||
self.distro = config.get('distro', "debian").lower()
|
self.distro = config.get('distro', "debian").lower()
|
||||||
if self.distro not in SUPPORTED_DISTROS:
|
if self.distro not in SUPPORTED_DISTROS:
|
||||||
|
@ -74,6 +72,9 @@ class UpdateManager:
|
||||||
self._handle_auto_refresh, UPDATE_REFRESH_TIME)
|
self._handle_auto_refresh, UPDATE_REFRESH_TIME)
|
||||||
self.refresh_cb.start()
|
self.refresh_cb.start()
|
||||||
|
|
||||||
|
AsyncHTTPClient.configure(None, defaults=dict(user_agent="Moonraker"))
|
||||||
|
self.http_client = AsyncHTTPClient()
|
||||||
|
|
||||||
self.server.register_endpoint(
|
self.server.register_endpoint(
|
||||||
"/machine/update/moonraker", ["POST"],
|
"/machine/update/moonraker", ["POST"],
|
||||||
self._handle_update_request)
|
self._handle_update_request)
|
||||||
|
@ -93,8 +94,16 @@ class UpdateManager:
|
||||||
# Register Ready Event
|
# Register Ready Event
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
"server:klippy_identified", self._set_klipper_repo)
|
"server:klippy_identified", self._set_klipper_repo)
|
||||||
# Initialize GitHub API Rate Limits
|
# Initialize GitHub API Rate Limits and configured updaters
|
||||||
IOLoop.current().spawn_callback(self._init_api_rate_limit)
|
IOLoop.current().spawn_callback(
|
||||||
|
self._initalize_updaters, list(self.updaters.values()))
|
||||||
|
|
||||||
|
async def _initalize_updaters(self, initial_updaters):
|
||||||
|
await self._init_api_rate_limit()
|
||||||
|
for updater in initial_updaters:
|
||||||
|
ret = updater.refresh()
|
||||||
|
if asyncio.iscoroutine(ret):
|
||||||
|
await updater.refresh()
|
||||||
|
|
||||||
async def _set_klipper_repo(self):
|
async def _set_klipper_repo(self):
|
||||||
kinfo = self.server.get_klippy_info()
|
kinfo = self.server.get_klippy_info()
|
||||||
|
@ -109,6 +118,7 @@ class UpdateManager:
|
||||||
# Current Klipper Updater is valid
|
# Current Klipper Updater is valid
|
||||||
return
|
return
|
||||||
self.updaters['klipper'] = GitUpdater(self, "klipper", kpath, env)
|
self.updaters['klipper'] = GitUpdater(self, "klipper", kpath, env)
|
||||||
|
await self.updaters['klipper'].refresh()
|
||||||
|
|
||||||
async def _check_klippy_printing(self):
|
async def _check_klippy_printing(self):
|
||||||
klippy_apis = self.server.lookup_plugin('klippy_apis')
|
klippy_apis = self.server.lookup_plugin('klippy_apis')
|
||||||
|
@ -387,7 +397,6 @@ class GitUpdater:
|
||||||
self.remote = "origin"
|
self.remote = "origin"
|
||||||
self.branch = "master"
|
self.branch = "master"
|
||||||
self.is_valid = self.is_dirty = self.detached = False
|
self.is_valid = self.is_dirty = self.detached = False
|
||||||
IOLoop.current().spawn_callback(self.refresh)
|
|
||||||
|
|
||||||
def _get_version_info(self):
|
def _get_version_info(self):
|
||||||
ver_path = os.path.join(self.repo_path, "scripts/version.txt")
|
ver_path = os.path.join(self.repo_path, "scripts/version.txt")
|
||||||
|
@ -699,7 +708,6 @@ class PackageUpdater:
|
||||||
self.available_packages = []
|
self.available_packages = []
|
||||||
self.init_evt = Event()
|
self.init_evt = Event()
|
||||||
self.refresh_condition = None
|
self.refresh_condition = None
|
||||||
IOLoop.current().spawn_callback(self.refresh)
|
|
||||||
|
|
||||||
async def refresh(self, fetch_packages=False):
|
async def refresh(self, fetch_packages=False):
|
||||||
# TODO: Use python-apt python lib rather than command line for updates
|
# TODO: Use python-apt python lib rather than command line for updates
|
||||||
|
@ -774,7 +782,6 @@ class ClientUpdater:
|
||||||
logging.info(f"\nInitializing Client Updater: '{self.name}',"
|
logging.info(f"\nInitializing Client Updater: '{self.name}',"
|
||||||
f"\nversion: {self.version}"
|
f"\nversion: {self.version}"
|
||||||
f"\npath: {self.path}")
|
f"\npath: {self.path}")
|
||||||
IOLoop.current().spawn_callback(self.refresh)
|
|
||||||
|
|
||||||
def _get_local_version(self):
|
def _get_local_version(self):
|
||||||
version_path = os.path.join(self.path, ".version")
|
version_path = os.path.join(self.path, ".version")
|
||||||
|
|
Loading…
Reference in New Issue