def build_db(source, repos): today = now().date() tomorrow = today + timedelta(days=1) for repo in repos: path = index_path(repo) repodata = load_repo(path) if repodata is None: continue arch = repo.rpartition('/')[-1] for pkgname in repodata: dictionary = {} for k, v in repodata[pkgname].items(): if isinstance(v, bytes): v = v.decode() dictionary[k] = v depends_count = len(dictionary.get('run_depends', [])) mainpkg = dictionary.get('source-revisions', pkgname).split(':')[0] source.create(datasource.PackageRow( arch=arch, pkgname=pkgname, pkgver=dictionary['pkgver'], repodata=dictionary, mainpkg=mainpkg, depends_count=depends_count, repo=repo ), dates=[today, tomorrow])
def _initialize(self): self._cursor.execute('''create table if not exists packages ( arch text not null, pkgname text not null, pkgver text not null, restricted integer not null, builddate text not null, repodata text not null, templatedata text not null, mainpkg text not null, depends_count integer, upstreamver text not null, repo text not null, popularity integer default 0) ''') self._cursor.execute('''create table if not exists daily_hash ( pkgname text not null, date text not null, unique(pkgname, date) ) ''') self._cursor.execute('''create table if not exists metapackages ( pkgname text unique not null, classification text not null ) ''') time = datetime_to_string(sink.now().replace(microsecond=0)) self._cursor.execute('''create table if not exists auxiliary as select ? as key, ? as value ''', ['update_time', time])
def of_day(): source = datasource.factory() packages = source.of_day(now().date()) parameters = { 'title': 'Packages of the day', 'packages': packages, 'bullets': True, } return present.render_template('list.html', **parameters)
def main_page(): source = datasource.factory() lists = [ { 'title': 'Newest', 'more': 'More newest', 'address': 'newest', 'packages': source.newest(20) }, { 'title': 'Popular', 'more': 'More popular', 'address': 'popular', 'packages': source.popular(20) }, { 'title': 'Of day', 'bullets': True, 'address': 'of_day', 'packages': source.of_day(now().date()), }, { 'title': 'Sets', 'more': 'More sets', 'bullets': True, 'address': 'sets', 'packages': [ i['pkgname'] for i in source.metapackages([ Interest.INTERESTING, Interest.NOVEL, ]) ] }, ] parameters = { 'title': 'Packages', 'updated': _ago(source), 'lists': lists, } return present.render_template('main.html', **parameters)
def build_db(source, repos): today = now().date() tomorrow = today + timedelta(days=1) srcpkgs = os.path.join(DISTDIR, 'srcpkgs') for pkgname in os.listdir(srcpkgs): entry = os.path.join(srcpkgs, pkgname) if os.path.islink(entry) or not os.path.isdir(entry): continue raw_data = templatedata(pkgname, repos[0]) dictionary = {} for k, v in raw_data.items(): k = _XBPS_SRC_FIELDS.get(k, k) if k in _SINGLE_VALUE_FIELDS: dictionary[k] = v[0] else: dictionary[k] = v try: pkgver = '{pkgname}-{version}_{revision}'.format(**dictionary) except KeyError: continue dictionary['pkgver'] = pkgver dictionary['source-revisions'] = dictionary['pkgname'] template_json = datasource.to_json(dictionary) if 'restricted' in dictionary: if dictionary['restricted'] == 'yes': dictionary['restricted'] = True source.create(datasource.PackageRow( pkgname=pkgname, pkgver=pkgver, arch='unknown-unknown', restricted=dictionary['restricted'], templatedata=template_json, mainpkg=pkgname, repo='' ), dates=[today, tomorrow]) else: source.update( pkgname=pkgname, pkgver=pkgver, set_templatedata=template_json )
def _ago(source): updated = _update_time(source) ago = humanize.naturaltime(now() - updated) updated_no_zone = updated.strftime('%Y-%m-%d %H:%M:%S') return f'{updated_no_zone} UTC ({ago})'