Ejemplo n.º 1
0
def download_files(i, links):
    download_path = os.path.join(os.getcwd(), 'emi_files')
    if not os.path.exists(download_path):
        os.makedirs(download_path)

    files = []
    for l in links:
        if not l.strip():
            continue
        print "Downloading %s" % l
        # Determine filename
        from_file = open_url(l)
        content_disp = from_file.info().getheader('Content-Disposition')
        basename = None
        if content_disp:
            for item in content_disp.split(';'):
                item = item.strip()
                if item.strip().startswith('filename='):
                    basename = item[len('filename="'):-len('"')]
        from_file.close()
        if basename is None:
            basename = os.path.basename(l)
        print "Filename %s" % basename
        new_path = os.path.join(download_path, "%s_%s" % (i, basename))
        if not os.path.exists(new_path):
            tmp_path = download_external_url(l)
            os.rename(tmp_path, new_path)
        files.append((new_path, basename))
    return files
Ejemplo n.º 2
0
def dropbox_upload(pub_id=None, fileurl=''):
    """
    Dropbox upload backend
    """
    if pub_id:
        pub_id = pub_id.encode('utf8')
    if fileurl:
        fileurl = fileurl.encode('utf8')

    uid = current_user.get_id()

    if not fileurl:
        abort(400)

    if not (fileurl.startswith("https://dl.dropbox.com/")
            or fileurl.startswith("https://dl.dropboxusercontent.com/")):
        abort(400)

    publication = OpenAIREPublication(uid)
    if not is_editable(publication):
        flash(
            "You cannot upload new files when your upload has already been submitted!"
        )
        abort(400)

    # Pre-fill user collection
    c = request.values.get('c', None)
    if c:
        publication.add_usercollection(c)

    uploaded_file = download_external_url(fileurl)
    publication.add_a_fulltext(uploaded_file,
                               secure_filename(os.path.basename(fileurl)))

    return redirect(url_for('deposit.edit', pub_id=publication.publicationid))
Ejemplo n.º 3
0
def dropbox_upload(pub_id=None, fileurl=''):
    """
    Dropbox upload backend
    """
    if pub_id:
        pub_id = pub_id.encode('utf8')
    if fileurl:
        fileurl = fileurl.encode('utf8')

    uid = current_user.get_id()

    if not fileurl:
        abort(400)

    if not (fileurl.startswith("https://dl.dropbox.com/") or fileurl.startswith("https://dl.dropboxusercontent.com/")):
        abort(400)

    publication = OpenAIREPublication(uid)
    if not is_editable(publication):
        flash("You cannot upload new files when your upload has already been submitted!")
        abort(400)

    # Pre-fill user collection
    c = request.values.get('c', None)
    if c:
        publication.add_usercollection(c)

    uploaded_file = download_external_url(fileurl)
    publication.add_a_fulltext(uploaded_file, secure_filename(os.path.basename(fileurl)))

    return redirect(url_for('deposit.edit', pub_id=publication.publicationid))
Ejemplo n.º 4
0
def download_files(i, links):
    download_path = os.path.join(os.getcwd(), 'emi_files')
    if not os.path.exists(download_path):
        os.makedirs(download_path)

    files = []
    for l in links:
        if not l.strip():
            continue
        print "Downloading %s" % l
        # Determine filename
        from_file = open_url(l)
        content_disp = from_file.info().getheader('Content-Disposition')
        basename = None
        if content_disp:
            for item in content_disp.split(';'):
                item = item.strip()
                if item.strip().startswith('filename='):
                    basename = item[len('filename="'):-len('"')]
        from_file.close()
        if basename is None:
            basename = os.path.basename(l)
        print "Filename %s" % basename
        new_path = os.path.join(download_path, "%s_%s" % (i, basename))
        if not os.path.exists(new_path):
            tmp_path = download_external_url(l)
            os.rename(tmp_path, new_path)
        files.append((new_path, basename))
    return files