def pdf(project, branch='master'):
build_path = os.path.abspath(join('repos', project.name, branch.name,
'build/latex'))
build_latex(project.name, branch.name)
command = '(cd ' + build_path + '; pdflatex -interaction nonstopmode linux.tex > /tmp/222 || true)'
os.system(command)
return flask.send_from_directory(build_path, 'linux.pdf')
python类send_from_directory()的实例源码
def tex(project, branch='master'):
build_path = os.path.abspath(join('repos', project.name, branch.name,
'build/latex'))
build_latex(project.name, branch.name)
return flask.send_from_directory(build_path, 'linux.tex')
def source(project, branch, filename):
source_path = os.path.abspath(join('repos', project.name, branch.name, 'source'))
return flask.send_from_directory(source_path, filename)
def get_tikz(project, branch, action, filename):
images_path = join('repos', project.name, branch.name,
'build/html/_images')
response = send_from_directory(os.path.abspath(images_path), filename)
if '/_images/tikz-' in request.url:
response.cache_control.max_age = 5256000
return response
def resources(project, filename):
return send_from_directory(
os.path.abspath(join(project.get_folder(), '_resources/original')),
filename)
def send_js(path):
return send_from_directory('web_content/static', path)
def results(filename):
if not os.path.isfile(os.path.join('results', 'finished_'+filename[:filename.rindex('.')]+'.txt')):
abort(404)
return
return send_from_directory('results',filename)
def service_worker():
return send_from_directory('static/', 'service-worker.js')
def uploaded_file(filename): # pragma: no cover
"""Return uploaded file."""
return send_from_directory(uploader.upload_folder, filename)
def download_avatar(fname):
if platform.system() == "Windows":
path = UPLOAD_AVATAR_FOLDER + "/" + fname # windows??????????????????????
else:
path = os.path.join(UPLOAD_AVATAR_FOLDER, fname) # ?????
if os.path.isfile(path):
return send_from_directory(UPLOAD_AVATAR_FOLDER, fname, as_attachment=True)
abort(404)
def download_music(fname):
if platform.system() == "Windows":
path = UPLOAD_FOLDER + "/" + fname # windows??????????????????????
else:
path = os.path.join(UPLOAD_FOLDER, fname) # ?????
if os.path.isfile(path):
return send_from_directory(UPLOAD_FOLDER, fname, as_attachment=True)
abort(404)
def get_image(img_name):
if platform.system() == "Windows":
path = UPLOAD_IMAGE_FOLDER + "/" + img_name # windows??????????????????????
else:
path = os.path.join(UPLOAD_IMAGE_FOLDER, img_name) # ?????
if os.path.isfile(path):
return send_from_directory(UPLOAD_IMAGE_FOLDER, img_name, as_attachment=True)
abort(404)
def uploaded_file(filename):
return send_from_directory(FULL_UPLOAD_PATH, filename)
def send_static(path):
return send_from_directory('static', path)
def get_visualization(filename):
return send_from_directory(VIZ_FOLDER, filename)
def get_mbtiles(id):
return send_from_directory(
IMAGERY_PATH,
os.path.join(id, 'index.mbtiles'),
as_attachment=True,
attachment_filename='{}.mbtiles'.format(id),
conditional=True
)
# TODO allow bounding boxes + zoom ranges to be provided
def api_pheno(phenocode):
return send_from_directory(common_filepaths['manhattan'](''), phenocode)
def api_pheno_qq(phenocode):
return send_from_directory(common_filepaths['qq'](''), phenocode)
def web_remote_file():
remote_path = request.args.get('path')
if not remote_path:
return "No remote path given."
local_path, name = get_remote_file(remote_path)
if not local_path:
return "Remote file '{}' not found.".format(remote_path)
res = send_from_directory(local_path, name, as_attachment=True)
shutil.rmtree(local_path)
return res
# ########################################################################### #
# API Part #
# ########################################################################### #
def template_files(filename):
template_path = os.path.join(current_app.root_path,
current_app.template_folder)
return send_from_directory(template_path, filename)