Modernize newly written code as well

This commit is contained in:
Dmitry Shachnev 2014-01-20 18:59:15 +04:00
parent c2eaf2af81
commit 5f13479408
2 changed files with 62 additions and 61 deletions

View File

@ -14,6 +14,7 @@
:copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
import os
import sys
@ -68,90 +69,90 @@ class Make(object):
if not path.exists(self.builddir):
return
elif not path.isdir(self.builddir):
print "Error: %r is not a directory!" % self.builddir
print("Error: %r is not a directory!" % self.builddir)
return 1
print "Removing everything under %r..." % self.builddir
print("Removing everything under %r..." % self.builddir)
for item in os.listdir(self.builddir):
shutil.rmtree(self.builddir_join(item))
def build_help(self):
print bold("Sphinx v%s" % sphinx.__version__)
print "Please use `make %s' where %s is one of" % ((blue('target'),)*2)
print(bold("Sphinx v%s" % sphinx.__version__))
print("Please use `make %s' where %s is one of" % ((blue('target'),)*2))
for osname, bname, description in BUILDERS:
if not osname or os.name == osname:
print ' %s %s' % (blue(bname.ljust(10)), description)
print(' %s %s' % (blue(bname.ljust(10)), description))
def build_html(self):
if self.run_generic_build('html') > 0:
return 1
print
print 'Build finished. The HTML pages are in %s.' % self.builddir_join('html')
print()
print('Build finished. The HTML pages are in %s.' % self.builddir_join('html'))
def build_dirhtml(self):
if self.run_generic_build('dirhtml') > 0:
return 1
print
print 'Build finished. The HTML pages are in %s.' % self.builddir_join('dirhtml')
print()
print('Build finished. The HTML pages are in %s.' % self.builddir_join('dirhtml'))
def build_singlehtml(self):
if self.run_generic_build('singlehtml') > 0:
return 1
print
print 'Build finished. The HTML page is in %s.' % self.builddir_join('singlehtml')
print()
print('Build finished. The HTML page is in %s.' % self.builddir_join('singlehtml'))
def build_pickle(self):
if self.run_generic_build('pickle') > 0:
return 1
print
print 'Build finished; now you can process the pickle files.'
print()
print('Build finished; now you can process the pickle files.')
def build_json(self):
if self.run_generic_build('json') > 0:
return 1
print
print 'Build finished; now you can process the JSON files.'
print()
print('Build finished; now you can process the JSON files.')
def build_htmlhelp(self):
if self.run_generic_build('htmlhelp') > 0:
return 1
print
print ('Build finished; now you can run HTML Help Workshop with the '
'.hhp project file in %s.') % self.builddir_join('htmlhelp')
print()
print('Build finished; now you can run HTML Help Workshop with the '
'.hhp project file in %s.' % self.builddir_join('htmlhelp'))
def build_qthelp(self):
if self.run_generic_build('qthelp') > 0:
return 1
print
print ('Build finished; now you can run "qcollectiongenerator" with the '
'.qhcp project file in %s, like this:') % self.builddir_join('qthelp')
print '$ qcollectiongenerator %s.qhcp' % self.builddir_join('qthelp', proj_name)
print 'To view the help file:'
print '$ assistant -collectionFile %s.qhc' % self.builddir_join('qthelp', proj_name)
print()
print('Build finished; now you can run "qcollectiongenerator" with the '
'.qhcp project file in %s, like this:' % self.builddir_join('qthelp'))
print('$ qcollectiongenerator %s.qhcp' % self.builddir_join('qthelp', proj_name))
print('To view the help file:')
print('$ assistant -collectionFile %s.qhc' % self.builddir_join('qthelp', proj_name))
def build_devhelp(self):
if self.run_generic_build('devhelp') > 0:
return 1
print
print "Build finished."
print "To view the help file:"
print "$ mkdir -p $HOME/.local/share/devhelp/" + proj_name
print "$ ln -s %s $HOME/.local/share/devhelp/%s" % \
(self.builddir_join('devhelp'), proj_name)
print "$ devhelp"
print()
print("Build finished.")
print("To view the help file:")
print("$ mkdir -p $HOME/.local/share/devhelp/" + proj_name)
print("$ ln -s %s $HOME/.local/share/devhelp/%s" %
(self.builddir_join('devhelp'), proj_name))
print("$ devhelp")
def build_epub(self):
if self.run_generic_build('epub') > 0:
return 1
print
print 'Build finished. The ePub file is in %s.' % self.builddir_join('epub')
print()
print('Build finished. The ePub file is in %s.' % self.builddir_join('epub'))
def build_latex(self):
if self.run_generic_build('latex') > 0:
return 1
print "Build finished; the LaTeX files are in %s." % self.builddir_join('latex')
print("Build finished; the LaTeX files are in %s." % self.builddir_join('latex'))
if os.name == 'posix':
print "Run `make' in that directory to run these through (pdf)latex"
print "(use `make latexpdf' here to do that automatically)."
print("Run `make' in that directory to run these through (pdf)latex")
print("(use `make latexpdf' here to do that automatically).")
def build_latexpdf(self):
if self.run_generic_build('latex') > 0:
@ -166,16 +167,16 @@ class Make(object):
def build_text(self):
if self.run_generic_build('text') > 0:
return 1
print
print 'Build finished. The text files are in %s.' % self.builddir_join('text')
print()
print('Build finished. The text files are in %s.' % self.builddir_join('text'))
def build_texinfo(self):
if self.run_generic_build('texinfo') > 0:
return 1
print "Build finished; the Texinfo files are in %s." % self.builddir_join('texinfo')
print("Build finished; the Texinfo files are in %s." % self.builddir_join('texinfo'))
if os.name == 'posix':
print "Run `make' in that directory to run these through makeinfo"
print "(use `make info' here to do that automatically)."
print("Run `make' in that directory to run these through makeinfo")
print("(use `make info' here to do that automatically).")
def build_info(self):
if self.run_generic_build('texinfo') > 0:
@ -186,47 +187,47 @@ class Make(object):
dtdir = self.builddir_join('gettext', '.doctrees')
if self.run_generic_build('gettext', doctreedir=dtdir) > 0:
return 1
print
print 'Build finished. The message catalogs are in %s.' % self.builddir_join('gettext')
print()
print('Build finished. The message catalogs are in %s.' % self.builddir_join('gettext'))
def build_changes(self):
if self.run_generic_build('changes') > 0:
return 1
print
print 'Build finished. The overview file is in %s.' % self.builddir_join('changes')
print()
print('Build finished. The overview file is in %s.' % self.builddir_join('changes'))
def build_linkcheck(self):
res = self.run_generic_build('linkcheck')
print
print ('Link check complete; look for any errors in the above output '
'or in %s.') % self.builddir_join('linkcheck', 'output.txt')
print()
print('Link check complete; look for any errors in the above output '
'or in %s.' % self.builddir_join('linkcheck', 'output.txt'))
return res
def build_doctest(self):
res = self.run_generic_build('doctest')
print ("Testing of doctests in the sources finished, look at the "
"results in %s." % self.builddir_join('doctest', 'output.txt'))
print("Testing of doctests in the sources finished, look at the "
"results in %s." % self.builddir_join('doctest', 'output.txt'))
return res
def build_coverage(self):
if self.run_generic_build('coverage') > 0:
print "Has the coverage extension been enabled?"
print("Has the coverage extension been enabled?")
return 1
print
print ("Testing of coverage in the sources finished, look at the "
"results in %s." % self.builddir_join('coverage'))
print()
print("Testing of coverage in the sources finished, look at the "
"results in %s." % self.builddir_join('coverage'))
def build_xml(self):
if self.run_generic_build('xml') > 0:
return 1
print
print 'Build finished. The XML files are in %s.' % self.builddir_join('xml')
print()
print('Build finished. The XML files are in %s.' % self.builddir_join('xml'))
def build_pseudoxml(self):
if self.run_generic_build('pseudoxml') > 0:
return 1
print
print 'Build finished. The pseudo-XML files are in %s.' % self.builddir_join('pseudoxml')
print()
print('Build finished. The pseudo-XML files are in %s.' % self.builddir_join('pseudoxml'))
def run_generic_build(self, builder, doctreedir=None):
# compatibility with old Makefile
@ -242,8 +243,8 @@ class Make(object):
def run_make_mode(args):
if len(args) < 3:
print >>sys.stderr, ('Error: at least 3 arguments (builder, source '
'dir, build dir) are required.')
print('Error: at least 3 arguments (builder, source '
'dir, build dir) are required.', file=sys.stderr)
return 1
make = Make(args[1], args[2], args[3:])
run_method = 'build_' + args[0]

View File

@ -273,7 +273,7 @@ class HTMLTranslator(BaseTranslator):
**highlight_args)
starttag = self.starttag(node, 'div', suffix='',
CLASS='highlight-%s' % lang)
if node.has_key('filename'):
if 'filename' in node:
starttag += '<div class="code-block-filename"><tt>%s</tt></div>' % (
node['filename'],)
self.body.append(starttag + highlighted + '</div>\n')