Esempio n. 1
0
def delete_package(package_id):
    """Delete a package, all its releases and all files and directory
    associated with it
    """
    package = Package.query.get_or_404(package_id)
    store = get_store(app.config['STORAGE'], app.config['STORAGE_PARAMS'])
    if store.delete_package(package) is True:
        db.session.delete(package)
        db.session.commit()
    return redirect(url_for("dashboard.index"))
Esempio n. 2
0
def download_package(package, source):
    """Return a package file from storage
    """
    store = get_store(current_app.config['STORAGE'],
                      current_app.config['STORAGE_PARAMS'])

    try:
        package_obj = Package.query.filter_by(name=package).one()
    except NoResultFound:
        abort(404, "package %s does not exists" % package)

    return send_file(store.get_file(package_obj, source))
Esempio n. 3
0
def package_view(package):
    """List all files avaible for a package
    """
    store = get_store(current_app.config['STORAGE'],
                      current_app.config['STORAGE_PARAMS'])
    try:
        package_obj = Package.query.filter_by(name=package).one()
    except NoResultFound:
        abort(404, "package %s does not exists" % package)

    files = store.get_files(package_obj)
    return render_template("simple/package.html",
                           files=files,
                           package=package_obj)
Esempio n. 4
0
def reimport(user):
    from extrapypi import models
    from flask import current_app as app
    from extrapypi.commons.packages import get_store, create_release_from_source

    user_obj = models.User.query.filter_by(username=user).first()
    if user_obj is None:
        click.echo("Unknow user %s" % user, err=True)

    store = get_store(app.config['STORAGE'], app.config['STORAGE_PARAMS'])

    for package, metadata in store.get_releases_metadata():
        create_release_from_source(metadata, user_obj)
        click.echo("created %s release for % s" %
                   (metadata['version'], package))
Esempio n. 5
0
def package(package):
    """Package detail view
    """
    try:
        p = Package.query.filter_by(name=package).one()
    except NoResultFound:
        abort(404)

    release = p.latest_release
    store = get_store(app.config['STORAGE'], app.config['STORAGE_PARAMS'])
    files = store.get_files(p, release) or []
    releases = [r for r in p.releases if r != release]
    return render_template("dashboard/package_detail.html",
                           release=release,
                           files=files,
                           releases=releases)
Esempio n. 6
0
def release(package, release_id):
    """Specific release view
    """
    try:
        package = Package.query.filter_by(name=package).one()
        release = Release.query.filter(Release.id == release_id,
                                       Release.package_id == package.id).one()
    except NoResultFound:
        abort(404)

    store = get_store(app.config['STORAGE'], app.config['STORAGE_PARAMS'])
    files = store.get_files(package, release) or []
    releases = [r for r in package.releases if r != release]
    return render_template("dashboard/package_detail.html",
                           release=release,
                           files=files,
                           releases=releases)
Esempio n. 7
0
def delete_release(release_id):
    """Delete a release"""
    release = Release.query.get_or_404(release_id)
    package = release.package

    store = get_store(app.config['STORAGE'], app.config['STORAGE_PARAMS'])
    if store.delete_release(package, release.version) is True:
        db.session.delete(release)
        db.session.commit()
        flash(
            "Release " + release.version + " from package " + package.name +
            " deleted", "alert-success")

    if len(package.releases.all()) == 0:
        delete_package(package.id)
        flash("Package " + package.name + " deleted", "alert-success")

    return redirect(url_for("dashboard.index"))
Esempio n. 8
0
def test_get_store_errors():
    with pytest.raises(AttributeError):
        get_store('BadStore', {})