from wizard.app import php
def make_filename_regex(var):
- return 'LocalSettings.php', re.compile('^\$(' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M)
+ return 'LocalSettings.php', re.compile('^(\$' + re.escape(var) + r'''\s*=\s*)(.*)(;)$''', re.M)
make_extractor = app.filename_regex_extractor(make_filename_regex)
class Application(deploy.Application):
+ parametrized_files = ['LocalSettings.php', 'php.ini']
@property
def extractors(self):
if not self._extractors:
except util.NoOperatorInfo:
pass
# naive merge algorithm:
- sh.call("git", "merge", "-m", message, "scripts/master")
+ # sh.call("git", "merge", "-m", message, "scripts/master")
# crazy merge algorithm:
- #original_scripts_tag = d # something here
- #sh.call("git", "checkout", original_scripts_tag)
+ original_scripts_tag = "v" + str(d.version)
+ sh.call("git", "checkout", original_scripts_tag)
+ d.parametrize(temp_wc_dir)
except shell.CallError:
print temp_wc_dir
raise MergeFailed
import fileinput
import dateutil.parser
import distutils.version
+import tempfile
import wizard
from wizard import log
if you don't mind having stale data; generally
'wizard list' and commands that operate of of the
versions store will set this."""
- self.location = location
+ self.location = os.path.realpath(location)
self._app_version = version
# some cache variables
self._read_cache = {}
def extract(self):
"""Extracts all the values of all variables from deployment."""
return self.application.extract(self)
+ def parametrize(self, dir):
+ """Edits files in dir to replace WIZARD_* variables with literal
+ instances. This is used for constructing virtual merge bases, and
+ as such dir will generally not equal self.location."""
+ return self.application.parametrize(self, dir)
def updateVersion(self, version):
"""Bump the version of this deployment.
class Application(object):
"""Represents the generic notion of an application, i.e.
mediawiki or phpbb."""
+ parametrized_files = []
def __init__(self, name):
self.name = name
self.versions = {}
# cache variables
self._extractors = {}
+ self._parametrizers = {}
@property
def repository(self):
"""Returns the Git repository that would contain this application."""
for k,extractor in self.extractors.items():
result[k] = extractor(deployment)
return result
+ def parametrize(self, deployment, dir):
+ """Takes a generic source checkout at dir and parametrizes
+ it according to the values of deployment."""
+ variables = deployment.extract()
+ for file in self.parametrized_files:
+ fullpath = os.path.join(dir, file)
+ f = open(fullpath, "r")
+ contents = f.read()
+ f.close()
+ for key, value in variables.items():
+ if value is None: continue
+ contents = contents.replace(key, value)
+ tmp = tempfile.NamedTemporaryFile(delete=False)
+ tmp.write(contents)
+ tmp.close()
+ os.rename(tmp.name, fullpath)
@property
def extractors(self):
return {}