本文整理汇总了Python中pystache.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _render
def _render(self, articles):
template_string = ''
with open(self.template['content'], 'r') as f:
template_string = f.read().decode('utf-8')
content_parsed = pystache.parse(template_string)
with open(self.template['layout'], 'r') as f:
template_string = f.read().decode('utf-8')
layout_parsed = pystache.parse(template_string)
params = []
for article in articles:
dt = datetime.datetime.fromtimestamp(article['issued'])
params.append({
'href': article['filename'] + '.html',
'date': dt.strftime('%b %d, %Y'),
'title': article['title'],
})
contents = self.renderer.render(content_parsed, {'articles': params})
dt = datetime.datetime.now()
param = {
'content': contents,
'date': dt.strftime('%b %d, %Y'),
'date_iso': dt.isoformat(),
'author': articles[0]['author'],
'url': self.html_filename,
}
dest_path = os.path.join(self.output_path, self.html_filename)
with open(dest_path, 'w') as f:
f.write(self.renderer.render(layout_parsed, param).encode('utf-8'))
开发者ID:cou929,项目名称:Misc-stuffs,代码行数:31,代码来源:view.py
示例2: __init__
def __init__(self, template_file, dest_file_template_str, overwrite=True):
"""Ctor.
@param template_file: Filename of the mustache template.
@param dest_file_template_str: Destination file name. This is a
mustache template, so each resource can write to a unique file.
@param overwrite: If True, destination file is ovewritten if it exists.
"""
template_str = unicode(open(template_file, "r").read())
self.template = pystache.parse(template_str)
dest_file_template_str = unicode(dest_file_template_str)
self.dest_file_template = pystache.parse(dest_file_template_str)
self.overwrite = overwrite
开发者ID:GGGO,项目名称:asterisk,代码行数:13,代码来源:transform.py
示例3: mustache_template
def mustache_template(self, namespace, data):
"""
Takes a namespace and finds it's file. Takes that file and parses it's
template. Then takes that template, loads the partials for it, and
renderers the template, given the data and the partials.
"""
partials_path = config.build_paths['partials_path'] + "/"
paths = namespace.split('.')
file_path = '/'.join(paths) + '.mustache'
partials = dict()
if self.application.debug == True:
with open(config.build_paths['mustache_path'] + '/' + file_path) as f:
read_data = f.read()
read_data = unicode(read_data)
for (dirpath, dirname, filenames) in os.walk(partials_path):
dirpath += '/' if not dirpath.endswith('/') else ''
new_namespace = dirpath.replace(partials_path, '')
new_namespace = new_namespace.replace('/', '.')
for filename in filenames:
if filename.endswith('.mustache'):
with open(dirpath + filename) as f:
read_file = f.read()
filename = filename.replace(".mustache", "")
partials[new_namespace + filename] = read_file
parsed_template = pystache.parse(read_data)
renderer = pystache.Renderer(partials=partials)
return renderer.render(parsed_template, data)
else:
return 'no bueno'
开发者ID:benasher44,项目名称:clornado,代码行数:32,代码来源:template_methods.py
示例4: parse_templates
def parse_templates(self, templates):
for template in templates:
print "Parse template: %s" % os.path.join(self.template_dir, template)
with codecs.open(os.path.join(self.template_dir, template), 'r', 'utf-8') as content_file:
content = content_file.read()
self.templates[template.strip('.mustache')] = pystache.parse(content)
开发者ID:benjiao,项目名称:torrent-bot,代码行数:7,代码来源:responses.py
示例5: parse_template
def parse_template(template_text):
if six.PY2:
# pystache does a typecheck for unicode in python 2.x but rewrites its sources to deal
# unicode via str in python 3.x.
template_text = unicode(template_text)
template = pystache.parse(template_text)
return template
开发者ID:MathewJennings,项目名称:pants,代码行数:7,代码来源:mustache.py
示例6: generate_xmls
def generate_xmls(json_filenames):
xml_template_str = unicode(open('tool-template.xml').read())
xml_template = pystache.parse(xml_template_str)
for tool_path in json_filenames:
desc = json.load(open(tool_path))
desc['collectionName'] = desc['collectionName'].capitalize()
print pystache.render(xml_template, desc)
开发者ID:edamontology,项目名称:toolinfowarehouse,代码行数:7,代码来源:json2xml.py
示例7: parse_mustache_template
def parse_mustache_template(self, origin, source):
if origin not in self._parsed or settings.DEBUG: # no cache in DEBUG mode
try:
self._parsed[origin] = pystache.parse(smart_unicode(source))
except pystache.parser.ParsingError, e:
# better error
raise pystache.parser.ParsingError("Mustache couldn't parse {0}, reason : '{1}'.".format(origin, e))
开发者ID:liberation,项目名称:django-mustache,代码行数:7,代码来源:loader.py
示例8: render
def render(values):
renderer = pystache.Renderer()
with codecs.open('template.mustache', 'r', 'utf-8') as templateFile:
template = templateFile.read()
parsed = pystache.parse(template)
return renderer.render(parsed, values)
开发者ID:avilaton,项目名称:iritrac-robots,代码行数:7,代码来源:txt2kml.py
示例9: remove_components
def remove_components(self, template, tags):
new_components = []
tags = set(tags)
parsed = pystache.parse(safe_decode(template))
last_removed = False
for i, el in enumerate(parsed._parse_tree):
if hasattr(el, 'parsed'):
keys = [e.key for e in el.parsed._parse_tree if hasattr(e, 'key') and e.key not in tags]
if keys:
new_components.append(self.build_first_of_template(keys))
last_removed = False
else:
last_removed = True
elif hasattr(el, 'key'):
if el.key not in tags:
new_components.append('{{{{{{{key}}}}}}}'.format(key=el.key))
last_removed = False
else:
last_removed = True
elif not last_removed:
new_components.append(el)
else:
last_removed = False
return ''.join(new_components).strip()
开发者ID:BERENZ,项目名称:libpostal,代码行数:27,代码来源:formatter.py
示例10: subscribe
def subscribe(args):
consumer = KafkaConsumer(args.kafka_topic,
group_id=args.kafka_group_id,
metadata_broker_list=args.kafka_server.split(','))
renderer = pystache.Renderer()
logging.info("rsync_cmd: [{0}]".format(" ".join(args.rsync_cmd)))
templates = [ pystache.parse(unicode(c,"UTF-8")) for c in args.rsync_cmd ]
for message in consumer:
o = json.loads(message.value)
if not "maskname" in o:
continue
if o["maskname"] in ["IN_IGNORED","IN_DELETE"]:
continue
if 'dir' in o and o['dir']:
continue
cmd = [ renderer.render(t, {'o': o,'args':args}) for t in templates ]
target = cmd[-1]
# ensure the parent folder exists, having a hard time
# otherwise getting rsync to do this
folder = os.path.dirname(cmd[-1])
if not os.path.exists(folder):
os.makedirs(folder)
cmd.insert(0,"rsync")
logging.info("executing: "+" ".join(cmd))
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError, e:
logging.info("failed to execute: "+" ".join(cmd))
if e.output:
logging.info(e.output)
开发者ID:fullergalway,项目名称:docker-inotify2kafka,代码行数:32,代码来源:kafka-rsync.py
示例11: __init__
def __init__(self, template_text, **template_data):
# pystache does a typecheck for unicode in python 2.x but rewrites its sources to deal unicode
# via str in python 3.x.
if Compatibility.PY2:
template_text = unicode(template_text)
self._template = pystache.parse(template_text)
self.template_data = template_data
开发者ID:steliokontos,项目名称:commons,代码行数:7,代码来源:generator.py
示例12: build
def build(self, profile):
""" Build static website """
Console.info("Executing Konstrukteur...")
Console.indent()
self.__templatePath = os.path.join("source", "template")
self.__contentPath = os.path.join("source", "content")
self.__sourcePath = os.path.join("source")
self.__profile = profile
self.__fileManager = FileManager.FileManager(profile)
if not os.path.exists(self.__templatePath):
raise RuntimeError("Path to templates not found : %s" % self.__templatePath)
if not os.path.exists(self.__contentPath):
raise RuntimeError("Path to content not found : %s" % self.__contentPath)
if self.theme:
theme = session.getProjectByName(self.theme)
if not theme:
raise RuntimeError("Theme '%s' not found" % self.theme)
self.__postUrl = pystache.parse(self.posturl)
self.__pageUrl = pystache.parse(self.pageurl)
self.__feedUrl = pystache.parse(self.feedurl)
self.__parseTemplate()
self.__build()
if self.regenerate:
fileChangeEventHandler = konstrukteur.FileWatcher.FileChangeEventHandler()
observer = Observer()
observer.schedule(fileChangeEventHandler, self.__sourcePath, recursive=True)
observer.start()
try:
Console.info("Waiting for file changes (abort with CTRL-C)")
while True:
time.sleep(1)
if fileChangeEventHandler.dirty:
fileChangeEventHandler.dirty = False
self.__build()
except KeyboardInterrupt:
observer.stop()
observer.join()
Console.outdent()
开发者ID:fastner,项目名称:konstrukteur,代码行数:46,代码来源:Konstrukteur.py
示例13: __init__
def __init__(self):
client = pymongo.MongoClient()
self.auth_db = flowboard_auth.AuthDatabase(client)
self.auth_service = flowboard_auth.AuthService(self.auth_db)
self.posts_db = flowboard_posts.PostDatabase(client)
FlowBoard.instance = self
self.secret = "6LekGR4TAAAAADn4OR-Gr8pYqdpIJiv79re8fy24"
self.index_parsed = pystache.parse(''.join(open('index.html').readlines()))
self.renderer = pystache.Renderer()
self.recent_posts_html = self.most_recent_posts_html(10)
self.notify_update()
开发者ID:daemon,项目名称:flowboard,代码行数:11,代码来源:flowboard.py
示例14: render
def render(self, template_path, output_path, variables={}):
with open (self.template_root + template_path, "r") as myfile:
data=myfile.read()
parsed = pystache.parse(u"%(data)s" % locals())
renderer = pystache.Renderer()
output = renderer.render(parsed, variables)
with open (os.getcwd() + "/temp/" + output_path, "w") as myfile:
myfile.write(output)
return os.getcwd() + "/temp/" + output_path
开发者ID:Cygnus-Labs,项目名称:opendaylight-integration,代码行数:12,代码来源:deploy.py
示例15: main
def main(config_path):
with open(config_path) as simple_config_file:
simple_config=json.load(simple_config_file)
# These are not something the user will put into their simple config,
# so we need to get it from the environment (it will have been set by the start_services_in_container.sh script)
simple_config['sensu_server_ip_address'] = os.environ['SENSU_SERVER_IP_ADDRESS']
simple_config['queue_host'] = os.environ['SENSU_SERVER_IP_ADDRESS']
simple_config['fleet_name'] = os.environ['FLEET_NAME']
config_path = os.path.dirname(__file__)
with open(config_path +'/pancancer_config.mustache') as mustache_template_file:
mustache_template=mustache_template_file.read()
renderer=pystache.Renderer()
parsed=pystache.parse(mustache_template)
rendered_str=renderer.render(parsed,(simple_config))
data=json.loads(rendered_str)
# The master config file should be written to ~/.pancancer/pancancer_config.json
with open(config_path + '/pancancer_config.json','w') as master_config_file:
master_config_file.write(str(json.dumps(data,sort_keys=True, indent=4) ))
# Youxia config should go to ~/.youxia/config
with open(config_path + '/youxia_config','w') as youxia_file:
youxia_settings=data['youxia']
youxia_str=processYouxiaSettings(youxia_settings)
youxia_file.write(youxia_str)
# params.json should go to ~/params.json
with open(config_path + '/params.json','w') as params_json_file:
params_settings=data['params']
params_str=processParams(params_settings)
params_json_file.write(params_str)
# masterConfig should go to ~/arch3/config/masterConfig.ini
with open(config_path + '/masterConfig.ini','w') as consonance_file:
consonance_settings=data['consonance']
consonance_str=processConsonanceSettings(consonance_settings)
consonance_file.write(consonance_str)
#create the server tags, if necessary. The user can change this file later, and we won't touch it (since it already exists).
server_tags_path = os.path.expanduser('~/arch3/server-tags.json')
if not os.path.exists(server_tags_path):
with open(server_tags_path,'w') as server_tags_file:
server_tags={'KEEP':os.environ['FLEET_NAME']}
server_tags_file.write(str(json.dumps(server_tags,sort_keys=True, indent=4) ))
shutil.copy2(config_path + '/youxia_config','/home/ubuntu/.youxia/config')
shutil.copy2(config_path + '/masterConfig.ini','/home/ubuntu/arch3/config/masterConfig.ini')
shutil.copy2(config_path + '/params.json','/home/ubuntu/params.json')
开发者ID:vferretti,项目名称:cli,代码行数:51,代码来源:process_config.py
示例16: __init__
def __init__(self,argv,cols_):
self.db = DEFDB
self.noddl = False
self.dbdir = None
self.tables = {}
self.tableList = []
optlist, _ = getopt.getopt(argv, "", LONGOPTIONS)
for opt,arg in optlist:
if opt == "--dbconf":
self.dbconfFile = arg
elif opt == "--dbdir":
self.dbdir = arg
elif opt == "--noddl":
self.noddl = True
if self.dbconfFile is None:
raise Exception( "Missing required --dbconf file.")
if PatJSON.match( self.dbconfFile ) is None:
self.dbconfFile += ".json"
if not os.path.isfile(self.dbconfFile):
raise Exception( "Missing DBConf file. %s" % (self.dbconfFile) )
with open (self.dbconfFile, "r") as f:
self.dbconf = json.load(f)
if self.dbdir is None:
if "dbdir" not in self.dbconf:
raise Exception("Missing required --dbdir parameter or dbconf parameter.")
self.dbdir = self.dbconf["dbdir"]
if not os.path.isdir(self.dbdir):
raise Exception("DBDir doesn't exists %s" % (self.dbdir) )
self.ddldbdir = self.dbdir + "/ddl"
if not os.path.isdir(self.ddldbdir):
raise Exception("DBDir/ddl doesn't exists %s" % (self.ddldbdir) )
self.dmldbdir = self.dbdir + "/dml"
if not os.path.isdir(self.dmldbdir):
raise Exception("DBDir/dml doesn't exists %s" % (self.dmldbdir) )
self.ddlrenderer = pystache.Renderer(search_dirs=[self.ddldbdir])
self.dmlrenderer = pystache.Renderer(search_dirs=[self.dmldbdir])
self.arraySubtables = self.dbconf["array_subtables"]
if self.arraySubtables:
if (not "array_template" in self.dbconf):
self.dbconf["array_template"] = "arraytablename"
self.arrayTemplate = self.ddlrenderer.load_template(self.dbconf["array_template"])
else:
self.arrayTemplate = pystache.parse(self.dbconf["array_template"])
if self.arrayTemplate is None:
raise Exception("Array table name template unable to load. %s" % (self.dbconf["array_template"]))
for col in cols_.keys():
self.registerCol( col, cols_[col] )
self.genddl()
开发者ID:KeyBridge,项目名称:sfaf,代码行数:48,代码来源:py2sql.py
示例17: template
def template(x, cntx, master=False):
# x = template name
# cntx = stuff you want to pass
# master = do not touch!!!!
if x in templates:
renderer = pystache.Renderer()
o = renderer.render( templates[x], cntx )
if master:
return o
else:
cntx['content'] = o
return template("layout", cntx, True)
else:
templates[ x ] = pystache.parse( unicode(open('referencecat/gui/web/%s.html' % x).read() ))
o = template( x, cntx, master )
if debug:
del templates[x]
return o
开发者ID:kennydude,项目名称:reference-cat,代码行数:18,代码来源:__init__.py
示例18: create_changelog
def create_changelog(current_version,
previous_version,
repo,
milestone=None,
token=os.environ.get('GITHUB_TOKEN', None),
description=None,
since=None,
date=datetime.utcnow(),
template=changelog_template,
logger=EmptyLogger()):
logger.debug('Creating changelog for %s from %s' % (current_version, repo))
description = description or 'The v%s release of %s' % (current_version,
repo.split('/')[1])
issues = get_closed_issues(repo=repo,
token=token,
since=since,
logger=logger)
if milestone:
milestone[
'html_url'] = 'https://github.com/%s/issues?q=milestone%%3Av%s+is%%3Aall' % (
repo, current_version)
data = {
'version': {
'from': str(previous_version)
if previous_version > (0, 0, 0) else None,
'to': str(current_version),
},
'milestone': milestone,
'date': date.isoformat()[:10],
'repo': repo,
'description': description,
'issues': [i for i in issues if not i.get('pull_request', None)],
'pullrequests': [i for i in issues if i.get('pull_request', None)],
}
renderer = pystache.Renderer()
parsed = pystache.parse(template)
changelog = renderer.render(parsed, data)
logger.info('Rendered changelog')
return changelog
开发者ID:vcatechnology,项目名称:cmake-boilerplate,代码行数:39,代码来源:__init__.py
示例19: _render
def _render(self, articles):
template_string = ''
with open(self.template['layout'], 'r') as f:
template_string = f.read()
parsed = pystache.parse(template_string)
for article in articles:
markdown_string = ''
with open(article['path'], 'r') as f:
f.readline() # remove header
markdown_string = f.read()
html = markdown2.markdown(markdown_string)
dt = datetime.datetime.fromtimestamp(article['issued'])
view_params = {
'title': article['title'],
'date': dt.strftime('%d %B %Y'),
'date_iso': dt.isoformat(),
'author': article['author'],
'url': article['filename'] + '.html',
'disqus_id': article['filename'],
'content': html,
'is_article': True,
'year': dt.strftime('%Y'),
}
if 'prev' in article:
view_params['prev_article'] = {
'url': article['prev']['filename'] + '.html',
'title': article['prev']['title']
}
if 'next' in article:
view_params['next_article'] = {
'url': article['next']['filename'] + '.html',
'title': article['next']['title']
},
dest_path = os.path.join(self.output_path,
article['filename'] + '.html')
with open(dest_path, 'w') as f:
f.write(self.renderer.render(parsed, view_params))
开发者ID:cou929,项目名称:rug,代码行数:38,代码来源:view.py
示例20: export
def export(self, template_file_name, output_file_name, sort):
"""Export ranking to a file
Args:
template_file_name (str): where is the template (moustache template)
output_file_name (str): where create the file with the ranking
sort (str): field to sort the users
"""
exportedData = {}
dataUsers = self.getSortedUsers(sort)
exportedUsers = []
position = 1
for u in dataUsers:
userExported = u.export()
userExported["position"] = position
exportedUsers.append(userExported)
if position < len(dataUsers):
userExported["comma"] = True
position+=1
exportedData["users"] = exportedUsers
with open(template_file_name) as template_file:
template_raw = template_file.read()
template = pystache.parse(template_raw)
renderer = pystache.Renderer()
output = renderer.render(template, exportedData)
with open(output_file_name, "w") as text_file:
text_file.write(output)
开发者ID:iblancasa,项目名称:GitHubCity,代码行数:37,代码来源:ghcity.py
注:本文中的pystache.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论