[Checkins] SVN: grokproject/trunk/grokproject/main.py Add support for --version option.

Uli Fouquet uli at gnufix.de
Sat Jan 10 18:11:35 EST 2009


Log message for revision 94683:
  Add support for --version option.

Changed:
  U   grokproject/trunk/grokproject/main.py

-=-
Modified: grokproject/trunk/grokproject/main.py
===================================================================
--- grokproject/trunk/grokproject/main.py	2009-01-10 15:41:14 UTC (rev 94682)
+++ grokproject/trunk/grokproject/main.py	2009-01-10 23:11:35 UTC (rev 94683)
@@ -1,4 +1,5 @@
 import sys
+import pkg_resources
 from paste.script import command
 import optparse
 from grokproject import GrokProject
@@ -15,7 +16,9 @@
                       default=False, help="Be verbose.")
     parser.add_option('--zopectl', action="store_true", dest="zopectl",
                       default=False, help="Use zopectl.")
-
+    parser.add_option('--version', action="store_true", dest="version",
+                      default=False, help="Show grokproject version.")
+    
     # Options that override the interactive part of filling the templates.
     for var in GrokProject.vars:
         option_name = '--'+var.name.replace('_', '-')
@@ -25,6 +28,11 @@
                 help=var.description)
 
     options, args = parser.parse_args()
+    
+    if options.version:
+        print get_version()
+        return 0
+
     if len(args) != 1:
         parser.print_usage()
         return 1
@@ -53,3 +61,10 @@
     exit_code = runner.run(option_args + ['-t', 'grok', project]
                            + extra_args)
     sys.exit(exit_code)
+
+def get_version():
+    info = pkg_resources.get_distribution('grokproject')
+    if info.has_version and info.version:
+        return info.version
+    return 'Unknown'
+



More information about the Checkins mailing list