[Zope-Checkins] CVS: Zope3/lib/python/Zope/TAL - talgettext.py:1.2

Barry Warsaw barry@wooz.org
Mon, 17 Jun 2002 20:18:21 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv24366/lib/python/Zope/TAL

Modified Files:
	talgettext.py 
Log Message:
Get rid of the -o/--output switch (just use shell i/o redirection for
now).

Handle multiple files specified on the command line so that we can
combine all msgid's in a single .po file.  Add a POEngine which
contains a `catalog' of all the msgids seen.


=== Zope3/lib/python/Zope/TAL/talgettext.py 1.1 => 1.2 ===
 this program to extract GNU gettext .po file entries.
 
-Usage: talgettext.py [options] file
+Usage: talgettext.py [options] files
 Options:
-    -o file
-    --output=file
-        Send output to the named file, otherwise standard out is used.
-
     -h / --help
         Print this message and exit.
 """
@@ -46,6 +42,18 @@
     sys.exit(code)
 
 
+class POEngine(DummyEngine):
+    __implements__ = ITALESEngine
+
+    catalog = {}
+
+    def evaluatePathOrVar(self, expr):
+        return 'who cares'
+
+    def translate(self, domain, msgid, mapping):
+        self.catalog[msgid] = ''
+        
+
 def main():
     try:
         opts, args = getopt.getopt(
@@ -62,40 +70,31 @@
         elif opt in ('-o', '--output'):
             outfile = arg
 
-    if len(args) <> 1:
-        usage(1)
-
-    # Output goes here
-    if outfile:
-        outfp = open(outfile, 'w')
-    else:
-        outfp = sys.stdout
+    if not args:
+        print 'nothing to do'
+        return
 
     # We don't care about the rendered output of the .pt file
     class Devnull:
         def write(self, s):
             pass
 
-    file = args[0]
-    p = HTMLTALParser()
-    p.parseFile(file)
-    program, macros = p.getCode()
     engine = POEngine()
-    engine.outfp = outfp
-    TALInterpreter(program, macros, engine, stream=Devnull())()
-
-
-class POEngine(DummyEngine):
-    __implements__ = ITALESEngine
+    for file in args:
+        p = HTMLTALParser()
+        p.parseFile(file)
+        program, macros = p.getCode()
+        TALInterpreter(program, macros, engine, stream=Devnull())()
+
+    # Now print all the entries in the engine
+    msgids = engine.catalog.keys()
+    msgids.sort()
+    for msgid in msgids:
+        msgstr = engine.catalog[msgid]
+        print 'msgid "%s"' % msgid
+        print 'msgstr "%s"' % msgstr
+        print
 
-    def evaluatePathOrVar(self, expr):
-        return 'who cares'
-
-    def translate(self, domain, msgid, mapping):
-        print >> self.outfp, 'msgid "%s"' % msgid
-        print >> self.outfp, 'msgstr ""'
-        print >> self.outfp
-        
 
 if __name__ == '__main__':
     main()