##// END OF EJS Templates
doc: don't use mutable default arguments...
Gregory Szorc -
r44088:15cccbac default
parent child Browse files
Show More
@@ -1,64 +1,63 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # runrst - register custom roles and run correct writer
3 # runrst - register custom roles and run correct writer
4 #
4 #
5 # Copyright 2010 Matt Mackall <mpm@selenic.com> and others
5 # Copyright 2010 Matt Mackall <mpm@selenic.com> and others
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version.
8 # GNU General Public License version 2 or any later version.
9
9
10 """usage: %s WRITER args...
10 """usage: %s WRITER args...
11
11
12 where WRITER is the name of a Docutils writer such as 'html' or 'manpage'
12 where WRITER is the name of a Docutils writer such as 'html' or 'manpage'
13 """
13 """
14
14
15 from __future__ import absolute_import
15 from __future__ import absolute_import
16
16
17 import sys
17 import sys
18 try:
18 try:
19 import docutils.core as core
19 import docutils.core as core
20 import docutils.nodes as nodes
20 import docutils.nodes as nodes
21 import docutils.utils as utils
21 import docutils.utils as utils
22 import docutils.parsers.rst.roles as roles
22 import docutils.parsers.rst.roles as roles
23 except ImportError:
23 except ImportError:
24 sys.stderr.write("abort: couldn't generate documentation: docutils "
24 sys.stderr.write("abort: couldn't generate documentation: docutils "
25 "module is missing\n")
25 "module is missing\n")
26 sys.stderr.write("please install python-docutils or see "
26 sys.stderr.write("please install python-docutils or see "
27 "http://docutils.sourceforge.net/\n")
27 "http://docutils.sourceforge.net/\n")
28 sys.exit(-1)
28 sys.exit(-1)
29
29
30 def role_hg(name, rawtext, text, lineno, inliner,
30 def role_hg(name, rawtext, text, lineno, inliner, options=None, content=None):
31 options={}, content=[]):
32 text = "hg " + utils.unescape(text)
31 text = "hg " + utils.unescape(text)
33 linktext = nodes.literal(rawtext, text)
32 linktext = nodes.literal(rawtext, text)
34 parts = text.split()
33 parts = text.split()
35 cmd, args = parts[1], parts[2:]
34 cmd, args = parts[1], parts[2:]
36 refuri = "hg.1.html#%s" % cmd
35 refuri = "hg.1.html#%s" % cmd
37 if cmd == 'help' and args:
36 if cmd == 'help' and args:
38 if args[0] == 'config':
37 if args[0] == 'config':
39 # :hg:`help config`
38 # :hg:`help config`
40 refuri = "hgrc.5.html"
39 refuri = "hgrc.5.html"
41 elif args[0].startswith('config.'):
40 elif args[0].startswith('config.'):
42 # :hg:`help config.SECTION...`
41 # :hg:`help config.SECTION...`
43 refuri = "hgrc.5.html#%s" % args[0].split('.', 2)[1]
42 refuri = "hgrc.5.html#%s" % args[0].split('.', 2)[1]
44 elif len(args) >= 2 and args[0] == '-c':
43 elif len(args) >= 2 and args[0] == '-c':
45 # :hg:`help -c COMMAND ...` is equivalent to :hg:`COMMAND`
44 # :hg:`help -c COMMAND ...` is equivalent to :hg:`COMMAND`
46 # (mainly for :hg:`help -c config`)
45 # (mainly for :hg:`help -c config`)
47 refuri = "hg.1.html#%s" % args[1]
46 refuri = "hg.1.html#%s" % args[1]
48 else:
47 else:
49 refuri = "hg.1.html#%s" % args[0]
48 refuri = "hg.1.html#%s" % args[0]
50 node = nodes.reference(rawtext, '', linktext,
49 node = nodes.reference(rawtext, '', linktext,
51 refuri=refuri)
50 refuri=refuri)
52 return [node], []
51 return [node], []
53
52
54 roles.register_local_role("hg", role_hg)
53 roles.register_local_role("hg", role_hg)
55
54
56 if __name__ == "__main__":
55 if __name__ == "__main__":
57 if len(sys.argv) < 2:
56 if len(sys.argv) < 2:
58 sys.stderr.write(__doc__ % sys.argv[0])
57 sys.stderr.write(__doc__ % sys.argv[0])
59 sys.exit(1)
58 sys.exit(1)
60
59
61 writer = sys.argv[1]
60 writer = sys.argv[1]
62 del sys.argv[1]
61 del sys.argv[1]
63
62
64 core.publish_cmdline(writer_name=writer)
63 core.publish_cmdline(writer_name=writer)
General Comments 0
You need to be logged in to leave comments. Login now