本文整理汇总了Python中string.Template类的典型用法代码示例。如果您正苦于以下问题:Python Template类的具体用法?Python Template怎么用?Python Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Template类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _create_report
def _create_report(self):
context = aq_inner(self.context)
date = datetime.datetime.now()
token = django_random.get_random_string(length=24)
item = api.content.create(
type='xpose.seodash.report',
id=token,
title='Report {0} {1}'.format(date.strftime("%B"),
date.strftime("%Y")),
container=context,
safe_id=True
)
uuid = api.content.get_uuid(obj=item)
template_file = os.path.join(os.path.dirname(__file__),
'report.json')
template = Template(open(template_file).read())
template_vars = {
'id': uuid_tool.uuid4(),
'uid': uuid,
'timestamp': int(time.time()),
'created': datetime.datetime.now(),
'dashboard': api.content.get_uuid(obj=context),
}
report = template.substitute(template_vars)
setattr(item, 'report', report)
modified(item)
item.reindexObject(idxs='modified')
return uuid
开发者ID:potzenheimer,项目名称:xdash,代码行数:28,代码来源:dashboard.py
示例2: writeMembers
def writeMembers(c):
members = members_begin
for m in c["members"]:
members += member.safe_substitute(membername=m["name"], membertype=m["type"], comment=m["comment"])
members += members_end
members = Template(members)
print(members.substitute(classname=c["name"]))
开发者ID:Tomoyon,项目名称:makehuman1.0.0alpha7,代码行数:7,代码来源:wrapper.py
示例3: pattern_to_file
def pattern_to_file(input_l):
# 入力List[test_so,test_si,pi,pi,po]をテストパターンのリストに置き換える
# 入力List[{test_so='aaaa',..},{..}]
output = []
template = Template(' Ann {* fast_sequential *}\n' + \
' "pattern ${num}": Call "load_unload" { \n' + \
' "test_so"=${test_so}; ' + \
'"test_si"=${test_si}; }\n' + \
' Call "${launch}" { \n' + \
' "_pi"=${pi_1}; }\n' + \
' Call "${capture}" { \n' + \
' "_pi"=${pi_2}; "_po"=${po}; }\n')
template_first = Template(' Ann {* fast_sequential *}\n' + \
' "pattern ${num}": Call "load_unload" { \n' + \
' "test_si"=${test_si}; }\n' + \
' Call "${launch}" { \n' + \
' "_pi"=${pi_1}; }\n' + \
' Call "${capture}" { \n' + \
' "_pi"=${pi_2}; "_po"=${po}; }\n')
for i, l in enumerate(input_l):
l['num'] = i
if i == 0:
line = template_first.substitute(l)
output.append(line)
else:
#l['num'] = i + 1
line = template.substitute(l)
output.append(line)
return(output)
开发者ID:Kztka,项目名称:NNCT_Study,代码行数:30,代码来源:sort_min_transition.py
示例4: filter
def filter(self, ):
if (self.filters and len(self.filters) > 0):
self.filter_params = self.stage_dir + 'filters.txt'
try:
with open(self.filter_params, 'w') as f:
f.write('--keep="{0}"\n'.format(' or '.join(self.filters)))
except IOError as e:
logger.error('Error saving filter params file', e)
# can't filter so return the raw data
shutil.copy(self.raw_osm, self.filtered_osm)
return self.filtered_osm
# convert to om5 for faster processing
om5 = self._convert_om5()
# filter om5 data
filter_tmpl = Template(
'osmfilter $om5 --parameter-file=$params --out-osm >$filtered_osm'
)
filter_cmd = filter_tmpl.safe_substitute({'om5': om5,
'params': self.filter_params,
'filtered_osm': self.filtered_osm})
proc = subprocess.Popen(filter_cmd, shell=True, executable='/bin/bash',
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
returncode = proc.wait()
if (returncode != 0):
logger.error('%s', stderr)
raise Exception, "osmfilter process failed with returncode {0}".format(returncode)
return self.filtered_osm
else:
logger.error('No filters found. Returning raw osm data.')
shutil.copy(self.raw_osm, self.filtered_osm)
return self.filtered_osm
开发者ID:dodobas,项目名称:osm-export-tool2,代码行数:35,代码来源:overpass.py
示例5: renderTemplates
def renderTemplates(inAndOutFilePaths, options, relPathToSdk, absPathToSdk, renderTarget, jobsAndDescs=[]):
for inFile, outFile in inAndOutFilePaths:
console.log("Patching file '%s'" % outFile)
#config = MyTemplate(open(inFile).read())
config = Template(open(inFile).read())
out = open(outFile, "w")
context = {
"Name": options.name,
"Namespace": options.namespace,
"NamespacePath" : (options.namespace).replace('.', '/'),
"REL_QOOXDOO_PATH": relPathToSdk,
"ABS_QOOXDOO_PATH": absPathToSdk,
"QOOXDOO_VERSION": QOOXDOO_VERSION,
"Cache" : options.cache,
}
if renderTarget == TARGET.GRUNT:
context["JOBS_AND_DESCS"] = jobsAndDescs
for k, v in context.iteritems():
if isinstance(v, (str, unicode)):
context[k] = gruntifyMacros(v);
out.write(config.substitute(context).encode('utf-8'))
out.close()
os.remove(inFile)
开发者ID:leandrorchaves,项目名称:qooxdoo,代码行数:27,代码来源:create-application.py
示例6: GenerateBridgeWrapperMethod
def GenerateBridgeWrapperMethod(self):
no_return_value = self._method_return == 'void'
return_is_internal = self.IsInternalClass(self._method_return)
if return_is_internal:
return_type_java_data = self.LoadJavaClass(self._method_return)
template = Template(
' public ${RETURN_TYPE} ${NAME}(${PARAMS}) {\n' +
' ${RETURN}ReflectionHelper.invokeMethod(\n' +
' ${METHOD_DECLARE_NAME}, wrapper${PARAMS_PASSING});\n' +
' }\n\n')
if no_return_value:
return_statement = ''
elif return_is_internal:
return_statement = 'return (%s)' % return_type_java_data.bridge_name
else:
return_statement = 'return (%s)' % (
ConvertPrimitiveTypeToObject(self.method_return))
value = {'RETURN_TYPE': self.method_return,
'NAME': self.method_name,
'METHOD_DECLARE_NAME': self._method_declare_name,
'PARAMS': self._bridge_params_declare,
'RETURN': return_statement,
'PARAMS_PASSING': self._bridge_params_pass_to_wrapper}
return template.substitute(value)
开发者ID:Jabawack,项目名称:crosswalk,代码行数:25,代码来源:java_method.py
示例7: GenerateWrapperStaticMethod
def GenerateWrapperStaticMethod(self):
no_return_value = self._method_return == 'void'
template = Template(
' public static ${RETURN_TYPE} ${NAME}(${PARAMS}) {\n' +
' Class<?> clazz = ReflectionHelper.loadClass(' +
'\"${FULL_BRIDGE_NAME}\");\n' +
' Method method = ReflectionHelper.loadMethod(clazz, ' +
'\"${NAME}\"${PARAMS_DECLARE_FOR_BRIDGE});\n' +
' ${RETURN}ReflectionHelper.invokeMethod(method, null' +
'${PARAMS_PASSING});\n' +
' }\n\n')
if no_return_value:
return_state = ''
else:
return_state = 'return (%s)' % ConvertPrimitiveTypeToObject(
self.method_return)
value = {'RETURN_TYPE': self.method_return,
'NAME': self.method_name,
'FULL_BRIDGE_NAME': self._class_java_data.GetFullBridgeName(),
'PARAMS_DECLARE_FOR_BRIDGE':
self._wrapper_params_declare_for_bridge,
'PARAMS_PASSING': self._wrapper_params_pass_to_bridge,
'PARAMS': self._wrapper_params_declare,
'RETURN': return_state}
return template.substitute(value)
开发者ID:Jabawack,项目名称:crosswalk,代码行数:25,代码来源:java_method.py
示例8: _download_and_format_issues
def _download_and_format_issues():
try:
from robot.utils import HtmlWriter, html_format
except ImportError:
sys.exit('creating release requires Robot Framework to be installed.')
URL = Template('http://code.google.com/p/robotframework-ride/issues/csv?'
'sort=priority+type&colspec=ID%20Type%20Priority%20Summary'
'&q=target%3A${version}&can=1')
reader = csv.reader(urlopen(URL.substitute({'version': VERSION})))
total_issues = 0
writer = HtmlWriter(StringIO())
writer.element('h2', 'Release notes for %s' % VERSION)
writer.start('table', attrs={'border': '1'})
for row in reader:
if not row or row[1] == 'Task':
continue
row = row[:4]
writer.start('tr')
if reader.line_num == 1:
row = [ '*%s*' % cell for cell in row ]
else:
row[0] = '<a href="http://code.google.com/p/robotframework-ride/'\
'issues/detail?id=%s">Issue %s</a>' % (row[0], row[0])
total_issues += 1
for cell in row:
if reader.line_num == 1:
cell = html_format(cell)
writer.element('td', cell, escape=False)
writer.end('tr')
writer.end('table')
writer.element('p', 'Altogether %d issues.' % total_issues)
return writer.output.getvalue()
开发者ID:lostmouse,项目名称:RIDE,代码行数:32,代码来源:pavement.py
示例9: send_mail
def send_mail(self, correlations, time, script):
"""Simple convenience function which sends an email \
from the configured sender to receivers.
:param correlations: number representing the combined \
number of threats to be reported.
:type correlations: :mod:`int`
:param time: the time it took for the calling program \
to execute and finish successfully.
:type time: :mod:`string`
:param script: the script which was invoked such that a \
detailed job description can be provided to correlation notifications.
:type time: :mod:`string`
"""
description = self.get_description(script)
message = Template("""
<br><img src="cid:image1" width="200"><br>
<p>You are receiving this email because you are subscribed to <b>Assurant's Threat Intelligence notification service</b>.</p>
<p><b>$corr threat correlation(s) have been identified</b> whilst running one of our threat correlation scripts.</p>
<p>Identified correlations relate to: <b>$desc</b>.</p>
<p>To view correlation(s) please visit the Kibana dashboard.</p>
<p>Time taken to identify correlations was <b>$dur seconds</b>.</p>
<p><i>To unsubscribe from this service please contact $sender</i>.</p>
""")
fullMessage = message.substitute(corr=correlations, dur=time, sender=sender, desc=description)
# Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Assurant Threatelligence Update'
msgRoot['From'] = sender
msgRoot['To'] = receivers
msgRoot.preamble = 'This is a multi-part message in MIME format.'
# Encapsulate the plain and HTML versions of the message body in an
# 'alternative' part, so message agents can decide which they want to display.
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText('This is the alternative plain text message.')
msgAlternative.attach(msgText)
# We reference the image in the IMG SRC attribute by the ID we give it below
#msgRoot = MIMEText()
msgText = MIMEText(fullMessage, 'html')
msgAlternative.attach(msgText)
# This example assumes the image is in the current directory
fp = open('assurant-logo.png', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
# Define the image's ID as referenced above
msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage)
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(sender, '')
smtpObj.sendmail(sender, receivers, msgRoot.as_string())
smtpObj.quit()
开发者ID:gfunkoriginal,项目名称:Threatelligence,代码行数:60,代码来源:intelnotification.py
示例10: call_realign_single
def call_realign_single(java, gatk, ref_seq, blocks, input_list, output_map, target_intervals, known_vcfs, mem="8g"):
known_str = " ".join(list("-known %s" % (a) for a in known_vcfs))
template = Template("""
${JAVA}
-Xmx${MEM} -XX:ParallelGCThreads=2 -jar ${GATK}
-T IndelRealigner
-R ${REF_SEQ}
-disable_auto_index_creation_and_locking_when_reading_rods
-I ${INPUT_LIST}
-targetIntervals ${TARGET_INTERVALS}
${KNOWN_STR}
-nWayOut ${OUTPUT_MAP}
""".replace("\n", " "))
#for i, block in enumerate(fai_chunk( ref_seq + ".fai", block_size ) ):
#for i, block in enumerate(blocks):
cmd = template.substitute(
dict(
JAVA=java,
REF_SEQ=ref_seq,
GATK=gatk,
#BLOCK_NUM=i,
#INTERVAL="%s:%s-%s" % (block[0], block[1], block[2]),
#INTERVAL="%s" % (block),
INPUT_LIST=input_list,
#OUTPUT_BASE=output_base,
OUTPUT_MAP=output_map,
KNOWN_STR=known_str,
TARGET_INTERVALS=target_intervals,
MEM=mem
)
)
return cmd
开发者ID:Jeltje,项目名称:pcawg_tools,代码行数:34,代码来源:indel_realign.py
示例11: call_scan
def call_scan(java, gatk, ncpus, ref_seq, input_list, known_vcfs, intervals, mem="8g"):
known_str = " ".join(list("-known %s" % (a) for a in known_vcfs))
#out = "%s.intervals" % (output_base)
out = intervals
template = Template("""
${JAVA}
-Xmx${MEM} -XX:ParallelGCThreads=2 -jar ${GATK}
-T RealignerTargetCreator
-disable_auto_index_creation_and_locking_when_reading_rods
-nt ${NCPUS}
-R ${REF_SEQ}
-I ${INPUT_LIST}
${KNOWN_STR}
-o ${OUT}
""".replace("\n", " "))
#output_base
cmd = template.substitute(
dict(
JAVA=java,
REF_SEQ=ref_seq,
GATK=gatk,
INPUT_LIST=input_list,
# OUTPUT_BASE=output_base,
KNOWN_STR=known_str,
NCPUS=ncpus,
OUT=out,
MEM=mem
))
return cmd #, out
开发者ID:Jeltje,项目名称:pcawg_tools,代码行数:30,代码来源:indel_realign.py
示例12: addressOrIntersection
def addressOrIntersection(cross_street0, cross_street1) :
place = None
street_address = Template("$street_0")
intersection = Template("$street_0 & $street_1")
if cross_street0 :
# Sometimes street addresses are written out, particularly
# 'One' and sometimes 'Two.' Right now we are only catching
# addresses that start with a sequence of numbers a space and
# something that is not a number or whitespace (ideally an
# letter.
if re.compile('\d+ [\D\W]').match(cross_street0) :
place = street_address.substitute(street_0 = cross_street0)
else :
if cross_street1 and cross_street1 != cross_street0 :
# Likely fertile place for improvement
xstreet_splitter = re.compile('(.+)( and |/)(.+)')
xstreet_split = xstreet_splitter.findall(cross_street1)
if xstreet_split :
xstreet0 = xstreet_split[0][0].strip()
xstreet1 = xstreet_split[0][2].strip()
else :
xstreet0 = cross_street0
xstreet1 = cross_street1
xstreet0 = xstreet0.title()
xstreet1 = xstreet1.title()
place = intersection.substitute(street_0 = xstreet0,
street_1 = xstreet1)
return place
开发者ID:fgregg,项目名称:neighborhoods,代码行数:31,代码来源:geocode_labels.py
示例13: gen_qsub_script
def gen_qsub_script(script, name='qsub_magic', nodes=1, ppn=1, walltime='01:00:00',
mailto='[email protected]', path=os.getcwd(), pre=[], post=[], logfile='',
isdonefile=''):
''' Generate a template to be runned using qsub.'''
tplate = Template('\n'.join(
['#!/bin/sh',
'#PBS -S /bin/sh',
'#PBS -N $name',
'#PBS -j oe',
'#PBS -l nodes=$nodes:ppn=$ppn,walltime=$walltime',
'#PBS -M $mailto',
'#PBS -m abe',
'cd $path',
'ulimit -s unlimited'] +
pre +
[ 'python $script > $logfile &&',
' echo 0 > $isdonefile ||',
' echo 1 > $isdonefile'] +
post +
['return 0']))
qsub_script = tplate.substitute(name=name, nodes=nodes, ppn=ppn,
walltime=walltime, mailto=mailto,
path=path, script=script, logfile=logfile,
isdonefile=isdonefile)
return qsub_script
开发者ID:cphyc,项目名称:ipython-qsub,代码行数:26,代码来源:submit.py
示例14: replace_template
def replace_template(infile, vars, outfile):
with open(infile, "r") as template_file:
temp = Template(template_file.read())
result = temp.substitute(vars)
with open(outfile, "w") as out:
out.write(result)
开发者ID:nachocarballeda,项目名称:kicad-project-generator,代码行数:7,代码来源:gen_project.py
示例15: GetMethodIDImpl
def GetMethodIDImpl(self, called_by_native):
"""Returns the implementation of GetMethodID."""
template = Template("""\
base::android::MethodID::LazyGet<
base::android::MethodID::TYPE_${STATIC}>(
env, ${JAVA_CLASS}_clazz(env),
"${JNI_NAME}",
${JNI_SIGNATURE},
&g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME});
""")
jni_name = called_by_native.name
jni_return_type = called_by_native.return_type
if called_by_native.is_constructor:
jni_name = '<init>'
jni_return_type = 'void'
if called_by_native.signature:
signature = called_by_native.signature
else:
signature = self.jni_params.Signature(called_by_native.params,
jni_return_type, True)
java_class = self.fully_qualified_class
if called_by_native.java_class_name:
java_class += '$' + called_by_native.java_class_name
values = {
'JAVA_CLASS': GetBinaryClassName(java_class),
'JNI_NAME': jni_name,
'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name,
'STATIC': 'STATIC' if called_by_native.static else 'INSTANCE',
'JNI_SIGNATURE': signature,
}
return template.substitute(values)
开发者ID:scheib,项目名称:chromium,代码行数:31,代码来源:jni_generator.py
示例16: do_GET
def do_GET(self):
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
self.end_headers()
return
elif self.path == '/jsmpg.js':
content_type = 'application/javascript'
content = self.server.jsmpg_content
elif self.path == '/index.html':
content_type = 'text/html; charset=utf-8'
tpl = Template(self.server.index_template)
content = tpl.safe_substitute(dict(
ADDRESS='%s:%d' % (self.request.getsockname()[0], WS_PORT),
WIDTH=WIDTH, HEIGHT=HEIGHT, COLOR=COLOR, BGCOLOR=BGCOLOR, ROTATION = ROTATION))
else:
self.send_error(404, 'File not found')
return
content = content.encode('utf-8')
self.send_response(200)
self.send_header('Content-Type', content_type)
self.send_header('Content-Length', len(content))
self.send_header('Last-Modified', self.date_time_string(time()))
self.end_headers()
if self.command == 'GET':
self.wfile.write(content)
开发者ID:NiklasMerz,项目名称:pistreaming,代码行数:26,代码来源:server.py
示例17: get_init_colors
def get_init_colors(*inks):
process_color_value = '{0} {1} {2} {3}'
init_process_colors_tpl = Template(\
'/setcmykcolor where {pop\n $value setcmykcolor\n \
100 100 moveto 101 101 lineto stroke\n} if')
custom_color_value = '{0} {1} {2} {3} ({name})'
init_custom_colors_tpl = Template(\
'/findcmykcustomcolor where {pop\n $value\n \
findcmykcustomcolor 1 setcustomcolor\n 100 100 moveto 101 101 \
lineto stroke\n} if')
process_colors_init = []
custom_colors_init = []
for ink in inks:
if is_process_color(ink):
value = process_color_value.format(*process_colors[ink.name])
process_colors_init.append(
init_process_colors_tpl.substitute({'value': value}))
else:
value = custom_color_value.format(*ink.cmyk, name=escape_string(ink.name))
custom_colors_init.append(
init_custom_colors_tpl.substitute({'value': value}))
return init_colors.substitute({
'initProcessColors': '\n'.join(process_colors_init),
'initCustomColors' : '\n'.join(custom_colors_init)
})
开发者ID:entropik,项目名称:multitoner,代码行数:31,代码来源:epstool.py
示例18: __str__
def __str__(self):
bset_spec = []
for el, bset in self.basis_set.items():
bset_spec.append(" {} library \"{}\"".format(el, bset))
theory_spec = []
if self.theory_directives:
theory_spec.append("{}".format(self.theory))
for k, v in self.theory_directives.items():
theory_spec.append(" {} {}".format(k, v))
theory_spec.append("end")
t = Template("""title "$title"
charge $charge
basis
$bset_spec
end
$theory_spec
task $theory $operation""")
return t.substitute(
title=self.title, charge=self.charge,
bset_spec="\n".join(bset_spec),
theory_spec="\n".join(theory_spec),
theory=self.theory, operation=self.operation)
开发者ID:leicheng,项目名称:pymatgen,代码行数:25,代码来源:nwchemio.py
示例19: GenerateWrapperConstructor
def GenerateWrapperConstructor(self):
# TODO(wang16): Currently, only support pre/post wrapper lines for
# Constructors.
template = Template(
'${DOC}\n' +
' public ${CLASS_NAME}(${PARAMS}) {\n' +
'${PRE_WRAP_LINES}\n' +
' bridge = ReflectionHelper.createInstance(' +
'\"${CONSTRUCTOR_DECLARE_NAME}\"${PARAMS_PASSING}, this);\n' +
' try {\n' +
' reflectionInit();\n' +
' } catch(Exception e) {\n' +
' ReflectionHelper.handleException(e);\n' +
' }\n' +
'${POST_WRAP_LINES}\n' +
' }\n\n')
value = {'CLASS_NAME': self._class_java_data.wrapper_name,
'DOC': self.GenerateDoc(self.method_doc),
'PARAMS': self._wrapper_params_declare,
'PARAMS_PASSING': self._wrapper_params_pass_to_bridge,
'CONSTRUCTOR_DECLARE_NAME': self._method_declare_name,
'PRE_WRAP_LINES': self._method_annotations.get(
self.ANNOTATION_PRE_WRAPLINE, ''),
'POST_WRAP_LINES': self._method_annotations.get(
self.ANNOTATION_POST_WRAPLINE, '')}
return template.substitute(value)
开发者ID:Jabawack,项目名称:crosswalk,代码行数:26,代码来源:java_method.py
示例20: get_html
def get_html(self):
"""Return the HTML content"""
StaticFile = Pool().get('nereid.static.file')
# XXX: Use read, as all fields are not required
banner = self.read(
[self], [
'type', 'click_url', 'file', 'file.mimetype',
'custom_code', 'height', 'width',
'alternative_text', 'click_url'
]
)[0]
if banner['type'] == 'media':
if not (banner['file.mimetype'] and
banner['file.mimetype'].startswith('image')):
return "<!-- no html defined for mime type '%s' -->" % \
banner['file.mimetype']
# replace the `file` in the dictionary with the complete url
# that is required to render the image based on static file
file = StaticFile(banner['file'])
banner['file'] = file.url
image = Template(
u'<a href="$click_url">'
u'<img src="$file" alt="$alternative_text"'
u' width="$width" height="$height"/>'
u'</a>'
)
return image.substitute(**banner)
elif banner['type'] == 'custom_code':
return banner['custom_code']
开发者ID:priyankarani,项目名称:nereid-cms,代码行数:31,代码来源:cms.py
注:本文中的string.Template类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论