opts, args = getopt.getopt(
'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', 'no-docstrings',
except getopt.error, msg:
# for holding option values
extractall = 0 # FIXME: currently this option has no effect at all.
locations = {'gnu' : options.GNU,
'solaris' : options.SOLARIS,
if opt in ('-h', '--help'):
elif opt in ('-a', '--extract-all'):
elif opt in ('-d', '--default-domain'):
options.outfile = arg + '.pot'
elif opt in ('-E', '--escape'):
elif opt in ('-D', '--docstrings'):
elif opt in ('-k', '--keyword'):
options.keywords.append(arg)
elif opt in ('-K', '--no-default-keywords'):
elif opt in ('-n', '--add-location'):
options.writelocations = 1
elif opt in ('--no-location',):
options.writelocations = 0
elif opt in ('-S', '--style'):
options.locationstyle = locations.get(arg.lower())
if options.locationstyle is None:
usage(1, _('Invalid value for --style: %s') % arg)
elif opt in ('-o', '--output'):
elif opt in ('-p', '--output-dir'):
elif opt in ('-v', '--verbose'):
elif opt in ('-V', '--version'):
print _('pygettext.py (xgettext for Python) %s') % __version__
elif opt in ('-w', '--width'):
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'):
options.nodocstrings[line[:-1]] = 1
make_escapes(not options.escape)
options.keywords.extend(default_keywords)
# initialize list of strings to exclude
if options.excludefilename:
fp = open(options.excludefilename)
options.toexclude = fp.readlines()
"Can't read --exclude-file: %s") % options.excludefilename
# resolve args to module lists
expanded.extend(getFilesForName(arg))
# slurp through all the files
eater = TokenEater(options)
print _('Reading standard input')
print _('Working on %s') % filename
eater.set_filename(filename)
tokenize.tokenize(fp.readline, eater)
except tokenize.TokenError, e:
print >> sys.stderr, '%s: %s, line %d, column %d' % (
e[0], filename, e[1][0], e[1][1])
if options.outfile == '-':
options.outfile = os.path.join(options.outpath, options.outfile)
fp = open(options.outfile, 'w')
if __name__ == '__main__':
# this one creates a warning
_('*** Seen unexpected token "%(token)s"') % {'token': 'test'}
_('more' 'than' 'one' 'string')