[Checkins] SVN: Sandbox/J1m/sbo/ Gaaaa. Porting *latest* rev from zc repo

Jim Fulton jim at zope.com
Mon Mar 7 06:22:49 EST 2011


Log message for revision 120787:
  Gaaaa. Porting *latest* rev from zc repo

Changed:
  U   Sandbox/J1m/sbo/README.txt
  U   Sandbox/J1m/sbo/src/zc/sbo/__init__.py
  U   Sandbox/J1m/sbo/src/zc/sbo/sbo.test
  U   Sandbox/J1m/sbo/src/zc/sbo/tests.py

-=-
Modified: Sandbox/J1m/sbo/README.txt
===================================================================
--- Sandbox/J1m/sbo/README.txt	2011-03-07 11:16:56 UTC (rev 120786)
+++ Sandbox/J1m/sbo/README.txt	2011-03-07 11:22:49 UTC (rev 120787)
@@ -1,13 +1,30 @@
-Title Here
-**********
+System Buildouts
+****************
 
+The system buildout script (``sbo``) provided by the zc.sbo package is
+used to perform "system" buildouts that write to system directories
+on unix-like systems.  They are run using ``sudo`` or as ``root`` so
+they can write to system directiories.  You can install the ``sbo``
+command into a Python environment using its setupo script or a tool
+like easy_install.
 
-To learn more, see
+One installed, the ``sbo`` command is typically run with 2 arguments:
 
 
 Changes
 *******
 
+0.6.1 (unreleased)
+==================
+
+- Add missing --version option to report sbo's version.
+
+
+0.6.0 (2010-11-05)
+==================
+
+- Add --installation to point to a specific software installation to use.
+
 0.1.0 (yyyy-mm-dd)
 ==================
 

Modified: Sandbox/J1m/sbo/src/zc/sbo/__init__.py
===================================================================
--- Sandbox/J1m/sbo/src/zc/sbo/__init__.py	2011-03-07 11:16:56 UTC (rev 120786)
+++ Sandbox/J1m/sbo/src/zc/sbo/__init__.py	2011-03-07 11:22:49 UTC (rev 120787)
@@ -1,15 +1,23 @@
 import optparse
 import os
+import pkg_resources
 import subprocess
 import sys
 import tempfile
 
+
+for dist in pkg_resources.working_set:
+    if dist.project_name == "zc.sbo":
+        version = dist.version
+assert version
+
+
 parser = optparse.OptionParser("""\
 Usage: %prog [options] application [configuration]
 
 Configure or unconfigure an application defined by a buildout
 configuration file.  By default, an application is configured.  If the
--U option is provided, then the application is unconfigured.  An
+-u option is provided, then the application is unconfigured.  An
 optional configuration name may be given.  If not given, the
 configuration name defaults to the application name.
 
@@ -29,7 +37,7 @@
    /opt/${application}/bin/buildout
 
 So the named application must be installed in /opt.
-""")
+""", version=("%%prog %s" % version))
 
 parser.add_option(
     '-a', '--all', action="store_true", dest="all",
@@ -37,6 +45,11 @@
     )
 
 parser.add_option(
+    '-i', '--installation', action="store", dest="installation",
+    help="""Installation directory of the application.""",
+    )
+
+parser.add_option(
     '-l', '--list', action="store_true", dest="list",
     help="""List available configurations.""",
     )
@@ -91,7 +104,10 @@
         error("No application was specified.")
     application = args.pop(0)
 
-    app_dir = os.path.join(root, 'opt', application)
+    if options.installation:
+        app_dir = options.installation
+    else:
+        app_dir = os.path.join(root, 'opt', application)
     assert_exists("The application directory", app_dir)
 
     buildout = os.path.join(app_dir, 'bin', 'buildout')

Modified: Sandbox/J1m/sbo/src/zc/sbo/sbo.test
===================================================================
--- Sandbox/J1m/sbo/src/zc/sbo/sbo.test	2011-03-07 11:16:56 UTC (rev 120786)
+++ Sandbox/J1m/sbo/src/zc/sbo/sbo.test	2011-03-07 11:22:49 UTC (rev 120787)
@@ -17,7 +17,7 @@
     <BLANKLINE>
     Configure or unconfigure an application defined by a buildout
     configuration file.  By default, an application is configured.  If the
-    -U option is provided, then the application is unconfigured.  An
+    -u option is provided, then the application is unconfigured.  An
     optional configuration name may be given.  If not given, the
     configuration name defaults to the application name.
     <BLANKLINE>
@@ -40,8 +40,11 @@
     <BLANKLINE>
     <BLANKLINE>
     Options:
+      --version             show program's version number and exit
       -h, --help            show this help message and exit
       -a, --all             Operate on all configurations.
+      -i INSTALLATION, --installation=INSTALLATION
+                            Installation directory of the application.
       -l, --list            List available configurations.
       -q                    Decrease the verbosity
       --test-root=TEST_ROOT
@@ -227,7 +230,42 @@
     -oUvc
     ...tmp/...buildout
 
+We can specify an alternate application installation while still
+pointing to the usual place for configurations:
 
+    >>> test('--test-root', 'root', '--installation', 'myapp-1.2.3',
+    ...      'myapp', 'cust') # doctest: +ELLIPSIS
+    Error:
+    The application directory, 'myapp-1.2.3', doesn't exist.
+    ...
+    Exit status 1
+
+Let's create an application installation there:
+
+    >>> myapp123 = os.path.join('root', 'opt', 'myapp-1.2.3')
+    >>> os.makedirs(myapp123)
+    >>> os.makedirs(os.path.join(myapp123, 'bin'))
+    >>> open(os.path.join(myapp123, 'bin', 'buildout'), 'w').write(
+    ... """#!%s
+    ... import sys
+    ... installed = [a[19:] for a in sys.argv
+    ...              if a.startswith('buildout:installed=')][0]
+    ... open(installed, 'w').write('\\n'.join(sys.argv[1:]))
+    ... """ % sys.executable)
+    >>> os.chmod(os.path.join(myapp123, 'bin', 'buildout'), 0755)
+
+    >>> test('--test-root', 'root', '--installation', myapp123,
+    ...      'myapp', 'cust') # doctest: +ELLIPSIS
+    Configuring: cust
+
+    >>> print open(os.path.join('root', 'etc', 'myapp', 'cust.configured')
+    ... ).read()
+    buildout:installed=root/etc/myapp/cust.configured
+    buildout:directory=root/opt/myapp-1.2.3
+    -oUc
+    root/etc/myapp/cust.cfg
+
+
 Cleanup
 
     >>> tempfile.tempdir = oldtempdir

Modified: Sandbox/J1m/sbo/src/zc/sbo/tests.py
===================================================================
--- Sandbox/J1m/sbo/src/zc/sbo/tests.py	2011-03-07 11:16:56 UTC (rev 120786)
+++ Sandbox/J1m/sbo/src/zc/sbo/tests.py	2011-03-07 11:22:49 UTC (rev 120787)
@@ -18,9 +18,9 @@
 def test_suite():
     return doctest.DocFileSuite(
         'sbo.test',
+        optionflags=doctest.NORMALIZE_WHITESPACE,
         setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown,
         )
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
-



More information about the checkins mailing list