本文整理汇总了Python中pyramid.scaffolds.template.Template.pre方法的典型用法代码示例。如果您正苦于以下问题:Python Template.pre方法的具体用法?Python Template.pre怎么用?Python Template.pre使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.scaffolds.template.Template
的用法示例。
在下文中一共展示了Template.pre方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
"""
Overrides ``pyramid.scaffold.template.Template.pre``, adding
several variables to the default variables list. Also prevents
common misnamings (such as naming a package "site" or naming a
package logger "root").
"""
ret = Template.pre(self, command, output_dir, vars)
self._set_package_in_vars(command, vars)
if vars["package"] == "site":
raise ValueError(
"Sorry, you may not name your package 'site'. "
"The package name 'site' has a special meaning in "
"Python. Please name it anything except 'site'.")
package_logger = vars["package"]
if package_logger == "root":
# Rename the app logger in the rare case a project
# is named "root"
package_logger = "app"
vars["package_logger"] = package_logger
return ret
示例2: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)
示例3: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
vars['random_string'] = os.urandom(20).encode('hex')
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)
示例4: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
if vars['package'] == 'site':
raise ValueError('Sorry, you may not name your package "site". '
'The package name "site" has a special meaning in '
'Python. Please name it anything except "site".')
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)
示例5: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
""" Overrides :meth:`pyramid.scaffolds.template.Template.pre`, adding
several variables to the default variables list (including
``random_string``, and ``package_logger``). It also prevents common
misnamings (such as naming a package "site" or naming a package
logger "root".
"""
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)
示例6: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars_):
"""
Overrides ``pyramid.scaffold.template.Template.pre``, adding
several variables to the default variables list. Also prevents
common misnamings (such as naming a package "site" or naming a
package logger "root").
"""
self._get_vars(vars_, "package", "Get a package name: ")
self._get_vars(
vars_, "srid",
"Spatial Reference System Identifier (e.g. 21781): ", int,
)
srid = vars_["srid"]
extent = self._epsg2bbox(srid)
self._get_vars(
vars_, "extent",
"Extent (minx miny maxx maxy): in EPSG: {srid} projection, default is "
"[{bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}]: ".format(srid=srid, bbox=extent)
if extent else
"Extent (minx miny maxx maxy): in EPSG: {srid} projection: ".format(srid=srid)
)
match = re.match(r"([\d.]+)[,; ] *([\d.]+)[,; ] *([\d.]+)[,; ] *([\d.]+)", vars_["extent"])
if match is not None:
extent = [match.group(n + 1) for n in range(4)]
vars_["extent"] = ",".join(extent)
vars_["extent_mapserver"] = " ".join(extent)
vars_["extent_viewer"] = json.dumps(extent)
ret = Template.pre(self, command, output_dir, vars_)
if vars_["package"] == "site":
raise ValueError(
"Sorry, you may not name your package 'site'. "
"The package name 'site' has a special meaning in "
"Python. Please name it anything except 'site'.")
package_logger = vars_["package"]
if package_logger == "root":
# Rename the app logger in the rare case a project
# is named "root"
package_logger = "app"
vars_["package_logger"] = package_logger
c2cgeoportal_version = pkg_resources.get_distribution('c2cgeoportal_commons') \
.parsed_version._version.release
vars_["geomapfish_version"] = "{}.{}".format(c2cgeoportal_version[0], c2cgeoportal_version[1])
return ret
示例7: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
""" Overrides :meth:`pyramid.scaffold.template.Template.pre`, adding
several variables to the default variables list (including
``random_string``, and ``package_logger``). It also prevents common
misnamings (such as naming a package "site" or naming a package
logger "root".
"""
if vars['package'] == 'site':
raise ValueError('Sorry, you may not name your package "site". '
'The package name "site" has a special meaning in '
'Python. Please name it anything except "site".')
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
vars['package_dirname'] = os.path.dirname(vars['package_full_name'])
vars['test_package_full_name'] = re.sub(r'\/', '/test_', vars['package_full_name'])
if vars['test_package_full_name'][0:3] != 'test' and vars['test_package_full_name'][0:4] != '/test':
vars['test_package_full_name'] = re.sub(r'^', 'test_', vars['test_package_full_name'])
vars['test_package_dirname'] = re.sub(r'\/', '/test_', vars['package_dirname'])
if vars['test_package_dirname'][0:3] != 'test' and vars['test_package_dirname'][0:4] != '/test':
vars['test_package_dirname'] = re.sub(r'^', 'test_', vars['test_package_dirname'])
if vars['package_dirname'] == '' or vars['package_dirname'] == '.':
vars['test_package_dirname'] = '.'
vars['package_full_name_dot'] = re.sub(r'\/', '.', vars['package_full_name'])
vars['package_dirname_dot'] = re.sub(r'\/', '.', vars['package_dirname'])
vars['package_dirname_dot_with_app'] = 'app.' + vars['package_dirname_dot']
if vars['package_dirname'] == '' or vars['package_dirname'] == '.':
vars['package_dirname_dot_with_app'] = 'app'
logging.warning('command: ' + repr(command))
logging.warning('output_dir: ' + repr(output_dir))
logging.warning('vars: ' + repr(vars))
vars['project_camelcase'] = underscore_to_camelcase(vars['project'])
vars['project_camelcase_uppercase'] = underscore_to_camelcase_uppercase(vars['project'])
the_tmp = re.sub(ur'\.', '_', vars['project'])
vars['project_underscore'] = re.sub(ur'-', '_', the_tmp)
return Template.pre(self, command, output_dir, vars)
示例8: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
""" Overrides :meth:`pyramid.scaffold.template.Template.pre`, adding
several variables to the default variables list (including
``random_string``, and ``package_logger``). It also prevents common
misnamings (such as naming a package "site" or naming a package
logger "root".
"""
if vars['package'] == 'site':
raise ValueError('Sorry, you may not name your package "site". '
'The package name "site" has a special meaning in '
'Python. Please name it anything except "site".')
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)
示例9: pre
# 需要导入模块: from pyramid.scaffolds.template import Template [as 别名]
# 或者: from pyramid.scaffolds.template.Template import pre [as 别名]
def pre(self, command, output_dir, vars):
""" Overrides `pre` method to verify if package name is not equals of
anything package.
"""
package_name = os.path.abspath('.').split('/')[-1]
blacklist_names = ('site', package_name)
if vars['package'] in blacklist_names:
msg = """
Sorry, you may not name your "{0}". This name "{0}" has been
defined. Please name it anything except "{0}".
""".format(vars['package'])
raise ValueError(msg)
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
vars['root_project'] = package_name
package_logger = vars['package']
if package_logger == 'root':
# Rename the app logger in the rare case a project is named 'root'
package_logger = 'app'
vars['package_logger'] = package_logger
return Template.pre(self, command, output_dir, vars)