[Zope3-checkins] CVS: Zope3/src/zope/fssync - command.py:1.5 main.py:1.33

Fred L. Drake, Jr. fred at zope.com
Tue Aug 12 15:06:27 EDT 2003


Update of /cvs-repository/Zope3/src/zope/fssync
In directory cvs.zope.org:/tmp/cvs-serv4427

Modified Files:
	command.py main.py 
Log Message:
refactor: most of main() is sharable; only the command setup is local to the main
script, so move it to the command-line handler


=== Zope3/src/zope/fssync/command.py 1.4 => 1.5 ===
--- Zope3/src/zope/fssync/command.py:1.4	Tue Aug 12 13:12:50 2003
+++ Zope3/src/zope/fssync/command.py	Tue Aug 12 14:06:20 2003
@@ -56,6 +56,26 @@
             assert n not in self.command_table
             self.command_table[n] = cmdinfo
 
+    def main(self, args=None):
+        try:
+            self.realize()
+            self.run()
+
+        except Usage, msg:
+            self.usage(sys.stderr, msg)
+            self.usage(sys.stderr, 'for help use "%(program)s help"')
+            return 2
+
+        except Error, msg:
+            self.usage(sys.stderr, msg)
+            return 1
+
+        except SystemExit:
+            raise
+
+        else:
+            return None
+
     def realize(self, args=None):
         if "help" not in self.command_table:
             self.addCommand("help", self.help)
@@ -97,6 +117,7 @@
         func(self.local_options, self.args)
 
     def usage(self, file, text):
+        text = str(text)
         print >>file, text % {"program": self.program}
 
     def help(self, opts, args):


=== Zope3/src/zope/fssync/main.py 1.32 => 1.33 ===
--- Zope3/src/zope/fssync/main.py:1.32	Tue Aug 12 13:51:09 2003
+++ Zope3/src/zope/fssync/main.py	Tue Aug 12 14:06:20 2003
@@ -55,24 +55,7 @@
     for func, aliases, short, long in command_table:
         cmd.addCommand(func.__name__, func, short, long, aliases)
 
-    try:
-        cmd.realize()
-        cmd.run()
-
-    except Usage, msg:
-        print >>sys.stderr, msg
-        print >>sys.stderr, "for help use --help"
-        return 2
-
-    except Error, msg:
-        print >>sys.stderr, msg
-        return 1
-
-    except SystemExit:
-        raise
-
-    else:
-        return None
+    return cmd.main()
 
 def checkout(opts, args):
     """%(program)s checkout URL [TARGETDIR]




More information about the Zope3-Checkins mailing list