[Checkins] SVN: z3c.recipe.i18n/branches/baijum-zcml-path/ Implement new Feature: The value of `zcml` option

Baiju M baiju.m.mail at gmail.com
Sat Aug 7 06:08:50 EDT 2010


Log message for revision 115534:
  Implement new Feature: The value of `zcml` option
  could be path to ZCML file or ZCML string.
  

Changed:
  U   z3c.recipe.i18n/branches/baijum-zcml-path/CHANGES.txt
  U   z3c.recipe.i18n/branches/baijum-zcml-path/setup.py
  U   z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/README.txt
  U   z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/i18n.py

-=-
Modified: z3c.recipe.i18n/branches/baijum-zcml-path/CHANGES.txt
===================================================================
--- z3c.recipe.i18n/branches/baijum-zcml-path/CHANGES.txt	2010-08-07 10:05:20 UTC (rev 115533)
+++ z3c.recipe.i18n/branches/baijum-zcml-path/CHANGES.txt	2010-08-07 10:08:49 UTC (rev 115534)
@@ -2,12 +2,12 @@
 CHANGES
 =======
 
-0.7.1 (unreleased)
+0.8.0 (unreleased)
 ------------------
 
-- Nothing changed yet.
+- Feature: The value of `zcml` option could be path to ZCML file
+  or ZCML string.
 
-
 0.7.0 (2010-02-18)
 ------------------
 

Modified: z3c.recipe.i18n/branches/baijum-zcml-path/setup.py
===================================================================
--- z3c.recipe.i18n/branches/baijum-zcml-path/setup.py	2010-08-07 10:05:20 UTC (rev 115533)
+++ z3c.recipe.i18n/branches/baijum-zcml-path/setup.py	2010-08-07 10:08:49 UTC (rev 115534)
@@ -26,7 +26,7 @@
 
 setup(
     name = 'z3c.recipe.i18n',
-    version = '0.7.1dev',
+    version = '0.8.0dev',
     author = 'Roger Ineichen and the Zope Community',
     author_email = 'zope-dev at zope.org',
     description = 'Zope3 egg based i18n locales extration recipes',

Modified: z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/README.txt
===================================================================
--- z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/README.txt	2010-08-07 10:05:20 UTC (rev 115533)
+++ z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/README.txt	2010-08-07 10:08:49 UTC (rev 115534)
@@ -52,8 +52,8 @@
   be a catalog dictionary.
 
 zcml (required)
-  The contents of configuration used for extraction. Normaly used for load
-  meta configuration.
+  The contents of configuration used for extraction.  Normaly used for load meta
+  configuration.  This value could be path to ZCML file or ZCML string.
 
 excludeDefaultDomain (optional, default=False)
   Exclude all messages found as part of the default domain. Messages are in
@@ -97,13 +97,6 @@
   ... setup(name = 'demo1')
   ... ''')
 
-  >>> mkdir('demo2')
-  >>> write('demo2', 'setup.py',
-  ... '''
-  ... from setuptools import setup
-  ... setup(name = 'demo2', install_requires='demo1')
-  ... ''')
-
 Now check if the setup was correct:
 
   >>> ls('bin')
@@ -123,7 +116,7 @@
   ... packages = demo1
   ... domain = recipe
   ... output = outputDir
-  ... zcml = <include package="z3c.recipe.tests" file="extract.zcml" />"
+  ... zcml = <include package="z3c.recipe.tests" file="extract.zcml" />
   ... ''' % globals())
 
 Now, Let's run the buildout and see what we get:
@@ -145,6 +138,53 @@
   -  i18nmergeall
   -  i18nstats
 
+Test ZCML file path
+-------------------
+
+  >>> write('demo1', 'site.zcml',
+  ... '''
+  ... ''')
+  >>> zcml = join('demo1', 'site.zcml')
+
+Lets create a minimal `buildout.cfg` file with `zcml` option pointing
+to a path:
+
+  >>> write('buildout.cfg',
+  ... '''
+  ... [buildout]
+  ... parts = i18n
+  ... offline = true
+  ...
+  ... [i18n]
+  ... recipe = z3c.recipe.i18n:i18n
+  ... eggs = z3c.recipe.i18n
+  ... packages = demo1
+  ... domain = recipe
+  ... output = outputDir
+  ... zcml = %(zcml)s
+  ... ''' % globals())
+
+Now, Let's run the buildout and see what we get:
+
+  >>> print system(join('bin', 'buildout')),
+  Uninstalling i18n.
+  Installing i18n.
+  i18n: setting up i18n tools
+  Generated script '/sample-buildout/bin/i18nextract'.
+  Generated script '/sample-buildout/bin/i18nmergeall'.
+  Generated script '/sample-buildout/bin/i18nstats'.
+  Generated script '/sample-buildout/bin/i18ncompile'.
+
+After running buildout, the bin folder contains the different i18n script:
+
+  >>> ls('bin')
+  -  buildout
+  -  i18ncompile
+  -  i18nextract
+  -  i18nmergeall
+  -  i18nstats
+
+
 i18nextract
 -----------
 
@@ -243,7 +283,7 @@
   ... packages = demo1
   ... domain = recipe
   ... output = outputDir
-  ... zcml = <include package="z3c.recipe.tests" file="extract.zcml" />"
+  ... zcml = <include package="z3c.recipe.tests" file="extract.zcml" />
   ... maker = z3c.csvvocabulary.csvStrings
   ... excludeDefaultDomain = true
   ... pythonOnly = true

Modified: z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/i18n.py
===================================================================
--- z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/i18n.py	2010-08-07 10:05:20 UTC (rev 115533)
+++ z3c.recipe.i18n/branches/baijum-zcml-path/src/z3c/recipe/i18n/i18n.py	2010-08-07 10:08:49 UTC (rev 115534)
@@ -23,6 +23,8 @@
 import zc.recipe.egg
 
 import pkg_resources
+from xml.dom.minidom import parseString
+from xml.parsers.expat import ExpatError
 
 this_loc = pkg_resources.working_set.find(
     pkg_resources.Requirement.parse('z3c.recipe.i18n')).location
@@ -74,7 +76,12 @@
         zcml = self.options.get('zcml', None)
         if zcml is None:
             raise zc.buildout.UserError('No zcml configuration defined.')
-        zcml = zcmlTemplate % zcml
+        try:
+            parseString(zcml)
+        except ExpatError:
+            zcml = open(zcml).read()
+        else:
+            zcml = zcmlTemplate % zcml
 
         # get domain
         domain = self.options.get('domain', None)



More information about the checkins mailing list