[Checkins] SVN: z3c.recipe.i18n/trunk/ Implemented environment argument support

Roger Ineichen roger at projekt01.ch
Sat May 3 11:26:52 EDT 2008


Log message for revision 86236:
  Implemented environment argument support
  Added tests

Changed:
  U   z3c.recipe.i18n/trunk/CHANGES.txt
  U   z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
  U   z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py

-=-
Modified: z3c.recipe.i18n/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.i18n/trunk/CHANGES.txt	2008-05-03 15:21:09 UTC (rev 86235)
+++ z3c.recipe.i18n/trunk/CHANGES.txt	2008-05-03 15:26:51 UTC (rev 86236)
@@ -5,4 +5,8 @@
 Version 0.5.0 (unreleased)
 --------------------------
 
+- Implemented environment section argument support for i18nextract.py script. 
+  This is a name of a section which defines a set of environment variables that 
+  should be exported before starting the extraction.
+
 - Initial Release

Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt	2008-05-03 15:21:09 UTC (rev 86235)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt	2008-05-03 15:26:51 UTC (rev 86236)
@@ -64,6 +64,12 @@
   Allows to specify one or more directory name, relative to the package, to 
   exclude. (None if not used)
 
+environment
+    A section name defining a set of environment variables that should be 
+    exported before starting the tests. Can be used for set product 
+    configuration enviroment.
+
+
 Test
 ****
 
@@ -106,9 +112,9 @@
   >>> print system(join('bin', 'buildout')),
   Installing i18n.
   i18n: setting up i18n tools
-  Generated script 'bin\\i18nextract'.
-  Generated script 'bin\\i18nmergeall'.
-  Generated script 'bin\\i18nstats'.
+  Generated script '/sample-buildout/bin/i18nextract'.
+  Generated script '/sample-buildout/bin/i18nmergeall'.
+  Generated script '/sample-buildout/bin/i18nstats'.
 
 After running buildout, the bin folder contains the different i18n script:
 
@@ -132,9 +138,14 @@
   <BLANKLINE>
   import sys
   sys.path[0:0] = [
-    ...
+  ...
     ]
   <BLANKLINE>
+  import os
+  sys.argv[0] = os.path.abspath(sys.argv[0])
+  os.chdir('...src')
+  <BLANKLINE>
+  <BLANKLINE>
   import z3c.recipe.i18n.i18nextract
   <BLANKLINE>
   if __name__ == '__main__':
@@ -188,6 +199,9 @@
   ... parts = i18n
   ... offline = true
   ...
+  ... [testenv]
+  ... fooDir = ${buildout:directory}/parts/foo
+  ...
   ... [i18n]
   ... recipe = z3c.recipe.i18n:i18n
   ... eggs = z3c.recipe.i18n
@@ -200,6 +214,7 @@
   ... pythonOnly = true
   ... exludeDirectoryName = foo
   ...                       bar
+  ... environment = testenv
   ... ''' % globals())
 
 Now, Let's run the buildout and see what we get:
@@ -208,9 +223,9 @@
   Uninstalling i18n.
   Installing i18n.
   i18n: setting up i18n tools
-  Generated script 'bin\\i18nextract'.
-  Generated script 'bin\\i18nmergeall'.
-  Generated script 'bin\\i18nstats'.
+  Generated script '/sample-buildout/bin/i18nextract'.
+  Generated script '/sample-buildout/bin/i18nmergeall'.
+  Generated script '/sample-buildout/bin/i18nstats'.
 
 After running buildout, the bin folder contains the different i18n script:
 
@@ -231,13 +246,18 @@
 The i18nextract.py contains the following code:
 
   >>> cat('bin', 'i18nextract-script.py')
-  #!C:\Python24\python.exe
   <BLANKLINE>
   import sys
   sys.path[0:0] = [
   ...
     ]
   <BLANKLINE>
+  import os
+  sys.argv[0] = os.path.abspath(sys.argv[0])
+  os.chdir('...src')
+  os.environ['fooDir'] = '/sample-buildout/parts/foo'
+  <BLANKLINE>
+  <BLANKLINE>
   import z3c.recipe.i18n.i18nextract
   <BLANKLINE>
   if __name__ == '__main__':

Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py	2008-05-03 15:21:09 UTC (rev 86235)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py	2008-05-03 15:26:51 UTC (rev 86236)
@@ -37,7 +37,16 @@
 </configure>
 """
 
+initialization_template = """import os
+sys.argv[0] = os.path.abspath(sys.argv[0])
+os.chdir(%r)
+"""
 
+
+env_template = """os.environ['%s'] = %r
+"""
+
+
 class I18nSetup(object):
 
     def __init__(self, buildout, name, options):
@@ -115,11 +124,21 @@
         for x in exludeDirNames:
             arguments.extend(['-x', x])
 
+        initialization = initialization_template % this_loc
+        env_section = self.options.get('environment', '').strip()
+        if env_section:
+            env = self.buildout[env_section]
+            for key, value in env.items():
+                initialization += env_template % (key, value)
+
+        # Generate i18nextract
         generated = zc.buildout.easy_install.scripts(
             [('%sextract'% self.name, 'z3c.recipe.i18n.i18nextract', 'main')],
-            ws, self.options['executable'], 'bin',
+            ws, self.options['executable'],
+            self.buildout['buildout']['bin-directory'],
             extra_paths = [this_loc],
             arguments = arguments,
+            initialization = initialization,
             )
 
         # Generate i18nmergeall
@@ -129,20 +148,21 @@
                 [('%smergeall'% self.name,
                   'z3c.recipe.i18n.i18nmergeall',
                   'main')],
-                ws, self.options['executable'], 'bin',
+                ws, self.options['executable'],
+                self.buildout['buildout']['bin-directory'],
                 extra_paths = [this_loc],
                 arguments = arguments,
             ))
 
         # Generate i18nstats
-
         arguments = ['%sstats'% self.name, '-l', output]
         generated.extend(
             zc.buildout.easy_install.scripts(
                 [('%sstats'% self.name,
                   'z3c.recipe.i18n.i18nstats',
                   'main')],
-                ws, self.options['executable'], 'bin',
+                ws, self.options['executable'],
+                self.buildout['buildout']['bin-directory'],
                 extra_paths = [this_loc],
                 arguments = arguments,
             ))



More information about the Checkins mailing list