Exemple #1
0
def download_zip(id, version_id):
    ai = AI.query.get(id)
    if not ai:
        return CommonErrors.INVALID_ID
    if not current_user.can_access(ai):
        return CommonErrors.NO_ACCESS

    version = AI_Version.query.filter(AI_Version.ai_id == id).filter(
        AI_Version.version_id == version_id).first()
    if not version:
        return CommonErrors.INVALID_ID

    tmpdir = tempfile.mkdtemp()
    _, tmpzip = tempfile.mkstemp()

    if not ftp.download_tree(version.path, tmpdir):
        return CommonErrors.FTP_ERROR

    currdir = os.getcwd()
    os.chdir(tmpdir)
    zipf = zipfile.ZipFile(tmpzip, 'w')
    zipdir(".", zipf)
    zipf.close()
    os.chdir(currdir)
    return send_file(tmpzip,
                     as_attachment=True,
                     attachment_filename="{}_v{}.zip".format(
                         ai.name, version_id))
Exemple #2
0
    def f():
        tmpdir = tempfile.mkdtemp()

        ftp.download_tree(p, tmpdir)

        _, tmpzip_path = tempfile.mkstemp()

        currdir = os.getcwd()
        os.chdir(tmpdir)
        zipf = zipfile.ZipFile(tmpzip_path, 'w')
        zipdir(".", zipf)
        zipf.close()
        os.chdir(currdir)
        return send_file(tmpzip_path)
Exemple #3
0
	def f():
		tmpdir = tempfile.mkdtemp()

		ftp.download_tree(p, tmpdir)

		_, tmpzip_path = tempfile.mkstemp()

		currdir = os.getcwd()
		os.chdir(tmpdir)
		zipf = zipfile.ZipFile(tmpzip_path, 'w')
		zipdir(".", zipf)
		zipf.close()
		os.chdir(currdir)
		return send_file(tmpzip_path)
Exemple #4
0
def download_zip(id, version_id):
	ai = AI.query.get(id)
	if not ai:
		return CommonErrors.INVALID_ID
	if not current_user.can_access(ai):
		return CommonErrors.NO_ACCESS

	version = AI_Version.query.filter(AI_Version.ai_id == id).filter(AI_Version.version_id == version_id).first()
	if not version:
		return CommonErrors.INVALID_ID

	tmpdir = tempfile.mkdtemp()
	_, tmpzip = tempfile.mkstemp()

	if not ftp.download_tree(version.path, tmpdir):
		return CommonErrors.FTP_ERROR

	currdir = os.getcwd()
	os.chdir(tmpdir)
	zipf = zipfile.ZipFile(tmpzip, 'w')
	zipdir(".", zipf)
	zipf.close()
	os.chdir(currdir)
	return send_file(tmpzip, as_attachment=True, attachment_filename="{}_v{}.zip".format(ai.name, version_id))