Beispiel #1
0
def download_package(package):
    fb_versions = fallback_versions(package)
    cached_package = Package.query.filter_by(name=package).first()
    if not cached_package:
        cached_package = Package(name=package)
        db_session.add(cached_package)
    for version in fb_versions:
        filtered_version = cached_package.versions.filter_by(
            version_code=version).first()
        if filtered_version == None:
            filename = urlparse.urlparse(
                fb_versions[version])[2].split('/')[-1]
            fb_file = requests.get(fb_versions[version]).content
            with open(filename, 'w') as tempfile:
                tempfile.write(fb_file)
            storage.store_package(package, filename)
            db_session.add(
                Version(
                    package=cached_package,
                    version_code=version,
                    filename=filename,
                    date_cached=datetime.datetime.now(),
                ))
            os.remove(filename)
    db_session.commit()
Beispiel #2
0
def upload():
    print request.headers
    if 'Authorization' not in request.headers:
        abort(403)
    auth = base64.b64decode(
        request.headers['Authorization'].split()[1]).split(':')
    if auth[0] != 'havarti' or auth[1] != app.config['PASSCODE']:
        abort(403)
    package = secure_filename(request.form['name'])
    cached_package = Package.query.filter_by(name=package).first()
    if request.form[':action'] == 'submit':
        if cached_package == None:
            db_session.add(Package(name=package, ))
            db_session.commit()
            return 'OK'
        else:
            abort(400, 'ALREADY EXISTS')
    elif request.form[':action'] == 'file_upload':
        if cached_package == None:
            cached_package = Package(name=package)
            db_session.add(cached_package)
        elif cached_package.version.filter_by(
                version_code=request.form['version']).first() != None:
            abort(400, 'ALREADY EXISTS')
        filename = secure_filename(request.files['content'].filename)
        request.files['content'].save(filename)
        storage.store_package(package, filename)
        db_session.add(
            Version(
                version_code=request.form['version'],
                package=cached_package,
                filename=filename,
                date_cached=datetime.datetime.now(),
            ))
        db_session.commit()
        os.remove(filename)
        return 'OK'
    else:
        abort(400, 'BAD REQUEST')
Beispiel #3
0
def upload():
    print request.headers
    if "Authorization" not in request.headers:
        abort(403)
    auth = base64.b64decode(request.headers["Authorization"].split()[1]).split(":")
    if auth[0] != "havarti" or auth[1] != app.config["PASSCODE"]:
        abort(403)
    package = secure_filename(request.form["name"])
    cached_package = Package.query.filter_by(name=package).first()
    if request.form[":action"] == "submit":
        if cached_package == None:
            db_session.add(Package(name=package))
            db_session.commit()
            return "OK"
        else:
            abort(400, "ALREADY EXISTS")
    elif request.form[":action"] == "file_upload":
        if cached_package == None:
            cached_package = Package(name=package)
            db_session.add(cached_package)
        elif cached_package.version.filter_by(version_code=request.form["version"]).first() != None:
            abort(400, "ALREADY EXISTS")
        filename = secure_filename(request.files["content"].filename)
        request.files["content"].save(filename)
        storage.store_package(package, filename)
        db_session.add(
            Version(
                version_code=request.form["version"],
                package=cached_package,
                filename=filename,
                date_cached=datetime.datetime.now(),
            )
        )
        db_session.commit()
        os.remove(filename)
        return "OK"
    else:
        abort(400, "BAD REQUEST")
Beispiel #4
0
def download_package(package):
    fb_versions = fallback_versions(package)
    cached_package = Package.query.filter_by(name=package).first()
    if not cached_package:
        cached_package = Package(name=package)
        db_session.add(cached_package)
    for version in fb_versions:
        filtered_version = cached_package.versions.filter_by(version_code=version).first()
        if filtered_version == None:
            filename = urlparse.urlparse(fb_versions[version])[2].split('/')[-1]
            fb_file = requests.get(fb_versions[version]).content
            with open(filename, 'w') as tempfile:
                tempfile.write(fb_file)
            storage.store_package(package, filename)
            db_session.add(
                Version(
                    package=cached_package,
                    version_code=version,
                    filename=filename,
                    date_cached=datetime.datetime.now(),
                )
            )
            os.remove(filename)
    db_session.commit()