diff babel/messages/frontend.py @ 57:a6183d300a6e

* The `extract_messages` distutils command now operators on configurable input directories again, instead of the complete current directory. The `input_dirs` default to the package directories. * Add a pseudo extractor called ?ignore? for #10.
author cmlenz
date Fri, 08 Jun 2007 11:28:15 +0000
parents 27fba894d3ca
children dcd8ceccf416
line wrap: on
line diff
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -77,6 +77,8 @@
         ('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'
@@ -90,6 +92,7 @@
         self.no_location = False
         self.omit_header = False
         self.output_file = None
+        self.input_dirs = None
         self.width = 76
         self.no_wrap = False
 
@@ -111,6 +114,11 @@
         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')
@@ -136,21 +144,25 @@
 
         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()
+            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))
 
-            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)])
+                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(),
Copyright (C) 2012-2017 Edgewall Software