+ """
+ Represents a deployment of an autoinstall, e.g. directory in a user's
+ web_scripts that has ``.scripts`` directory or ``.scripts-version``
+ file in it. Supply ``version`` with an :class:`ApplicationVersion` only if
+ you were reading from the :term:`versions store` and care about
+ speed (data from there can be stale).
+ """
+ #: Absolute path to the deployment
+ location = None
+ def __init__(self, location, version=None):
+ self.location = os.path.abspath(location)
+ self._app_version = version
+ # some cache variables
+ self._read_cache = {}
+ self._log = None
+ def read(self, file, force = False):
+ """
+ Reads a file's contents, possibly from cache unless ``force``
+ is ``True``.
+ """
+ if force or file not in self._read_cache:
+ f = open(os.path.join(self.location, file))
+ self._read_cache[file] = f.read()
+ f.close()
+ return self._read_cache[file]
+ def extract(self):
+ """
+ Extracts all the values of all variables from deployment.
+ These variables may be used for parametrizing generic parent
+ commits and include things such as database access credentials
+ and local configuration.
+ """
+ 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 :attr:`location`.
+ """
+ return self.application.parametrize(self, dir)
+ def prepareConfig(self):
+ """
+ Edits files in the deployment such that any user-specific configuration
+ is replaced with generic WIZARD_* variables.
+ """
+ return self.application.prepareConfig(self)
+ def updateVersion(self, version):
+ """
+ Update the version of this deployment.
+
+ This method will update the version of this deployment in memory
+ and on disk. It doesn't actually do an upgrade. The version
+ string you pass here should have ``-scripts`` as a suffix.
+ """
+ self._app_version = self.application.makeVersion(version)
+ f = open(os.path.join(self.scripts_dir, 'version'), 'w')
+ f.write(self.application.name + '-' + version + "\n")
+ f.close()
+ def scriptsifyVersion(self):
+ """
+ Converts from ``v1.0`` to ``v1.0-scripts``; use at end of migration.
+
+ .. note::
+
+ This makes the assumption that a migration will be to
+ a ``-scripts`` tag and not a ``-scripts2`` tag. If you botch
+ migration, blow away the tag and try again.
+ """
+ self.updateVersion(self.app_version.scripts_tag)
+ @property
+ def migrated(self):
+ """Whether or not the autoinstalls has been migrated."""
+ return os.path.isdir(self.scripts_dir)
+ @property
+ def scripts_dir(self):
+ """The absolute path of the ``.scripts`` directory."""
+ return os.path.join(self.location, '.scripts')
+ @property
+ def old_version_file(self):
+ """
+ The absolute path of either ``.scripts-version`` (for unmigrated
+ installs) or ``.scripts/version``.
+
+ .. note::
+
+ Use of this is discouraged for migrated installs.
+ """
+ if self.migrated:
+ return os.path.join(self.scripts_dir, 'old-version')
+ else:
+ return os.path.join(self.location, '.scripts-version')