-class Application(object):
- """Represents an application, i.e. mediawiki or phpbb."""
- #: String name of the application
- name = None
- #: Dictionary of version strings to :class:`ApplicationVersion`.
- #: See also :meth:`makeVersion`.
- versions = None
- #: List of files that need to be modified when parametrizing.
- #: This is a class-wide constant, and should not normally be modified.
- parametrized_files = []
- def __init__(self, name):
- self.name = name
- self.versions = {}
- # cache variables
- self._extractors = {}
- self._substitutions = {}
- def repository(self, srv_path):
- """
- Returns the Git repository that would contain this application.
- ``srv_path`` corresponds to ``options.srv_path`` from the global baton.
- """
- repo = os.path.join(srv_path, self.name + ".git")
- if not os.path.isdir(repo):
- repo = os.path.join(srv_path, self.name, ".git")
- if not os.path.isdir(repo):
- raise NoRepositoryError(self.name)
- return repo
- def makeVersion(self, version):
- """
- Creates or retrieves the :class:`ApplicationVersion` singleton for the
- specified version.
- """
- if version not in self.versions:
- self.versions[version] = ApplicationVersion(distutils.version.LooseVersion(version), self)
- return self.versions[version]
- def extract(self, deployment):
- """Extracts wizard variables from a deployment."""
- result = {}
- 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)
- try:
- contents = open(fullpath, "r").read()
- except IOError:
- continue
- for key, value in variables.items():
- if value is None: continue
- contents = contents.replace(key, value)
- tmp = tempfile.NamedTemporaryFile(delete=False)
- tmp.write(contents)
- os.rename(tmp.name, fullpath)
- def prepareConfig(self, deployment):
- """
- Takes a deployment and replaces any explicit instances
- of a configuration variable with generic WIZARD_* constants.
- There is a sane default implementation built on substitutions;
- you can override this method to provide arbitrary extra
- behavior.
- """
- for key, subst in self.substitutions.items():
- subs = subst(deployment)
- if not subs and key not in self.deprecated_keys:
- logging.warning("No substitutions for %s" % key)
- def install(self, options):
- """
- Run for 'wizard configure' (and, by proxy, 'wizard install')
- to configure an application.
- """
- raise NotImplemented
- def upgrade(self, options):
- """
- Run for 'wizard upgrade' to upgrade database schemas and other
- non-versioned data in an application.
- """
- raise NotImplemented
- @property
- def extractors(self):