[Checkins] SVN: zc.recipe.deployment/trunk/ issue deprecation warnings if "etc", "log", or "var" settings are present,

Fred Drake cvs-admin at zope.org
Thu Mar 21 13:49:50 UTC 2013


Log message for revision 130145:
  issue deprecation warnings if "etc", "log", or "var" settings are present,
  indicating whether the values were used

Changed:
  U   zc.recipe.deployment/trunk/CHANGES.txt
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt

-=-
Modified: zc.recipe.deployment/trunk/CHANGES.txt
===================================================================
--- zc.recipe.deployment/trunk/CHANGES.txt	2013-03-21 12:34:18 UTC (rev 130144)
+++ zc.recipe.deployment/trunk/CHANGES.txt	2013-03-21 13:49:49 UTC (rev 130145)
@@ -8,10 +8,12 @@
   relative.
 
 - Add ``etc-prefix`` and ``var-prefix`` to specify new locations of
-  these entire trees; used instead of the previously untested ``etc``,
-  ``log`` and ``run`` settings.  Final (absolute) versions of these
-  paths are always exported in the output.
+  these entire trees.  Final versions of these paths are exported.
 
+- Previously undocumented & untested ``etc``, ``log`` and ``run``
+  settings are deprecated.  Warnings are logged if their values are
+  used.
+
 - Add ``cache-directory`` and ``lib-directory`` to the set of output
   directories.
 

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2013-03-21 12:34:18 UTC (rev 130144)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2013-03-21 13:49:49 UTC (rev 130145)
@@ -28,6 +28,15 @@
 logger = logging.getLogger('zc.recipe.deployment')
 
 
+def deprecated(name, instead=None):
+    if instead:
+        msg = ("found deprecated '%s' setting (used '%s' instead)"
+               % (name, instead))
+    else:
+        msg = "using deprecated '%s' setting" % name
+    logger.warn(msg)
+
+
 class Install:
 
     def __init__(self, buildout, name, options):
@@ -39,29 +48,51 @@
         prefix = os.path.join('/', options.get('prefix') or '/')
         options['prefix'] = prefix
 
-        etc = os.path.join(
-            prefix, options.get('etc-prefix') or options.get('etc') or 'etc')
+        etc_prefix = options.get('etc-prefix')
+        if not etc_prefix:
+            etc_prefix = options.get('etc')
+            if etc_prefix:
+                deprecated('etc')
+            else:
+                etc_prefix = 'etc'
+        elif options.get('etc'):
+            deprecated('etc', 'etc-prefix')
+        etc = os.path.join(prefix, etc_prefix)
 
         cfg = os.path.join(etc, "zc.recipe.deployment.cfg")
         cp = ConfigParser.RawConfigParser()
         cp.optionxform = str
         cp.read(cfg)
         if cp.has_section("deployment"):
-            for key in cp.options("deployment"):
-                if key in ("log", "run", "var-prefix"):
+            for key in sorted(cp.options("deployment")):
+                if key == "var-prefix":
                     value = cp.get("deployment", key)
                     if value and not options.get(key):
                         options[key] = value
-                elif key:
+                else:
                     raise zc.buildout.UserError(
-                        "disallowed option %s in system configuration" % key)
+                        "disallowed option %r in system configuration" % key)
 
         var = os.path.join(prefix, options.get('var-prefix') or 'var')
         if options.get('var-prefix'):
+            if options.get('log'):
+                deprecated('log', 'var-prefix')
             log = os.path.join(var, "log")
+            if options.get('run'):
+                deprecated('run', 'var-prefix')
             run = os.path.join(var, "run")
         else:
+            if options.get('log'):
+                if options.get('log-directory'):
+                    deprecated('log', 'log-directory')
+                else:
+                    deprecated('log')
             log = options.get('log') or 'var/log'
