[Checkins] SVN: zc.buildout/branches/help-api/src/zc/buildout/buildout. * -A annotated sections options; display value origins

Godefroid Chapelle gotcha at bubblenet.be
Sun Mar 29 17:30:28 EDT 2009


Log message for revision 98587:
  * -A annotated sections options; display value origins
  
  * tests

Changed:
  U   zc.buildout/branches/help-api/src/zc/buildout/buildout.py
  U   zc.buildout/branches/help-api/src/zc/buildout/buildout.txt

-=-
Modified: zc.buildout/branches/help-api/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/help-api/src/zc/buildout/buildout.py	2009-03-29 21:30:21 UTC (rev 98586)
+++ zc.buildout/branches/help-api/src/zc/buildout/buildout.py	2009-03-29 21:30:27 UTC (rev 98587)
@@ -27,7 +27,9 @@
 import ConfigParser
 import UserDict
 import glob
+import copy
 
+
 import pkg_resources
 import zc.buildout
 import zc.buildout.easy_install
@@ -74,6 +76,25 @@
         data[key] = _annotate_section(data[key], note)
     return data
 
+def _print_annotate(data):
+    sections = data.keys()
+    sections.sort()
+    print
+    print "Annotated sections"
+    print "="*len("Annotated sections")
+    for section in sections:
+        print
+        print '[%s]' % section
+        keys = data[section].keys()
+        keys.sort()
+        for key in keys:
+            value, files = data[section][key]
+            print "%s=%s" % (key, value)
+            for file in files.split():
+                print "    " + file
+    print
+    print
+
 def _unannotate_section(section):
     for key in section:
         value, note = section[key]
@@ -95,7 +116,8 @@
     'executable': sys.executable,
     'log-level': 'INFO',
     'log-format': '',
-    }, 'default_option')
+    'annotate': 'false',
+    }, 'DEFAULT_VALUE')
 
 
 class Buildout(UserDict.DictMixin):
@@ -122,14 +144,14 @@
                     # Sigh. this model of a buildout nstance
                     # with methods is breaking down :(
                     config_file = None
-                    data['buildout']['directory'] = ('.', 'computed')
+                    data['buildout']['directory'] = ('.', 'COMPUTED_VALUE')
                 else:
                     raise zc.buildout.UserError(
                         "Couldn't open %s" % config_file)
 
             if config_file:
                 data['buildout']['directory'] = (os.path.dirname(config_file),
-                    'computed')
+                    'COMPUTED_VALUE')
         else:
             base = None
 
@@ -150,11 +172,13 @@
             options = data.get(section)
             if options is None:
                 options = data[section] = {}
-            options[option] = value, "command-line"
+            options[option] = value, "COMMAND_LINE_VALUE"
                 # The egg dire
 
-        self._annotated = data
+        self._annotated = copy.deepcopy(data)
         self._raw = _unannotate(data)
+        if data['buildout']['annotate'] == 'true':
+            _print_annotate(self._annotated)
         self._data = {}
         self._parts = []
         # provide some defaults before options are parsed
@@ -1357,14 +1381,14 @@
         if k.endswith('+'):
             key = k.rstrip(' +')
             v1, note1 = s1.get(key, ("", ""))
-            newnote = ' '.join((note1, note2)).strip()
+            newnote = ' +'.join((note1, note2)).strip()
             s2[key] = "\n".join((v1).split('\n') +
                 v2.split('\n')), newnote
             del s2[k]
         elif k.endswith('-'):
             key = k.rstrip(' -')
             v1, note1 = s1.get(key, ("", ""))
-            newnote = ' '.join((note1, note2)).strip()
+            newnote = ' -'.join((note1, note2)).strip()
             s2[key] = ("\n".join(
                 [v for v in v1.split('\n')
                    if v not in v2.split('\n')]), newnote)
@@ -1487,6 +1511,11 @@
     will be started. This is especially useful for debuging recipe
     problems.
 
+  -A
+
+    Display annotated sections. Each key-value pair is displayed along
+    with its value origin.
+
 Assignments are of the form: section:option=value and are used to
 provide configuration options that override those given in the
 configuration file.  For example, to run the buildout in offline mode,
@@ -1549,7 +1578,7 @@
         if args[0][0] == '-':
             op = orig_op = args.pop(0)
             op = op[1:]
-            while op and op[0] in 'vqhWUoOnND':
+            while op and op[0] in 'vqhWUoOnNDA':
                 if op[0] == 'v':
                     verbosity += 10
                 elif op[0] == 'q':
@@ -1568,6 +1597,8 @@
                     options.append(('buildout', 'newest', 'false'))
                 elif op[0] == 'D':
                     debug = True
+                elif op[0] == 'A':
+                    options.append(('buildout', 'annotate', 'true'))
                 else:
                     _help()
                 op = op[1:]

