#! /usr/bin/env python
-# Originally written by Barry Warsaw <barry@digicool.com>
+# Originally written by Barry Warsaw <barry@zope.com>
#
# Minimally patched to make it even more xgettext compatible
# by Peter Funk <pf@artcom-gmbh.de>
-a
--extract-all
- Extract all strings
+ Extract all strings.
-d name
--default-domain=name
- Rename the default output file from messages.pot to name.pot
+ Rename the default output file from messages.pot to name.pot.
-E
--escape
--docstrings
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.
+ consider them docstrings. (See also the -X option).
-h
--help
- print this help message and exit
+ Print this help message and exit.
-k word
--keyword=word
extracted from the input files. Each string to be excluded must
appear on a line by itself in the file.
-If `inputfile' is -, standard input is read.
+ -X filename
+ --no-docstrings=filename
+ Specify a file that contains a list of files (one per line) that
+ should not have their docstrings extracted. This is only useful in
+ conjunction with the -D option above.
+If `inputfile' is -, standard input is read.
"""
import os
except ImportError:
def _(s): return s
-__version__ = '1.3'
+__version__ = '1.4'
default_keywords = ['_']
DEFAULTKEYWORDS = ', '.join(default_keywords)
\f
-# The normal pot-file header. msgmerge and EMACS' po-mode work better if
-# it's there.
+# The normal pot-file header. msgmerge and Emacs's po-mode work better if it's
+# there.
pot_header = _('''\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
self.__data = []
self.__lineno = -1
self.__freshmodule = 1
+ self.__curfile = None
def __call__(self, ttype, tstring, stup, etup, line):
# dispatch
self.__state(ttype, tstring, stup[0])
def __waiting(self, ttype, tstring, lineno):
+ opts = self.__options
# Do docstring extractions, if enabled
- if self.__options.docstrings:
+ if opts.docstrings and not opts.nodocstrings.get(self.__curfile):
# module docstring?
if self.__freshmodule:
if ttype == tokenize.STRING:
if ttype == tokenize.NAME and tstring in ('class', 'def'):
self.__state = self.__suiteseen
return
- if ttype == tokenize.NAME and tstring in self.__options.keywords:
+ if ttype == tokenize.NAME and tstring in opts.keywords:
self.__state = self.__keywordseen
def __suiteseen(self, ttype, tstring, lineno):
def set_filename(self, filename):
self.__curfile = filename
+ self.__freshmodule = 1
def write(self, fp):
options = self.__options
try:
opts, args = getopt.getopt(
sys.argv[1:],
- 'ad:DEhk:Kno:p:S:Vvw:x:',
+ 'ad: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',
+ 'docstrings', 'no-docstrings',
])
except getopt.error, msg:
usage(1, msg)
width = 78
excludefilename = ''
docstrings = 0
+ nodocstrings = {}
options = Options()
locations = {'gnu' : options.GNU,
usage(1, _('--width argument must be an integer: %s') % arg)
elif opt in ('-x', '--exclude-file'):
options.excludefilename = arg
+ elif opt in ('-X', '--no-docstrings'):
+ fp = open(arg)
+ try:
+ while 1:
+ line = fp.readline()
+ if not line:
+ break
+ options.nodocstrings[line[:-1]] = 1
+ finally:
+ fp.close()
# calculate escapes
make_escapes(options.escape)