+            if options.get('run'):
+                if options.get('run-directory'):
+                    deprecated('run', 'run-directory')
+                else:
+                    deprecated('run')
             run = options.get('run') or 'var/run'
 
         def directory(key, base, *tail):

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt	2013-03-21 12:34:18 UTC (rev 130144)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/paths.txt	2013-03-21 13:49:49 UTC (rev 130145)
@@ -9,13 +9,23 @@
    don't break existing uses that do not use the newer ``etc-prefix``
    and ``var-prefix`` settings, but the later are recommended.
 
+    >>> import logging
     >>> import pprint
     >>> import zc.recipe.deployment
 
+    >>> import zope.testing.loggingsupport
+
+    >>> logging.getLogger("zc.recipe.deployment").propagate = False
+    >>> handler = zope.testing.loggingsupport.InstalledHandler(
+    ...     "zc.recipe.deployment")
+
     >>> def compute(options, name="myapp"):
     ...     options = options.copy()
+    ...     handler.clear()
     ...     zc.recipe.deployment.Install(object(), name, options)
     ...     pprint.pprint(options, width=1)
+    ...     if handler.records:
+    ...         print handler
 
 Deployment-specific directories are created based on the name of the part:
 
@@ -103,13 +113,20 @@
      'run': '/run/someplace',
      'run-directory': '/run/someplace/myapp',
      'var-prefix': '/usr/local/var'}
+    zc.recipe.deployment WARNING
+      using deprecated 'etc' setting
+    zc.recipe.deployment WARNING
+      using deprecated 'log' setting
+    zc.recipe.deployment WARNING
+      using deprecated 'run' setting
 
-If the ``etc`` and ``log`` settings are relative, the ``prefix`` setting
-also applies:
+If the ``etc``, ``log`` and ``run`` settings are relative, the
+``prefix`` setting also applies:
 
     >>> compute({"etc": "antsy",
     ...          "log": "var/someplace",
-    ...          "prefix": "/usr/local"})
+    ...          "prefix": "/usr/local",
+    ...          "run": "var/running"})
     {'cache-directory': '/usr/local/var/cache/myapp',
      'crontab-directory': '/usr/local/antsy/cron.d',
      'etc': 'antsy',
@@ -122,8 +139,15 @@
      'name': 'myapp',
      'prefix': '/usr/local',
      'rc-directory': '/usr/local/antsy/init.d',
-     'run-directory': '/usr/local/var/run/myapp',
+     'run': 'var/running',
+     'run-directory': '/usr/local/var/running/myapp',
      'var-prefix': '/usr/local/var'}
+    zc.recipe.deployment WARNING
+      using deprecated 'etc' setting
+    zc.recipe.deployment WARNING
+      using deprecated 'log' setting
+    zc.recipe.deployment WARNING
+      using deprecated 'run' setting
 
 Output options ending in '-directory' can be specified directly; these
 values will be retained instead of being clobbered by computed values:
@@ -153,6 +177,10 @@
      'rc-directory': '/my-rcs',
      'run-directory': '/variable/run-away',
      'var-prefix': '/usr/local/var'}
+    zc.recipe.deployment WARNING
+      using deprecated 'etc' setting
+    zc.recipe.deployment WARNING
+      found deprecated 'log' setting (used 'log-directory' instead)
 
 
 Paths are absolute
@@ -195,6 +223,10 @@
      'rc-directory': '/my/prefix/my-rcs',
      'run-directory': '/my/prefix/var/run/myapp',
      'var-prefix': '/my/prefix/var'}
+    zc.recipe.deployment WARNING
+      using deprecated 'etc' setting
+    zc.recipe.deployment WARNING
+      using deprecated 'log' setting
 
 
 Specifying sub-tree prefixes
@@ -282,6 +314,8 @@
      'rc-directory': '/config/init.d',
      'run-directory': '/var/run/myapp',
      'var-prefix': '/var'}
