async def _update_sql(self, prev_version: Version) -> None: """Apply any structural changes to the database since the last startup.""" if self.version == prev_version: # already up to date. return # version changed; there may be sql changes. with open(SQL_UPDATES_FILE, 'r') as f: content = f.read() updates = [] current_ver = None for line in content.splitlines(): if line.startswith('#') or not current_ver: # may be normal comment or new version if rgx := re.fullmatch(r'^# v(?P<ver>\d+\.\d+\.\d+)$', line): current_ver = Version.from_str(rgx['ver']) continue # we only need the updates between the # previous and new version of the server. if prev_version < current_ver <= self.version: updates.append(line)
async def _update_sql(self, prev_version: Version) -> None: """Apply any structural changes to sql since the last startup.""" if self.version == prev_version: # already up to date. return # version changed; there may be sql changes. content = SQL_UPDATES_FILE.read_text() queries = [] q_lines = [] current_ver = None for line in content.splitlines(): if not line: continue if line.startswith('#'): # may be normal comment or new version if rgx := re.fullmatch(r'^# v(?P<ver>\d+\.\d+\.\d+)$', line): current_ver = Version.from_str(rgx['ver']) continue elif not current_ver: continue
async def _update_cmyui(self) -> None: """Check if cmyui_pkg has a newer release; update if available.""" module_ver = Version.from_str(pkg_version('cmyui')) latest_ver = await self._get_latest_cmyui() if module_ver < latest_ver: # package is not up to date; update it. log(f'Updating cmyui_pkg (v{module_ver!r} -> ' f'v{latest_ver!r}).', Ansi.MAGENTA) pip_main(['install', '-Uq', 'cmyui']) # Update quiet
async def _get_latest_cmyui(self) -> Version: """Get the latest version release of cmyui_pkg from pypi.""" url = 'https://pypi.org/pypi/cmyui/json' async with glob.http.get(url) as resp: if not resp or resp.status != 200: return self.version # safe cuz py>=3.7 dicts are ordered if not (json := await resp.json()): return self.version # return most recent release version return Version.from_str(list(json['releases'])[-1])