admin 管理员组文章数量: 887021
root
本文整理匯總了Python中flask.current_app.root_path方法的典型用法代碼示例。如果您正苦於以下問題:Python current_app.root_path方法的具體用法?Python current_app.root_path怎麽用?Python current_app.root_path使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊flask.current_app的用法示例。
在下文中一共展示了current_app.root_path方法的16個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: load_file
點讚 6
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def load_file(self, filename):
"""
Load the filename from the local directory. The type of the returned
object depends on if the filename corresponds to a file or a directory.
If it's a file, a flask Response object containing the file's data will
be returned. If it's a directory, a gopher menu will be returned.
This method uses the flask application context, which means that it
can only be invoked from inside of a flask view.
"""
abs_filename = safe_join(self.local_directory, filename)
if not os.path.isabs(abs_filename):
abs_filename = os.path.join(current_app.root_path, abs_filename)
if os.path.isfile(abs_filename):
return self.result_class(False, send_file(abs_filename))
elif os.path.isdir(abs_filename):
data = self._parse_directory(filename, abs_filename)
return self.result_class(True, data)
else:
raise BadRequest()
開發者ID:michael-lazar,項目名稱:flask-gopher,代碼行數:23,
示例2: setup
點讚 6
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def setup(obj):
log.info('setting up fixtures...')
# Push a request and/or app context onto the stack
push_ctx(getattr(obj, 'app'))
# Setup the database
obj.db.create_all()
# Rollback any lingering transactions
obj.db.session.rollback()
# Construct a list of paths within which fixtures may reside
default_fixtures_dir = os.path.join(current_app.root_path, 'fixtures')
# All relative paths should be relative to the app's root directory.
fixtures_dirs = [default_fixtures_dir]
for directory in current_app.config.get('FIXTURES_DIRS', []):
if not os.path.isabs(directory):
directory = os.path.abspath(os.path.join(current_app.root_path, directory))
fixtures_dirs.append(directory)
# Load all of the fixtures
for filename in obj.fixtures:
load_fixtures_from_file(obj.db, filename, fixtures_dirs)
開發者ID:croach,項目名稱:Flask-Fixtures,代碼行數:27,
示例3: get_conf_json
點讚 6
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def get_conf_json(path, file):
"""
通用: 獲取 JSON 配置文件
:param path: 相對於 conf, e.g. bgp
:param file: 文件名, 不帶擴展名, e.g. as-name
:return: dict,e.g. {'123': '成都'}
"""
ret = {}
file = os.path.join(current_app.root_path, 'conf', path, file + '.json')
try:
with open(file, 'r', encoding='utf-8') as f:
ret = json.load(f)
except Exception as e:
current_app.logger.error('{0!r} {1}'.format(e, file))
return ret
開發者ID:fufuok,項目名稱:FF.PyAdmin,代碼行數:20,
示例4: plugin
點讚 6
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def plugin(plugin):
if request.method == "GET":
plugins_path = os.path.join(app.root_path, "plugins")
config_html_plugins = [
name
for name in os.listdir(plugins_path)
if os.path.isfile(os.path.join(plugins_path, name, "config.html"))
]
if plugin in config_html_plugins:
config_html = open(
os.path.join(app.root_path, "plugins", plugin, "config.html")
).read()
return render_template_string(config_html)
abort(404)
elif request.method == "POST":
for k, v in request.form.items():
if k == "nonce":
continue
set_config(k, v)
with app.app_context():
clear_config()
return "1"
開發者ID:CTFd,項目名稱:CTFd,代碼行數:26,
示例5: calendar_dir
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def calendar_dir() -> str:
"""獲得日曆文件路徑。生產環境為/var/calendar_files/,否則為程序根目錄下的calendar_files文件夾。"""
if get_env() == "PRODUCTION":
return "/var/calendar_files/"
return (current_app.root_path or "") + "/../../calendar_files/"
開發者ID:everyclass,項目名稱:everyclass-server,代碼行數:7,
示例6: _exist_config
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def _exist_config(app):
filename = "{}/config.py".format(app.root_path)
return os.path.exists(filename)
開發者ID:chaijunit,項目名稱:beibq,代碼行數:5,
示例7: create_config
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def create_config(username, password, host, db):
data = render_template("admin/start/config.html", username=username,
password=password, host=host, db = db)
filename = '{}/config.py'.format(current_app.root_path)
fd = open(filename, "w")
fd.write(data)
fd.close()
開發者ID:chaijunit,項目名稱:beibq,代碼行數:9,
示例8: create_path
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def create_path(app):
paths, config = [], app.config
log_path, _ = os.path.split(config["ERROR_LOG"])
paths.append(os.path.join(app.root_path, log_path))
paths.append(os.path.join(app.static_folder, config["AVATAR_PATH"]))
paths.append(os.path.join(app.static_folder, config["TMP_PATH"]))
paths.append(os.path.join(app.static_folder, config["IMAGE_PATH"]))
paths.append(os.path.join(app.static_folder, config["BOOK_COVER_PATH"]))
for path in paths:
if not os.path.exists(path):
os.makedirs(path)
開發者ID:chaijunit,項目名稱:beibq,代碼行數:14,
示例9: swagger_spec
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def swagger_spec():
try:
spec_path = os.path.join(current_app.root_path, "swagger-spec.yaml")
spec = open(spec_path, 'r')
loaded_spec = load(spec.read(), Loader)
except Exception as e:
current_app.logger.error(
'Cannot view swagger spec. Error: {0}'.format(e))
current_app.logger.debug(traceback.format_exc())
abort(500)
resp = make_response(json.dumps(loaded_spec), 200)
resp.headers['Content-Type'] = 'application/json'
return resp
開發者ID:ngoduykhanh,項目名稱:PowerDNS-Admin,代碼行數:17,
示例10: home
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def home():
filename = request.form['filename']
filename=filename.replace('../','')
if os.path.isfile(current_app.root_path + '/'+ filename):
with current_app.open_resource(filename) as f:
read = f.read()
else:
read='try harder'
return render_template("index.html",read = read)
開發者ID:blabla1337,項目名稱:skf-labs,代碼行數:11,
示例11: home
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def home():
filename = urllib.parse.unquote(request.form['filename'])
read='try harder...'
if '../' not in filename:
filename = urllib.parse.unquote(filename)
if os.path.isfile(current_app.root_path + '/'+ filename):
with current_app.open_resource(filename) as f:
read = f.read()
return render_template("index.html",read = read)
開發者ID:blabla1337,項目名稱:skf-labs,代碼行數:11,
示例12: themes
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def themes(theme, path):
"""
General static file handler
:param theme:
:param path:
:return:
"""
filename = safe_join(app.root_path, "themes", theme, "static", path)
if os.path.isfile(filename):
return send_file(filename)
else:
abort(404)
開發者ID:CTFd,項目名稱:CTFd,代碼行數:14,
示例13: stamp_latest_revision
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def stamp_latest_revision():
# Get proper migrations directory regardless of cwd
directory = os.path.join(os.path.dirname(app.root_path), "migrations")
stamp(directory=directory)
開發者ID:CTFd,項目名稱:CTFd,代碼行數:6,
示例14: get_themes
點讚 5
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def get_themes():
dir = os.path.join(app.root_path, "themes")
return [
name
for name in os.listdir(dir)
if os.path.isdir(os.path.join(dir, name)) and name != "admin"
]
開發者ID:CTFd,項目名稱:CTFd,代碼行數:9,
示例15: build_url
點讚 4
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def build_url(component, filename, **values):
"""
search bower asset and build url
:param component: bower component (package)
:type component: str
:param filename: filename in bower component - can contain directories (like dist/jquery.js)
:type filename: str
:param values: additional url parameters
:type values: dict[str, str]
:return: url
:rtype: str | None
"""
root = current_app.config['BOWER_COMPONENTS_ROOT']
bower_data = None
package_data = None
# check if component exists in bower_components directory
if not os.path.isdir(os.path.join(current_app.root_path, root, component)):
# FallBack to default url_for flask
return None
# load bower.json of specified component
bower_file_path = os.path.join(current_app.root_path, root, component, 'bower.json')
if os.path.exists(bower_file_path):
with open(bower_file_path, 'r') as bower_file:
bower_data = json.load(bower_file)
# check if package.json exists and load package.json data
package_file_path = os.path.join(current_app.root_path, root, component, 'package.json')
if os.path.exists(package_file_path):
with open(package_file_path, 'r') as package_file:
package_data = json.load(package_file)
# check if specified file actually exists
if not os.path.exists(os.path.join(current_app.root_path, root, component, filename)):
return None
# check if minified file exists (by pattern .min.
# returns filename if successful
if current_app.config['BOWER_TRY_MINIFIED']:
if '.min.' not in filename:
minified_filename = '%s.min.%s' % tuple(filename.rsplit('.', 1))
minified_path = os.path.join(root, component, minified_filename)
if os.path.exists(os.path.join(current_app.root_path, minified_path)):
filename = minified_filename
# determine version of component and append as ?version= parameter to allow cache busting
if current_app.config['BOWER_QUERYSTRING_REVVING']:
if bower_data is not None and 'version' in bower_data:
values['version'] = bower_data['version']
elif package_data is not None and 'version' in package_data:
values['version'] = package_data['version']
else:
values['version'] = os.path.getmtime(os.path.join(current_app.root_path, root, component, filename))
return url_for('bower.serve', component=component, filename=filename, **values)
開發者ID:lobeck,項目名稱:flask-bower,代碼行數:60,
示例16: export_ctf
點讚 4
# 需要導入模塊: from flask import current_app [as 別名]
# 或者: from flask.current_app import root_path [as 別名]
def export_ctf():
# TODO: For some unknown reason dataset is only able to see alembic_version during tests.
# Even using a real sqlite database. This makes this test impossible to pass in sqlite.
db = dataset.connect(get_app_config("SQLALCHEMY_DATABASE_URI"))
# Backup database
backup = tempfile.NamedTemporaryFile()
backup_zip = zipfile.ZipFile(backup, "w")
tables = db.tables
for table in tables:
result = db[table].all()
result_file = BytesIO()
freeze_export(result, fileobj=result_file)
result_file.seek(0)
backup_zip.writestr("db/{}.json".format(table), result_file.read())
# # Guarantee that alembic_version is saved into the export
if "alembic_version" not in tables:
result = {
"count": 1,
"results": [{"version_num": get_current_revision()}],
"meta": {},
}
result_file = BytesIO()
json.dump(result, result_file)
result_file.seek(0)
backup_zip.writestr("db/alembic_version.json", result_file.read())
# Backup uploads
uploader = get_uploader()
uploader.sync()
upload_folder = os.path.join(
os.path.normpath(app.root_path), app.config.get("UPLOAD_FOLDER")
)
for root, dirs, files in os.walk(upload_folder):
for file in files:
parent_dir = os.path.basename(root)
backup_zip.write(
os.path.join(root, file),
arcname=os.path.join("uploads", parent_dir, file),
)
backup_zip.close()
backup.seek(0)
return backup
開發者ID:CTFd,項目名稱:CTFd,代碼行數:50,
注:本文中的flask.current_app.root_path方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
本文标签: root
版权声明:本文标题:root 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1688263370h198849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论