+    zc.recipe.deployment WARNING
+      found deprecated 'etc' setting (used 'etc-prefix' instead)
 
 If ``var-prefix`` is used in conjunction with the (legacy) ``log`` and
 ``run`` settings, ``var-prefix`` wins:
@@ -303,6 +337,10 @@
      'run': '/run/someplace',
      'run-directory': '/big-disk/run/myapp',
      'var-prefix': '/big-disk'}
+    zc.recipe.deployment WARNING
+      found deprecated 'log' setting (used 'var-prefix' instead)
+    zc.recipe.deployment WARNING
+      found deprecated 'run' setting (used 'var-prefix' instead)
 
 
 Overriding settings from the target system
@@ -367,59 +405,57 @@
      'rc-directory': 'PREFIX/init.d',
      'run-directory': '/mnt/fatdisk/run/myapp',
      'var-prefix': '/mnt/fatdisk'}
+    zc.recipe.deployment WARNING
+      using deprecated 'etc' setting
 
-The ``log`` and ``run`` settings can be used here, though that's less
-interesting than ``var-prefix``:
 
+Disallowed settings
+~~~~~~~~~~~~~~~~~~~
+
+Attempting to set the location of /etc from the configuration file is an
+error, since the /etc location has already been determined:
+
     >>> write(config_path,
     ... '''\
     ... [deployment]
-    ... log = /mnt/fatdisk/logs
-    ... run = /mnt/scratch
+    ... etc-prefix = /some/where
     ... ''')
 
-    >>> compute({"etc-prefix": sample_buildout})
-    {'cache-directory': '/var/cache/myapp',
-     'crontab-directory': 'PREFIX/cron.d',
-     'etc-directory': 'PREFIX/myapp',
-     'etc-prefix': 'PREFIX',
-     'lib-directory': '/var/lib/myapp',
-     'log': '/mnt/fatdisk/logs',
-     'log-directory': '/mnt/fatdisk/logs/myapp',
-     'logrotate-directory': 'PREFIX/logrotate.d',
-     'name': 'myapp',
-     'prefix': '/',
-     'rc-directory': 'PREFIX/init.d',
-     'run': '/mnt/scratch',
-     'run-directory': '/mnt/scratch/myapp',
-     'var-prefix': '/var'}
+    >>> compute({"etc": sample_buildout})
+    Traceback (most recent call last):
+    UserError: disallowed option 'etc-prefix' in system configuration
 
+    >>> write(config_path,
+    ... '''\
+    ... [deployment]
+    ... etc = /some/where
+    ... ''')
 
-Disallowed settings
-~~~~~~~~~~~~~~~~~~~
+    >>> compute({"etc": sample_buildout})
+    Traceback (most recent call last):
+    UserError: disallowed option 'etc' in system configuration
 
-Attempting to set the location of /etc from the configuration file is an
-error, since the /etc location has already been determined:
+The deprecated ``log`` and ``run`` settings cannot be used here:
 
     >>> write(config_path,
     ... '''\
     ... [deployment]
-    ... etc-prefix = /some/where
+    ... log = /mnt/scratch
     ... ''')
 
     >>> compute({"etc": sample_buildout})
     Traceback (most recent call last):
-    UserError: disallowed option etc-prefix in system configuration
+    UserError: disallowed option 'log' in system configuration
 
     >>> write(config_path,
     ... '''\
     ... [deployment]
-    ... etc = /some/where
+    ... run = /mnt/scratch
     ... ''')
 
     >>> compute({"etc": sample_buildout})
     Traceback (most recent call last):
-    UserError: disallowed option etc in system configuration
+    UserError: disallowed option 'run' in system configuration
 
 Specific -directory settings cannot be included in the system
 configuration file:
@@ -432,4 +468,4 @@
 
     >>> compute({"etc": sample_buildout})
     Traceback (most recent call last):
-    UserError: disallowed option log-directory in system configuration
+    UserError: disallowed option 'log-directory' in system configuration



More information about the checkins mailing list