Index: pygettext.py =================================================================== RCS file: /home/cvs/development/software/application/Aspen/pygettext/pygettext.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -4 -r1.4 -r1.5 --- pygettext.py 9 Sep 2005 16:18:46 -0000 1.4 +++ pygettext.py 9 Sep 2005 16:19:40 -0000 1.5 @@ -82,8 +82,14 @@ Extract module, class, method, and function docstrings. These do not need to be wrapped in _() markers, and in fact cannot be for Python to consider them docstrings. (See also the -X option). + -C + --comments + Copy python source code comments into the output file if they occur on the + same source code line as an extracted string, and the first character of the + comment (immediately after the #) is a period (.) + -h --help Print this help message and exit. @@ -358,8 +364,9 @@ self.__data = [] self.__lineno = -1 self.__freshmodule = 1 self.__curfile = None + self.__comments = {} def __call__(self, ttype, tstring, stup, etup, line): # dispatch ## import token @@ -368,8 +375,12 @@ self.__state(ttype, tstring, stup[0]) def __waiting(self, ttype, tstring, lineno): opts = self.__options + # Do comment extractions, if enabled + if opts.writecomments: + if ttype == tokenize.COMMENT and tstring.startswith('#.'): + self.__comments[(self.__curfile,self.__lineno)] = tstring[2:].strip() # Do docstring extractions, if enabled if opts.docstrings and not opts.nodocstrings.get(self.__curfile): # module docstring? if self.__freshmodule: @@ -496,8 +507,13 @@ if len(locline) > 2: print >> fp, locline if isdocstring: print >> fp, '#, docstring' + if options.writecomments: + for filename, lineno in v: + comment = self.__comments.get((filename,lineno)) + if comment: + print >> fp, '#.', comment print >> fp, 'msgid', normalize(k) print >> fp, 'msgstr ""\n' @@ -506,14 +522,15 @@ global default_keywords try: opts, args = getopt.getopt( sys.argv[1:], - 'ad:DEhk:Kno:p:S:Vvw:x:X:', + 'aCd:DEhk:Kno:p:S:Vvw:x:X:', ['extract-all', 'default-domain=', 'escape', 'help', 'keyword=', 'no-default-keywords', 'add-location', 'no-location', 'output=', 'output-dir=', 'style=', 'verbose', 'version', 'width=', 'exclude-file=', 'docstrings', 'no-docstrings', + 'comments', ]) except getopt.error, msg: usage(1, msg) @@ -534,8 +551,9 @@ width = 78 excludefilename = '' docstrings = 0 nodocstrings = {} + writecomments = 0 options = Options() locations = {'gnu' : options.GNU, 'solaris' : options.SOLARIS, @@ -550,8 +568,10 @@ elif opt in ('-d', '--default-domain'): options.outfile = arg + '.pot' elif opt in ('-E', '--escape'): options.escape = 1 + elif opt in ('-C', '--comments'): + options.writecomments = 1 elif opt in ('-D', '--docstrings'): options.docstrings = 1 elif opt in ('-k', '--keyword'): options.keywords.append(arg)