本文整理汇总了Python中uliweb.utils.common.pkg.resource_filename函数的典型用法代码示例。如果您正苦于以下问题:Python resource_filename函数的具体用法?Python resource_filename怎么用?Python resource_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resource_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, options, global_options, *args):
from uliweb.utils.pyini import Ini
from uliweb.utils.common import pkg
from uliweb.contrib.template.tags import find
from uliweb.contrib.staticfiles import url_for_static
from uliweb import json_dumps
if not options.dest and not options.app:
print 'Error: Please use -d to specify output app'
sys.exit(1)
app = self.get_application(global_options)
if options.app:
settings_file = pkg.resource_filename(options.app, 'settings.ini')
x = Ini(settings_file)
else:
x = app.settings
if options.dest:
filename = pkg.resource_filename(options.dest, '/static/jsmodules.js')
else:
filename = pkg.resource_filename(options.app, '/static/jsmodules.js')
d = {}
for name in x.get('TEMPLATE_USE', {}).keys():
s = find(name)
m = s[0] + s[1]
d[name] = [url_for_static(i) for i in m if not i.startswith('<!--')]
print 'jsmodules.js is saved in {} please check'.format(filename)
with open(filename, 'wb') as f:
f.write('var jsmodules = ')
f.write(json_dumps(d))
示例2: process
def process(self, theme_name, data, options, global_options, args):
from uliweb.utils.common import pkg, copy_dir
import shutil
from uliweb.utils.pyini import Ini
#if there is no apps/appname then create files in current directory
path = os.path.join(global_options.apps_dir, data['appname'])
if not os.path.exists(path):
path = '.'
gpath = pkg.resource_filename('uliweb.contrib.generic', 'template_files/%s' % theme_name)
def render(fpath, dst, df):
text = template_file(fpath, data).replace('\r\n', '\n')
open(df, 'w').write(text)
return True
#copy template files
copy_dir(os.path.join(gpath, 'templates'), os.path.join(path, 'templates', data['classname']),
processor=render)
#process config.ini
src_config = os.path.join(gpath, 'config.ini')
dst_config = os.path.join(path, 'config.ini')
if os.path.exists(dst_config):
dst = Ini(dst_config)
src = Ini(src_config)
for x in src.DEPENDS.REQUIRED_APPS:
if x not in dst.DEPENDS.REQUIRED_APPS:
dst.DEPENDS.REQUIRED_APPS.append(x)
dst.save()
else:
shutil.copy2(os.path.join(gpath, 'config.ini'), path)
cpath = pkg.resource_filename('uliweb.contrib.generic', 'template_files/common')
#check if layout is existed, if not then create it
layout_file = os.path.join(path, 'templates', data['layout'])
if not os.path.exists(layout_file):
self.copy_template(os.path.join(cpath, 'layout.html'), data, layout_file)
#copy views file
self.copy_view(os.path.join(cpath, 'views.py.tmpl'), data,
os.path.join(path, data['viewfile']), options.replace)
#copy add, edit, view
dpath = os.path.join(path, 'templates', data['classname'])
if data['addview_popup']:
self.copy_template(os.path.join(cpath, 'ajax_add.html'), data, os.path.join(dpath, 'add.html'))
else:
self.copy_template(os.path.join(cpath, 'add.html'), data, os.path.join(dpath, 'add.html'))
if data['editview_popup']:
self.copy_template(os.path.join(cpath, 'ajax_edit.html'), data, os.path.join(dpath, 'edit.html'))
else:
self.copy_template(os.path.join(cpath, 'edit.html'), data, os.path.join(dpath, 'edit.html'))
self.copy_template(os.path.join(cpath, 'view.html'), data, os.path.join(dpath, 'view.html'))
示例3: handle
def handle(self, options, global_options, *args):
from uliweb.utils.common import check_apps_dir
opts = {'verbose':global_options.verbose, 'template':options.template,
'exact':options.exact}
if options.project:
check_apps_dir(global_options.apps_dir)
app = self.get_application(global_options)
_process(global_options.apps_dir, options.locale, opts, output_dir=global_options.project)
elif options.apps or args:
check_apps_dir(global_options.apps_dir)
app = self.get_application(global_options)
if options.apps:
_apps = SimpleFrame.get_apps(global_options.apps_dir)
else:
_apps = args
apps_dir = os.path.normpath(os.path.abspath(global_options.apps_dir))
for appname in _apps:
path = SimpleFrame.get_app_dir(appname)
if global_options.verbose:
print 'Processing... app=>[%s] path=>[%s]' % (appname, path)
_process(path, options.locale, opts)
elif options.uliweb:
path = pkg.resource_filename('uliweb', '')
_process(path, options.locale, opts)
elif options.directory:
_process(options.directory, options.locale, opts)
示例4: handle
def handle(self, options, global_options, *args):
from uliweb.utils.common import copy_dir
from uliweb.utils.common import pkg
_types = []
support_dirs = {}
app_dirs = [
os.path.join(SimpleFrame.get_app_dir(appname), "template_files/support")
for appname in self.get_apps(global_options)
]
for path in [pkg.resource_filename("uliweb", "template_files/support/")] + app_dirs:
if os.path.exists(path):
for f in os.listdir(path):
_path = os.path.join(path, f)
if os.path.isdir(_path) and not f.startswith("."):
_name = f
_types.append(_name)
support_dirs[_name] = _path
support_type = args[0] if args else ""
while not support_type in _types and support_type != "quit":
print "Supported types:\n"
print " " + "\n ".join(sorted(_types))
print
support_type = raw_input("Please enter support type[quit to exit]:")
if support_type != "quit":
src_dir = support_dirs[support_type]
copy_dir(src_dir, ".", verbose=global_options.verbose)
示例5: _loader
def _loader(filename):
from werkzeug.exceptions import Forbidden, NotFound
from uliweb.utils.common import pkg
app = self.app
f = None
if dir:
fname = os.path.normpath(os.path.join(dir, filename)).replace('\\', '/')
if not fname.startswith(dir):
return Forbidden("You can only visit the files under static directory."), None
if os.path.exists(fname):
f = fname
else:
for p in reversed(app.apps):
fname = os.path.normpath(os.path.join('static', filename)).replace('\\', '/')
if not fname.startswith('static/'):
return Forbidden("You can only visit the files under static directory."), None
ff = pkg.resource_filename(p, fname)
if os.path.exists(ff):
f = ff
break
if f:
return f, self._opener(f)
return NotFound("Can't found the file %s" % filename), None
示例6: handle
def handle(self, options, global_options, *args):
from uliweb.utils.common import copy_dir
from uliweb.utils.common import pkg
_types = []
support_dirs = {}
app_dirs = [os.path.join(SimpleFrame.get_app_dir(appname), 'template_files/support') for appname in self.get_apps(global_options)]
for path in [pkg.resource_filename('uliweb', 'template_files/support/')] + app_dirs:
if os.path.exists(path):
for f in os.listdir(path):
_path = os.path.join(path, f)
if os.path.isdir(_path) and not f.startswith('.'):
_name = f
_types.append(_name)
support_dirs[_name] = _path
support_type = args[0] if args else ''
while not support_type in _types and support_type != 'quit':
print 'Supported types:\n'
print ' ' + '\n '.join(sorted(_types))
print
support_type = raw_input('Please enter support type[quit to exit]:')
if support_type != 'quit':
src_dir = support_dirs[support_type]
copy_dir(src_dir, '.', verbose=global_options.verbose)
示例7: get_settings
def get_settings(project_dir, include_apps=None, settings_file='settings.ini',
local_settings_file='local_settings.ini', default_settings=None):
apps_dir = os.path.join(project_dir, 'apps')
apps = get_apps(apps_dir, settings_file=settings_file, local_settings_file=local_settings_file)
settings = []
inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
settings.insert(0, inifile)
for p in apps:
path = get_app_dir(p)
#deal with settings
inifile =os.path.join(get_app_dir(p), 'settings.ini')
if os.path.exists(inifile):
settings.append(inifile)
set_ini = os.path.join(apps_dir, settings_file)
if os.path.exists(set_ini):
settings.append(set_ini)
local_set_ini = os.path.join(apps_dir, local_settings_file)
if os.path.exists(local_set_ini):
settings.append(local_set_ini)
x = pyini.Ini()
for v in settings:
x.read(v)
x.update(default_settings or {})
#process FILESYSTEM_ENCODING
if not x.GLOBAL.FILESYSTEM_ENCODING:
x.GLOBAL.FILESYSTEM_ENCODING = sys.getfilesystemencoding() or x.GLOBAL.DEFAULT_ENCODING
return x
示例8: develop_app_conf
def develop_app_conf():
module = request.GET['module']
app_path = pkg.resource_filename(module, '')
form = '<h3>Nothing need to configure!</h3>'
message = ''
if is_pyfile_exist(app_path, 'conf'):
try:
mod = __import__(module + '.conf', {}, {}, [''])
f = getattr(mod, 'ManageForm', None)
if f:
form = f(action=url_for(develop_app_conf)+'?module=%s' % module, method='post')
if request.method == 'POST':
ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
default_ini = Ini(os.path.join(app_path, 'settings.ini'))
r = form.validate(request.POST)
if r:
flag = form_to_ini(form, ini, default_ini)
if flag:
message = '<div class="note">Changes have been saved!</div>'
ini.save()
else:
message = '<div class="important">There are no changes.</div>'
else:
message = '<div class="warning">There are some errors.</div>'
elif request.method == 'GET':
ini = Ini()
ini_file = os.path.join(app_path, 'settings.ini')
if os.path.exists(ini_file):
ini.read(ini_file)
ini.read(os.path.join(application.apps_dir, 'settings.ini'))
ini_to_form(form, ini)
except ImportError, e:
log.exception(e)
示例9: collect_modules
def collect_modules(self, check_view=True):
modules = {}
views = set()
settings = []
inifile = pkg.resource_filename("uliweb.core", "default_settings.ini")
settings.insert(0, inifile)
def enum_views(views_path, appname, subfolder=None, pattern=None):
if not os.path.exists(views_path):
log.error("Can't found the app %s path, please check if the path is right" % appname)
return
for f in os.listdir(views_path):
fname, ext = os.path.splitext(f)
if (
os.path.isfile(os.path.join(views_path, f))
and ext in [".py", ".pyc", ".pyo"]
and fname != "__init__"
):
if pattern:
import fnmatch
if not fnmatch.fnmatch(f, pattern):
continue
if subfolder:
views.add(".".join([appname, subfolder, fname]))
else:
views.add(".".join([appname, fname]))
for p in self.apps:
path = get_app_dir(p)
# deal with views
if check_view:
views_path = os.path.join(path, "views")
if os.path.exists(views_path) and os.path.isdir(views_path):
enum_views(views_path, p, "views")
else:
enum_views(path, p, pattern="views*")
# deal with settings
inifile = os.path.join(get_app_dir(p), "settings.ini")
if os.path.exists(inifile):
settings.append(inifile)
set_ini = os.path.join(self.apps_dir, self.settings_file)
if os.path.exists(set_ini):
settings.append(set_ini)
local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
if os.path.exists(local_set_ini):
settings.append(local_set_ini)
modules["views"] = list(views)
modules["settings"] = settings
return modules
示例10: handle
def handle(self, options, global_options, *args):
from uliweb.utils.common import extract_dirs, pkg
from uliweb.core.template import template_file
extract_dirs('uliweb.contrib.orm', 'templates/alembic', '.', verbose=global_options.verbose, replace=False)
engine_string = get_engine(options, global_options)
ini_file = os.path.join(pkg.resource_filename('uliweb.contrib.orm', 'templates/alembic/alembic.ini'))
text = template_file(ini_file, {'CONNECTION':engine_string})
with open(os.path.join(global_options.project, 'alembic.ini'), 'w') as f:
f.write(text)
示例11: collect_modules
def collect_modules(self, check_view=True):
modules = {}
views = []
settings = []
inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
settings.insert(0, ('', inifile))
def enum_views(views_path, appname, subfolder=None, pattern=None):
if not os.path.exists(views_path):
log.error("Can't found the app %s path, please check if the path is right" % appname)
return
for f in os.listdir(views_path):
fname, ext = os.path.splitext(f)
if os.path.isfile(os.path.join(views_path, f)) and ext in ['.py', '.pyc', '.pyo'] and fname!='__init__':
if pattern:
import fnmatch
if not fnmatch.fnmatch(f, pattern):
continue
if subfolder:
_view = '.'.join([appname, subfolder, fname])
else:
_view = '.'.join([appname, fname])
if _view not in views:
views.append(_view)
for p in self.apps:
path = get_app_dir(p)
#deal with views
if check_view:
views_path = os.path.join(path, 'views')
if os.path.exists(views_path) and os.path.isdir(views_path):
enum_views(views_path, p, 'views')
else:
enum_views(path, p, pattern='views*')
#deal with settings
inifile =os.path.join(get_app_dir(p), 'settings.ini')
if os.path.exists(inifile):
settings.append((p, inifile))
set_ini = os.path.join(self.apps_dir, self.settings_file)
if os.path.exists(set_ini):
settings.append(('', set_ini))
local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
if os.path.exists(local_set_ini):
settings.append(('', local_set_ini))
modules['views'] = views
modules['settings'] = settings
return modules
示例12: init
def init(self, project_dir, apps_dir):
if not project_dir:
project_dir = norm_path(os.path.join(apps_dir, '..'))
Dispatcher.project_dir = project_dir
Dispatcher.apps_dir = norm_path(os.path.join(project_dir, 'apps'))
Dispatcher.apps = get_apps(self.apps_dir, self.include_apps, self.settings_file, self.local_settings_file)
Dispatcher.modules = self.collect_modules()
self.install_settings(self.modules['settings'])
self.debug = settings.GLOBAL.get('DEBUG', False)
#process global_objects
self.install_global_objects()
#process binds
self.install_binds()
dispatch.call(self, 'after_init_settings')
Dispatcher.settings = settings
#process domains
self.process_domains(settings)
#setup log
self.set_log()
#set app rules
rules.set_app_rules(dict(settings.get('URL', {})))
rules.set_urlroute_rules(dict(settings.get('URL_ROUTE', {})))
Dispatcher.env = self._prepare_env()
Dispatcher.template_dirs = self.get_template_dirs()
Dispatcher.template_loader = self.install_template_loader(Dispatcher.template_dirs)
#begin to start apps
self.install_apps()
dispatch.call(self, 'after_init_apps')
#process views
self.install_views(self.modules['views'])
#process exposes
self.install_exposes()
#process middlewares
Dispatcher.middlewares = self.install_middlewares()
dispatch.call(self, 'prepare_default_env', Dispatcher.env)
Dispatcher.default_template = pkg.resource_filename('uliweb.core', 'default.html')
Dispatcher.installed = True
示例13: init
def init(self, project_dir, apps_dir):
if not project_dir:
project_dir = norm_path(os.path.join(apps_dir, ".."))
Dispatcher.project_dir = project_dir
Dispatcher.apps_dir = norm_path(os.path.join(project_dir, "apps"))
Dispatcher.apps = get_apps(self.apps_dir, self.include_apps, self.settings_file, self.local_settings_file)
Dispatcher.modules = self.collect_modules()
self.install_settings(self.modules["settings"])
# process global_objects
self.install_global_objects()
# process binds
self.install_binds()
dispatch.call(self, "after_init_settings")
Dispatcher.settings = settings
# process domains
self.process_domains(settings)
# setup log
self.set_log()
# set app rules
rules.set_app_rules(dict(settings.get("URL", {})))
Dispatcher.env = self._prepare_env()
Dispatcher.template_dirs = self.get_template_dirs()
Dispatcher.template_processors = {}
self.install_template_processors()
# begin to start apps
self.install_apps()
dispatch.call(self, "after_init_apps")
# process views
self.install_views(self.modules["views"])
# process exposes
self.install_exposes()
# process middlewares
Dispatcher.middlewares = self.install_middlewares()
self.debug = settings.GLOBAL.get("DEBUG", False)
dispatch.call(self, "prepare_default_env", Dispatcher.env)
Dispatcher.default_template = pkg.resource_filename("uliweb.core", "default.html")
Dispatcher.installed = True
示例14: get_file
def get_file(self, filename, dir='static'):
"""
get_file will search from apps directory
"""
if os.path.exists(filename):
return filename
dirs = self.apps
if dir:
fname = os.path.join(dir, filename)
else:
fname = filename
for d in reversed(dirs):
path = pkg.resource_filename(d, fname)
if os.path.exists(path):
return path
return None
示例15: collect_modules
def collect_modules(self, check_view=True):
modules = {}
views = set()
settings = []
inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
settings.insert(0, inifile)
def enum_views(views_path, appname, subfolder=None, pattern=None):
for f in os.listdir(views_path):
fname, ext = os.path.splitext(f)
if os.path.isfile(os.path.join(views_path, f)) and ext in ['.py', '.pyc', '.pyo'] and fname!='__init__':
if pattern:
import fnmatch
if not fnmatch.fnmatch(f, pattern):
continue
if subfolder:
views.add('.'.join([appname, subfolder, fname]))
else:
views.add('.'.join([appname, fname]))
for p in self.apps:
path = get_app_dir(p)
#deal with views
if check_view:
views_path = os.path.join(path, 'views')
if os.path.exists(views_path) and os.path.isdir(views_path):
enum_views(views_path, p, 'views')
else:
enum_views(path, p, pattern='views*')
#deal with settings
inifile =os.path.join(get_app_dir(p), 'settings.ini')
if os.path.exists(inifile):
settings.append(inifile)
set_ini = os.path.join(self.apps_dir, self.settings_file)
if os.path.exists(set_ini):
settings.append(set_ini)
local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
if os.path.exists(local_set_ini):
settings.append(local_set_ini)
modules['views'] = list(views)
modules['settings'] = settings
return modules