Modified: zc.buildout/branches/help-api/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/branches/help-api/src/zc/buildout/buildout.txt	2009-03-29 21:30:21 UTC (rev 98586)
+++ zc.buildout/branches/help-api/src/zc/buildout/buildout.txt	2009-03-29 21:30:27 UTC (rev 98587)
@@ -707,6 +707,57 @@
 keep section and option names simple, sticking to alphanumeric
 characters, hyphens, and periods.
 
+Annotated sections
+------------------
+
+When used with the -A option, buildout displays annotated sections. 
+All sections are displayed, sorted alphabetically. For each section,
+all key-value pairs are displayed, sorted alphabetically, along with 
+the origin of the value (file name or COMPUTED_VALUE, DEFAULT_VALUE, 
+COMMAND_LINE_VALUE).
+
+    >>> print system(buildout+ ' -A'), # doctest: +ELLIPSIS
+    <BLANKLINE>
+    Annotated sections
+    ==================
+    <BLANKLINE>
+    [buildout]
+    annotate=true
+        COMMAND_LINE_VALUE
+    bin-directory=bin
+        DEFAULT_VALUE
+    develop=recipes
+        .../_TEST_/sample-buildout/buildout.cfg
+    develop-eggs-directory=develop-eggs
+        DEFAULT_VALUE
+    directory=.../_TEST_/sample-buildout
+        COMPUTED_VALUE
+    eggs-directory=eggs
+        DEFAULT_VALUE
+    executable=...
+        DEFAULT_VALUE
+    installed=.installed.cfg
+        DEFAULT_VALUE
+    log-format=
+        DEFAULT_VALUE
+    log-level=INFO
+        DEFAULT_VALUE
+    parts=data-dir
+        .../_TEST_/sample-buildout/buildout.cfg
+    parts-directory=parts
+        DEFAULT_VALUE
+    python=buildout
+        DEFAULT_VALUE
+    <BLANKLINE>
+    [data-dir]
+    path=foo bins
+        .../_TEST_/sample-buildout/buildout.cfg
+    recipe=recipes:mkdir
+        .../_TEST_/sample-buildout/buildout.cfg
+    <BLANKLINE>
+    <BLANKLINE>
+    ...
+
 Variable substitutions
 ----------------------
 
@@ -1025,6 +1076,46 @@
     ['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'h1 h2']
     Develop: '/sample-buildout/demo'
 
+Annotated sections output shows which files are responsible for which
+operations.
+
+    >>> print system(os.path.join('bin', 'buildout') + ' -A'), # doctest: +ELLIPSIS
+    <BLANKLINE>
+    Annotated sections
+    ==================
+    ...
+    <BLANKLINE>
+    [part1]
+    option=a1 a2
+    a3 a4
+    a5
+        .../_TEST_/sample-buildout/base.cfg
+        +.../_TEST_/sample-buildout/extension1.cfg
+        +.../_TEST_/sample-buildout/extension2.cfg
+    recipe=
+        .../_TEST_/sample-buildout/base.cfg
+    <BLANKLINE>
+    [part2]
+    option=b1 b2 b3 b4
+        .../_TEST_/sample-buildout/base.cfg
+        -.../_TEST_/sample-buildout/extension1.cfg
+        -.../_TEST_/sample-buildout/extension2.cfg
+    recipe=
+        .../_TEST_/sample-buildout/base.cfg
+    <BLANKLINE>
+    [part3]
+    option=c1 c2
+    c3 c4 c5
+        .../_TEST_/sample-buildout/base.cfg
+        +.../_TEST_/sample-buildout/extension1.cfg
+    recipe=
+        .../_TEST_/sample-buildout/base.cfg
+    <BLANKLINE>
+    [part4]
+    option=h1 h2
+        .../_TEST_/sample-buildout/extension1.cfg
+    ...
+
 Cleanup.
 
     >>> os.remove(os.path.join(sample_buildout, 'base.cfg'))
@@ -1627,6 +1718,12 @@
     new distributions if installed distributions satisfy it's
     requirements.
 
+-A
+    Display annotated sections. All sections are displayed, sorted
+    alphabetically. For each section, all key-value pairs are displayed,
+    sorted alphabetically, along with the origin of the value (file name or 
+    COMPUTED_VALUE, DEFAULT_VALUE, COMMAND_LINE_VALUE).
+
 Assignments are of the form::
 
   section_name:option_name=value
@@ -2029,6 +2126,7 @@
     <BLANKLINE>
     Configuration data:
     [buildout]
+    annotate = false
     bin-directory = /sample-buildout/bin
     develop-eggs-directory = /sample-buildout/develop-eggs
     directory = /sample-buildout



More information about the Checkins mailing list