Пример #1
0
def cache_packages():
    preexisting = set([model.name for model in PackageModel.select()])
    output = []
    for pkg in Package.all():
        pkg_data = dict(
            name =  pkg.name,
            sha1 = pkg.sha1,
            version = pkg.version,
            patchlevel = pkg.patchlevel,
            filename = pkg.tarball_filename,
            description = gracefully_read(pkg, 'SPKG.txt'),
            pkgtype = gracefully_read(pkg, 'type'),
        )
        try:
            with database.atomic():
                model = PackageModel.create(**pkg_data)
        except peewee.IntegrityError:
            PackageModel.update(
                **pkg_data
            ).where(
                PackageModel.name == pkg.name
            ).execute()
        output.append(pformat(pkg_data))
        preexisting.discard(pkg.name)
    for pkg_name in preexisting:
        PackageModel.delete().where(PackageModel.name == pkg_name)
    return '\n'.join(output)
Пример #2
0
def list_packages_handler(request):
    log.debug(request)
    reply = dict(success=True, packages=[model.name for model in Package.select()])
    return web.Response(body=json.dumps(reply).encode("utf-8"))