[Checkins] SVN: z3c.recipe.usercrontab/trunk/ Added migration code for pre-0.4 entries without a BUILDOUT variable
Reinout van Rees
reinout at vanrees.org
Mon Jun 15 10:59:38 EDT 2009
Log message for revision 101009:
Added migration code for pre-0.4 entries without a BUILDOUT variable
Changed:
U z3c.recipe.usercrontab/trunk/CHANGES.txt
U z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/README.txt
U z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/usercrontab.py
-=-
Modified: z3c.recipe.usercrontab/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.usercrontab/trunk/CHANGES.txt 2009-06-15 13:52:36 UTC (rev 101008)
+++ z3c.recipe.usercrontab/trunk/CHANGES.txt 2009-06-15 14:59:37 UTC (rev 101009)
@@ -4,6 +4,9 @@
0.5 (unreleased)
----------------
+* Added migration code for pre-0.4 entries without a BUILDOUT variable.
+ [reinout]
+
* Added extra blank line in front of "BUILDOUT=..." variable to allow for
better readability. [reinout]
Modified: z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/README.txt
===================================================================
--- z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/README.txt 2009-06-15 13:52:36 UTC (rev 101008)
+++ z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/README.txt 2009-06-15 14:59:37 UTC (rev 101009)
@@ -174,7 +174,27 @@
BLA=bla
@reboot echo "mailto example, my/path"
+The environment variable is mainly used for grouping items per buildout. Now
+for some upgrade testing. Pre 0.4 versions of this recipe did not group
+entries per buildout. We'll add an entry without such a "grouping environment
+variable". First the start situation:
+ >>> c.crontab=['WARNING=The entries below were generated by buildout, do not modify',
+ ... '@reboot echo nothing happens']
+ >>> print c # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+ WARNING=The entries below were generated by buildout, do not modify
+ @reboot echo nothing happens
+
+Now we add a similar entry, but with a BUILDOUT environment variable. The old
+item should now be inside the environment, without a double:
+
+ >>> c.add_entry('@reboot echo nothing happens', BUILDOUT="my/buildout")
+ >>> print c # doctest: +REPORT_NDIFF
+ WARNING=The entries below were generated by buildout, do not modify
+ BUILDOUT=my/buildout
+ @reboot echo nothing happens
+
+
Read/write crontab methods
--------------------------
@@ -319,3 +339,4 @@
Running uninstall recipe.
foo: WARNING: Did not find a crontab-entry during uninstall; please check manually if everything was removed correctly
<BLANKLINE>
+
Modified: z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/usercrontab.py
===================================================================
--- z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/usercrontab.py 2009-06-15 13:52:36 UTC (rev 101008)
+++ z3c.recipe.usercrontab/trunk/src/z3c/recipe/usercrontab/usercrontab.py 2009-06-15 14:59:37 UTC (rev 101009)
@@ -105,7 +105,7 @@
def __repr__(self):
return "\n".join(self.crontab)
- def add_entry(self, line, **env):
+ def add_entry(self, entry, **env):
"""
Add an entry to a crontab, if kw's are set, set environment args
to be like that.
@@ -114,14 +114,31 @@
new_crontab = []
done = False
- for l in self.crontab:
- m = env_re.match(l)
- if m:
- cur_env[unescape_string(m.group(1))] = unescape_string(
- m.group(2))
- new_crontab.append(l)
+ for line in self.crontab:
+ match = env_re.match(line)
+ if match:
+ # We have an environment statement ('MAILTO=something')
+ env_key = match.group(1)
+ env_value = match.group(2)
+ cur_env[unescape_string(env_key)] = unescape_string(env_value)
+ if (entry == line and
+ 'BUILDOUT' in env and
+ 'BUILDOUT' not in cur_env):
+ # Possibly line we have to migrate post-0.3.
+ temp_env = cur_env.copy()
+ temp_env['BUILDOUT'] = env['BUILDOUT']
+ if dict_pmatch(env, temp_env):
+ # Don't copy the entry, it will be added in the proper
+ # environment later.
+ pass
+ else:
+ # Normal behaviour, just copy the line.
+ new_crontab.append(line)
+ else:
+ # Normal behaviour, just copy the line.
+ new_crontab.append(line)
if not done and dict_pmatch(env, cur_env):
- new_crontab.append(line)
+ new_crontab.append(entry)
done = True
if (not done):
@@ -129,7 +146,7 @@
if k not in cur_env or cur_env[k] != v:
new_crontab.append('%s=%s' % (escape_string(k),
escape_string(v)))
- new_crontab.append(line)
+ new_crontab.append(entry)
self.crontab = new_crontab
More information about the Checkins
mailing list