if options_map is None:
options_map = {}
+ # Sort methods by pattern length
+ # FIXME: we'll probably need to preserve the user-supplied order in the
+ # frontends
+ methods = method_map.items()
+ methods.sort(lambda a,b: -cmp(len(a[0]), len(b[0])))
+
absname = os.path.abspath(dirname)
for root, dirnames, filenames in os.walk(absname):
for subdir in dirnames:
os.path.join(root, filename).replace(os.sep, '/'),
dirname
)
- for pattern, method in method_map.items():
+ for pattern, method in methods:
if pathmatch(pattern, filename):
filepath = os.path.join(absname, filename)
options = {}
if pathmatch(opattern, filename):
options = odict
if callback:
- callback(filename, options)
+ callback(filename, method, options)
for lineno, message in extract_from_file(method, filepath,
keywords=keywords,
options=options):
yield filename, lineno, message
+ break
def extract_from_file(method, filename, keywords=DEFAULT_KEYWORDS,
options=None):
raise ValueError('Unknown extraction method %r' % method)
+def extract_nothing(fileobj, keywords, options):
+ """Pseudo extractor that does not actually extract anything, but simply
+ returns an empty list.
+ """
+ return []
+
def extract_genshi(fileobj, keywords, options):
"""Extract messages from Genshi templates.
('no-wrap', None,
'do not break long message lines, longer than the output line width, '
'into several lines')
+ ('input-dirs=',
+ 'directories that should be scanned for messages'),
]
boolean_options = [
'no-default-keywords', 'no-location', 'omit-header', 'no-wrap'
self.no_location = False
self.omit_header = False
self.output_file = None
+ self.input_dirs = None
self.width = 76
self.no_wrap = False
else:
self.width = int(self.width)
+ if not self.input_dirs:
+ self.input_dirs = dict.fromkeys([k.split('.',1)[0]
+ for k in self.distribution.packages
+ ]).keys()
+
def run(self):
if self.mapping_file:
fileobj = open(self.mapping_file, 'U')
outfile = open(self.output_file, 'w')
try:
- def callback(filename, options):
- optstr = ''
- if options:
- optstr = ' (%s)' % ', '.join(['%s="%s"' % (k, v) for k, v
- in options.items()])
- log.info('extracting messages from %s%s' % (filename, optstr))
-
catalog = Catalog()
- extracted = extract_from_dir(method_map=method_map,
- options_map=options_map,
- keywords=self.keywords,
- callback=callback)
- for filename, lineno, message in extracted:
- filepath = os.path.normpath(filename)
- catalog.add(message, None, [(filepath, lineno)])
+ for dirname in self.input_dirs:
+ def callback(filename, method, options):
+ if method == 'ignore':
+ return
+ filepath = os.path.normpath(os.path.join(dirname, filename))
+ optstr = ''
+ if options:
+ optstr = ' (%s)' % ', '.join(['%s="%s"' % (k, v) for
+ k, v in options.items()])
+ log.info('extracting messages from %s%s'
+ % (filepath, optstr))
+
+ extracted = extract_from_dir(dirname, method_map, options_map,
+ keywords=self.keywords,
+ callback=callback)
+ for filename, lineno, message in extracted:
+ filepath = os.path.normpath(os.path.join(dirname, filename))
+ catalog.add(message, None, [(filepath, lineno)])
log.info('writing PO template file to %s' % self.output_file)
write_pot(outfile, catalog, project=self.distribution.get_name(),