def get_history(self, pkg: AppImage) -> PackageHistory: history = [] res = PackageHistory(pkg, history, -1) app_con = self._get_db_connection(DATABASE_APPS_FILE) if not app_con: return res try: cursor = app_con.cursor() cursor.execute(query.FIND_APP_ID_BY_NAME_AND_GITHUB.format(pkg.name.lower(), pkg.github.lower() if pkg.github else '')) app_tuple = cursor.fetchone() if not app_tuple: self.logger.warning(f"Could not retrieve {pkg} from the database '{DATABASE_APPS_FILE}'") return res except: self.logger.error(f"An exception happened while querying the database file '{DATABASE_APPS_FILE}'") traceback.print_exc() app_con.close() return res app_con.close() releases_con = self._get_db_connection(DATABASE_RELEASES_FILE) if not releases_con: return res try: cursor = releases_con.cursor() releases = cursor.execute(query.FIND_RELEASES_BY_APP_ID.format(app_tuple[0])) if releases: treated_releases = [(LegacyVersion(r[0]), *r[1:]) for r in releases] treated_releases.sort(key=self._sort_release, reverse=True) for idx, tup in enumerate(treated_releases): ver = str(tup[0]) history.append({'0_version': ver, '1_published_at': datetime.strptime(tup[2], '%Y-%m-%dT%H:%M:%SZ') if tup[ 2] else '', '2_url_download': tup[1]}) if res.pkg_status_idx == -1 and pkg.version == ver: res.pkg_status_idx = idx return res except: self.logger.error(f"An exception happened while querying the database file '{DATABASE_RELEASES_FILE}'") traceback.print_exc() finally: releases_con.close()
def get_history(self, pkg: AppImage) -> PackageHistory: history = [] res = PackageHistory(pkg, history, -1) connection = self._get_db_connection(DB_APPS_PATH) if connection: try: cursor = connection.cursor() cursor.execute( query.FIND_APP_ID_BY_NAME_AND_GITHUB.format( pkg.name.lower(), pkg.github.lower() if pkg.github else '')) app_tuple = cursor.fetchone() if not app_tuple: raise Exception( "Could not retrieve {} from the database {}".format( pkg, DB_APPS_PATH)) finally: self._close_connection(DB_APPS_PATH, connection) connection = self._get_db_connection(DB_RELEASES_PATH) if connection: try: cursor = connection.cursor() releases = cursor.execute( query.FIND_RELEASES_BY_APP_ID.format(app_tuple[0])) if releases: for idx, tup in enumerate(releases): history.append({ '0_version': tup[0], '1_published_at': datetime.strptime(tup[2], '%Y-%m-%dT%H:%M:%SZ') if tup[2] else '', '2_url_download': tup[1] }) if res.pkg_status_idx == -1 and pkg.version == tup[ 0]: res.pkg_status_idx = idx finally: self._close_connection(DB_RELEASES_PATH, connection) return res
def get_history(self, pkg: FlatpakApplication, full_commit_str: bool = False) -> PackageHistory: pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation) pkg_commit = pkg.commit if pkg.commit else None if pkg_commit and not full_commit_str: pkg_commit = pkg_commit[0:8] commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin, pkg.installation, full_str=full_commit_str) status_idx = 0 commit_found = False if pkg_commit is None and len(commits) > 1 and commits[0]['commit'] == '(null)': del commits[0] pkg_commit = commits[0] commit_found = True if not commit_found: for idx, data in enumerate(commits): if data['commit'] == pkg_commit: status_idx = idx commit_found = True break if not commit_found and pkg_commit and commits[0]['commit'] == '(null)': commits[0]['commit'] = pkg_commit return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
def get_history(self, pkg: FlatpakApplication) -> PackageHistory: pkg.commit = flatpak.get_commit(pkg.id, pkg.branch) commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin) status_idx = 0 for idx, data in enumerate(commits): if data['commit'] == pkg.commit: status_idx = idx break return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
def get_history(self, pkg: ArchPackage) -> PackageHistory: temp_dir = '{}/build_{}'.format(BUILD_DIR, int(time.time())) try: Path(temp_dir).mkdir(parents=True) run_cmd('git clone ' + URL_GIT.format(pkg.name), print_error=False, cwd=temp_dir) clone_path = '{}/{}'.format(temp_dir, pkg.name) pkgbuild_path = '{}/PKGBUILD'.format(clone_path) commits = git.list_commits(clone_path) if commits: history, status_idx = [], -1 for idx, commit in enumerate(commits): with open(pkgbuild_path) as f: pkgdict = aur.map_pkgbuild(f.read()) if status_idx < 0 and '{}-{}'.format( pkgdict.get('pkgver'), pkgdict.get('pkgrel')) == pkg.version: status_idx = idx history.append({ '1_version': pkgdict['pkgver'], '2_release': pkgdict['pkgrel'], '3_date': commit['date'] }) # the number prefix is to ensure the rendering order if idx + 1 < len(commits): if not run_cmd('git reset --hard ' + commits[idx + 1]['commit'], cwd=clone_path): break return PackageHistory(pkg=pkg, history=history, pkg_status_idx=status_idx) finally: if os.path.exists(temp_dir): shutil.rmtree(temp_dir)