[Checkins] SVN: grokproject/trunk/ Do checks before asking questions. Define getters for some vars.

Maurits van Rees m.van.rees at zestsoftware.nl
Fri May 2 11:56:08 EDT 2008


Log message for revision 86105:
  Do checks before asking questions.  Define getters for some vars.
  Move no_buildout from the command to run_buildout in the template.
  Use version_info_url in the template instead of renaming it to
  extends.
  

Changed:
  U   grokproject/trunk/CHANGES.txt
  U   grokproject/trunk/grokproject/__init__.py
  U   grokproject/trunk/grokproject/template/buildout.cfg_tmpl

-=-
Modified: grokproject/trunk/CHANGES.txt
===================================================================
--- grokproject/trunk/CHANGES.txt	2008-05-02 15:37:17 UTC (rev 86104)
+++ grokproject/trunk/CHANGES.txt	2008-05-02 15:56:08 UTC (rev 86105)
@@ -4,6 +4,11 @@
 0.8 (unreleased)
 ------------------
 
+* Do checks before asking questions.  Define getters for some vars.
+  Move no_buildout from the command to run_buildout in the template.
+  Use version_info_url in the template instead of renaming it to
+  extends.
+
 * Remove the --newer option for bin/grokproject.  Use the 'newest'
   option from the template instead.
 

Modified: grokproject/trunk/grokproject/__init__.py
===================================================================
--- grokproject/trunk/grokproject/__init__.py	2008-05-02 15:37:17 UTC (rev 86104)
+++ grokproject/trunk/grokproject/__init__.py	2008-05-02 15:56:08 UTC (rev 86105)
@@ -16,13 +16,50 @@
 class ask_var(var):
 
     def __init__(self, name, description,
-                 default='', should_echo=True, should_ask=True):
+                 default='', should_echo=True, should_ask=True,
+                 getter=None):
         super(ask_var, self).__init__(
             name, description, default=default,
             should_echo=should_echo)
         self.should_ask = should_ask
+        self.getter = getter
+        if self.getter is None:
+            self.getter = lambda x, y: self.default
 
+def get_boolean_value_for_option(vars, option):
+    value = vars.get(option.name)
+    if value is not None:
+        if isinstance(option.default, bool):
+            want_boolean = True
+        else:
+            want_boolean = False
+        value = value.lower()
+        if value in ('1', 'true'):
+            if want_boolean:
+                value = True
+            else:
+                value = 'true'
+        elif value in ('0', 'false'):
+            if want_boolean:
+                value = False
+            else:
+                value = 'false'
+        else:
+            print ""
+            print "Error: %s should be true or false." % option.name
+            sys.exit(1)
+    else:
+        value = option.default
+    return value
 
+def get_version_info_url(vars, option):
+    value = vars.get(option.name, '')
+    if value == '':
+        info = urllib.urlopen(VERSIONINFO_INFO_URL).read().strip()
+        value = urlparse.urljoin(VERSIONINFO_INFO_URL, info)
+    return value
+
+
 class GrokProject(templates.Template):
     _template_dir = 'template'
     summary = "A grok project"
@@ -33,58 +70,45 @@
         ask_var('passwd', 'Password for the initial administrator user',
             default=NoDefault, should_echo=False),
         ask_var('newest', 'Check for newer versions of packages',
-                default='false', should_ask=False),
+                default='false', should_ask=False,
+                getter=get_boolean_value_for_option),
         ask_var('version_info_url',
             "The URL to a *.cfg file containing a [versions] section.",
-            default=None, should_ask=False),
+            default='', should_ask=False, getter=get_version_info_url),
+        ask_var('run_buildout', "After creating the project area "
+                "bootstrap the buildout.",
+                default=True, should_ask=False,
+                getter=get_boolean_value_for_option),
         ]
 
     def check_vars(self, vars, cmd):
+        if vars['package'] in ('grok', 'zope'):
+            print
+            print "Error: The chosen project name results in an invalid " \
+                  "package name: %s." % vars['package']
+            print "Please choose a different project name."
+            sys.exit(1)
+
         skipped_vars = {}
-        for var in self.vars:
+        for var in list(self.vars):
             if not var.should_ask:
-                skipped_vars[var.name] = var.default
+                skipped_vars[var.name] = var.getter(vars, var)
                 self.vars.remove(var)
 
         vars = super(GrokProject, self).check_vars(vars, cmd)
         for name in skipped_vars:
             vars[name] = skipped_vars[name]
-        extra_args = [v.split('=') for v in cmd.args if v.find('=') != -1]
-        for arg in extra_args:
-            name = arg[0]
-            value = arg[1]
-            if name in skipped_vars:
-                vars[name] = value
 
-        if vars['package'] in ('grok', 'zope'):
-            print
-            print "Error: The chosen project name results in an invalid " \
-                  "package name: %s." % vars['package']
-            print "Please choose a different project name."
-            sys.exit(1)
         for var_name in ['user', 'passwd']:
             # Escape values that go in site.zcml.
             vars[var_name] = xml.sax.saxutils.quoteattr(vars[var_name])
-        extends = vars.get('version_info_url')
-        if extends is None:
-            info = urllib.urlopen(VERSIONINFO_INFO_URL).read().strip()
-            extends = urlparse.urljoin(VERSIONINFO_INFO_URL, info)
-        vars['extends'] = extends
         vars['app_class_name'] = vars['project'].capitalize()
-
-        # We want to have newest be 'false' or 'true'.
-        if vars['newest'].lower() in ('1', 'true'):
-            vars['newest'] = 'true'
-        else:
-            vars['newest'] = 'false'
         return vars
 
+
 def main():
     usage = "usage: %prog [options] PROJECT"
     parser = optparse.OptionParser(usage=usage)
-    parser.add_option('--no-buildout', action="store_true", dest="no_buildout",
-                      default=False, help="Only create project area, do not "
-                      "bootstrap the buildout.")
     parser.add_option('--svn-repository', dest="repos", default=None,
                       help="Import project to given repository location (this "
                       "will also create the standard trunk/ tags/ branches/ "
@@ -132,11 +156,10 @@
                            + extra_args)
     # TODO exit_code
 
-    if options.no_buildout:
-        return
-
     os.chdir(project)
 
+    # TODO Handle buildout in post()
+
     extra_args = []
     if not options.verbose:
         extra_args.append('-q')

Modified: grokproject/trunk/grokproject/template/buildout.cfg_tmpl
===================================================================
--- grokproject/trunk/grokproject/template/buildout.cfg_tmpl	2008-05-02 15:37:17 UTC (rev 86104)
+++ grokproject/trunk/grokproject/template/buildout.cfg_tmpl	2008-05-02 15:56:08 UTC (rev 86105)
@@ -3,7 +3,7 @@
 parts = app data zopectl i18n test
 find-links = http://download.zope.org/distribution/
 newest = ${newest}
-extends = ${extends}
+extends = ${version_info_url}
 versions = versions
 
 [app]



More information about the Checkins mailing list