7 if isinstance(val, str):
10 return '(?:' + '|'.join(map(expand_re, val)) + ')'
12 def filename_regex_extractor(f):
14 This is a decorator to apply to functions that take a name and return
15 (filename, RegexObject) tuples. It converts it into a function
16 that takes a name and returns another function (the actual extractor)
17 which takes a deployment and returns the value of the extracted variable.
19 The regular expression requires a very specific form, essentially ()()()
20 (with the second subgroup being the value we care about), so that we can
21 reuse the regex for other things.
23 Its Haskell-style type signature would be::
25 (String -> (Filename, Regex)) -> (String -> (Deployment -> String))
27 For convenience purposes, we also accept [Filename], in which case
28 we use the first entry (index 0). Passing an empty list is invalid.
32 if not isinstance(file, str):
36 contents = deployment.read(file) # cached
39 match = regex.search(contents)
40 if not match: return None
41 # assumes that the second match is the one we want.
46 def filename_regex_substitution(f):
48 This is a decorator to apply to functions that take a name and return
49 (filename, RegexObject) tuples. It converts it into a function
50 that takes a name and returns another function (that does substitution)
51 which takes a deployment and modifies its files to replace explicit
52 values with their generic WIZARD_* equivalents. The final function returns
53 the number of replacements made.
55 The regular expression requires a very specific form, essentially ()()()
56 (with the second subgroup being the value to be replaced).
58 Its Haskell-style type signature would be::
60 (String -> ([Filename], Regex)) -> (String -> (Deployment -> IO Int))
62 For convenience purposes, we also accept Filename, in which case it is treated
63 as a single item list.
67 if isinstance(files, str):
70 base = deployment.location
73 file = os.path.join(base, file)
75 contents = open(file, "r").read()
76 contents, n = regex.subn("\\1" + key + "\\3", contents)
78 open(file, "w").write(contents)
85 class Error(wizard.Error):
86 """Generic error class for this module."""
89 class UpgradeFailure(Error):
90 """Upgrade script failed."""
91 #: String details of failure (possibly stdout or stderr output)
93 def __init__(self, details):
94 self.details = details
98 ERROR: Upgrade script failed, details:
102 class BackupFailure(Error):
103 """Backup script failed."""
104 #: String details of failure
106 def __init__(self, details):
107 self.details = details
111 ERROR: Backup script failed, details:
115 class RestoreFailure(Error):
116 """Restore script failed."""
117 #: String details of failure
119 def __init__(self, details):
120 self.details = details
124 ERROR: Restore script failed, details: