本文整理汇总了Python中sphinx.util.osutil.os_path函数的典型用法代码示例。如果您正苦于以下问题:Python os_path函数的具体用法?Python os_path怎么用?Python os_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了os_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_page
def handle_page(self, pagename, ctx, templatename='page.html',
outfilename=None, event_arg=None):
# type: (str, Dict, str, str, Any) -> None
ctx['current_page_name'] = pagename
self.add_sidebars(pagename, ctx)
if not outfilename:
outfilename = path.join(self.outdir,
os_path(pagename) + self.out_suffix)
# we're not taking the return value here, since no template is
# actually rendered
self.app.emit('html-page-context', pagename, templatename, ctx, event_arg)
# make context object serializable
for key in list(ctx):
if isinstance(ctx[key], types.FunctionType):
del ctx[key]
ensuredir(path.dirname(outfilename))
self.dump_context(ctx, outfilename)
# if there is a source file, copy the source file for the
# "show source" link
if ctx.get('sourcename'):
source_name = path.join(self.outdir, '_sources',
os_path(ctx['sourcename']))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例2: handle_page
def handle_page(self, pagename, ctx, templatename='page.html',
outfilename=None, event_arg=None):
ctx['current_page_name'] = pagename
self.add_sidebars(pagename, ctx)
if not outfilename:
outfilename = path.join(self.outdir,
os_path(pagename) + self.out_suffix)
self.app.emit('html-page-context', pagename, templatename,
ctx, event_arg)
ensuredir(path.dirname(outfilename))
f = open(outfilename, 'wb')
try:
self.implementation.dump(ctx, f, 2)
finally:
f.close()
# if there is a source file, copy the source file for the
# "show source" link
if ctx.get('sourcename'):
source_name = path.join(self.outdir, '_sources',
os_path(ctx['sourcename']))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例3: get_outfilename
def get_outfilename(self, pagename):
if pagename == "index" or pagename.endswith(SEP + "index"):
outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix)
else:
outfilename = path.join(self.outdir, os_path(pagename), "index" + self.out_suffix)
return outfilename
示例4: get_outfilename
def get_outfilename(self, pagename):
if pagename == 'index' or pagename.endswith(SEP + 'index'):
outfilename = path.join(self.outdir, os_path(pagename) +
self.out_suffix)
else:
outfilename = path.join(self.outdir, os_path(pagename),
'index' + self.out_suffix)
return outfilename
示例5: handle_page
def handle_page(self, pagename, addctx, templatename="page.html", outfilename=None, event_arg=None):
ctx, doc_ctx = self._render_page(pagename, addctx, templatename, event_arg)
if not outfilename:
outfilename = path.join(self.outdir, "pickles", os_path(pagename) + self.out_suffix)
ensuredir(path.dirname(outfilename))
self.dump_context(doc_ctx, outfilename)
# if there is a source file, copy the source file for the
# "show source" link
if ctx.get("sourcename"):
source_name = path.join(self.staticdir, "_sources", os_path(ctx["sourcename"]))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例6: write_doc
def write_doc(self, docname, doctree):
# work around multiple string % tuple issues in docutils;
# replace tuples in attribute values with lists
doctree = doctree.deepcopy()
for node in doctree.traverse(nodes.Element):
for att, value in list(node.attributes.items()):
if isinstance(value, tuple):
node.attributes[att] = list(value)
value = node.attributes[att]
if isinstance(value, list):
for i, val in enumerate(value):
if isinstance(val, tuple):
value[i] = list(val)
destination = StringOutput(encoding='utf-8')
self.writer.write(doctree, destination)
outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
ensuredir(path.dirname(outfilename))
try:
f = codecs.open(outfilename, 'w', 'utf-8')
try:
f.write(self.writer.output)
finally:
f.close()
except (IOError, OSError) as err:
self.warn("error writing file %s: %s" % (outfilename, err))
示例7: run
def run(self):
env = self.state.document.settings.env
baseurl = env.config.rss_baseurl
assert baseurl, "rss_baseurl must be defined in your config.py"
source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)
rss_doc = utils.new_document(b("<rss>"), self.state.document.settings)
Parser().parse("\n".join(self.content), rss_doc)
rst_suffix = env.config.source_suffix
path = os.path.relpath(source, env.srcdir).replace(rst_suffix, ".html")
builder = env.app.builder
docwriter = HTMLWriter(self)
docsettings = OptionParser(defaults=env.settings, components=(docwriter,)).get_default_values()
docsettings.compact_lists = bool(env.config.html_compact_lists)
dest = os.path.join(env.app.outdir, os_path(env.docname) + ".rss")
pageurl = "%s/%s" % (baseurl, path)
with open(dest, "w") as rss:
title = self.options.get("title", "")
description = self.options.get("description", None)
rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
rss.write('<rss version="2.0">\n')
rss.write("<channel>\n")
rss.write("<title>%s</title>\n" % cgi.escape(title))
rss.write("<link>%s</link>\n" % pageurl)
if description:
rss.write("<description>%s</description>\n" % cgi.escape(description))
for child in rss_doc.children:
if not isinstance(child, nodes.section):
continue
title_index = child.first_child_matching_class(nodes.title)
if title_index is None:
continue
node = nodes.paragraph()
node.extend(child.children[title_index + 1 :])
sec_doc = utils.new_document(b("<rss-section>"), docsettings)
sec_doc.append(node)
visitor = RssTranslator(builder, sec_doc)
sec_doc.walkabout(visitor)
title = child.children[title_index].astext()
sectionurl = "%s#%s" % (pageurl, child.get("ids")[0])
description = "".join(visitor.body)
rss.write("<item>\n")
rss.write("<title>%s</title>\n" % cgi.escape(title))
rss.write("<link>%s</link>\n" % sectionurl)
rss.write("<description><![CDATA[%s]]></description>\n" % description)
rss.write("</item>\n")
rss.write("</channel>\n")
rss.write("</rss>\n")
return []
示例8: write_doc
def write_doc(self, docname, doctree):
self.current_docname = docname
destination = StringOutput(encoding='utf-8')
self.writer.write(doctree, destination)
outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
ensuredir(path.dirname(outfilename))
try:
f = codecs.open(outfilename, 'w', 'utf-8')
try:
f.write("#rst2hooktail_source" + (linesep*2))
for link in self.writer.links:
f.write(".. _%s: %s%s" % (link.children[0].astext(), link['refuri'], linesep))
f.write(linesep)
f.write(self.writer.output)
f.write("@@author:%[email protected]@%s" % (self.config.copyright[6:], linesep))
f.write("@@accept:%[email protected]@%s" % (ustrftime("%Y-%m-%d"), linesep))
relations = self.env.collect_relations().get(docname)
if relations and relations[0] and relations[0] != "index":
f.write("@@category:%[email protected]@%s" % (self.categories[relations[0]], linesep))
f.write("@@id:%[email protected]@%s" % (docname.split('/')[-1], linesep))
finally:
f.close()
except (IOError, OSError) as err:
self.warn("error writing file %s: %s" % (outfilename, err))
示例9: handle_page
def handle_page(self, pagename, addctx, templatename='page.html',
outfilename=None, event_arg=None):
ctx = self.globalcontext.copy()
# current_page_name is backwards compatibility
ctx['pagename'] = ctx['current_page_name'] = pagename
default_baseuri = self.get_target_uri(pagename)
# in the singlehtml builder, default_baseuri still contains an #anchor
# part, which relative_uri doesn't really like...
default_baseuri = default_baseuri.rsplit('#', 1)[0]
def pathto(otheruri, resource=False, baseuri=default_baseuri):
if resource and '://' in otheruri:
# allow non-local resources given by scheme
return otheruri
elif not resource:
otheruri = self.get_target_uri(otheruri)
uri = relative_uri(baseuri, otheruri) or '#'
return uri
ctx['pathto'] = pathto
ctx['hasdoc'] = lambda name: name in self.env.all_docs
if self.name != 'htmlhelp':
ctx['encoding'] = encoding = self.config.html_output_encoding
else:
ctx['encoding'] = encoding = self.encoding
ctx['toctree'] = lambda **kw: self._get_local_toctree(pagename, **kw)
self.add_sidebars(pagename, ctx)
ctx.update(addctx)
newtmpl = self.app.emit_firstresult('html-page-context', pagename,
templatename, ctx, event_arg)
if newtmpl:
templatename = newtmpl
try:
output = self.templates.render(templatename, ctx)
except UnicodeError:
self.warn("a Unicode error occurred when rendering the page %s. "
"Please make sure all config values that contain "
"non-ASCII content are Unicode strings." % pagename)
return
if not outfilename:
outfilename = self.get_outfilename(pagename)
# outfilename's path is in general different from self.outdir
ensuredir(path.dirname(outfilename))
try:
f = codecs.open(outfilename, 'w', encoding, 'xmlcharrefreplace')
try:
f.write(output)
finally:
f.close()
except (IOError, OSError) as err:
self.warn("error writing file %s: %s" % (outfilename, err))
if self.copysource and ctx.get('sourcename'):
# copy the source file for the "show source" link
source_name = path.join(self.outdir, '_sources',
os_path(ctx['sourcename']))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例10: handle_page
def handle_page(self, pagename, ctx, templatename="page.html", outfilename=None, event_arg=None):
ctx["current_page_name"] = pagename
self.add_sidebars(pagename, ctx)
if not outfilename:
outfilename = path.join(self.outdir, os_path(pagename) + self.out_suffix)
self.app.emit("html-page-context", pagename, templatename, ctx, event_arg)
ensuredir(path.dirname(outfilename))
self.dump_context(ctx, outfilename)
# if there is a source file, copy the source file for the
# "show source" link
if ctx.get("sourcename"):
source_name = path.join(self.outdir, "_sources", os_path(ctx["sourcename"]))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例11: write_doc
def write_doc(self, docname, doctree):
destination = StringOutput(encoding='utf-8')
self.writer.write(doctree, destination)
outfilename = path.join(
self.outdir, os_path(docname) + self.out_suffix)
ensuredir(path.dirname(outfilename))
try:
self.writer.save(outfilename)
except (IOError, OSError), err:
self.warn("error writing file %s: %s" % (outfilename, err))
示例12: handle_page
def handle_page(self, pagename, addctx, templatename='page.html',
outfilename=None, event_arg=None):
# type: (unicode, Dict, unicode, unicode, unicode) -> None
ctx, doc_ctx = self._render_page(pagename, addctx,
templatename, event_arg)
if not outfilename:
outfilename = path.join(self.outdir, 'pickles',
os_path(pagename) + self.out_suffix)
ensuredir(path.dirname(outfilename))
self.dump_context(doc_ctx, outfilename)
# if there is a source file, copy the source file for the
# "show source" link
if ctx.get('sourcename'):
source_name = path.join(self.staticdir,
'_sources', os_path(ctx['sourcename']))
ensuredir(path.dirname(source_name))
copyfile(self.env.doc2path(pagename), source_name)
示例13: write_doc
def write_doc(self, docname, doctree, targetname):
os.chdir(self.srcdir)
parser = ReStructuredTextParser()
rinoh_tree = parser.from_doctree(doctree)
rinoh_document = Book(rinoh_tree, backend=pdf,
options=BookOptions(**self.config.rinoh_options))
rinoh_document.metadata['title'] = doctree.settings.title
rinoh_document.metadata['author'] = doctree.settings.author
outfilename = path.join(self.outdir, os_path(targetname))
ensuredir(path.dirname(outfilename))
rinoh_document.render(outfilename)
示例14: write_doc
def write_doc(self, docname, doctree):
self.current_docname = docname
destination = StringOutput(encoding='utf-8')
self.writer.write(doctree, destination)
outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
ensuredir(path.dirname(outfilename))
try:
with codecs.open(outfilename, 'w', 'utf-8') as f:
f.write(self.writer.output)
except (IOError, OSError) as err:
self.warn("error writing file %s: %s" % (outfilename, err))
示例15: write_doc
def write_doc(self, docname, doctree):
# type: (unicode, nodes.Node) -> None
self.current_docname = docname
destination = StringOutput(encoding='utf-8')
self.writer.write(doctree, destination)
outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
ensuredir(path.dirname(outfilename))
try:
with codecs.open(outfilename, 'w', 'utf-8') as f: # type: ignore
f.write(self.writer.output)
except (IOError, OSError) as err:
logger.warning("error writing file %s: %s", outfilename, err)