+
+ def verify(self):
+ """
+ Checks if this is an autoinstall, throws an exception if there
+ are problems.
+ """
+ with util.ChangeDirectory(self.location):
+ has_git = os.path.isdir(".git")
+ has_scripts = os.path.isdir(".scripts")
+ if not has_git and has_scripts:
+ raise CorruptedAutoinstallError(self.location)
+ elif has_git and not has_scripts:
+ raise AlreadyVersionedError(self.location)
+ elif not has_git and not has_scripts:
+ if os.path.isfile(".scripts-version"):
+ raise NotMigratedError(self.location)
+
+ def verifyTag(self, srv_path):
+ """
+ Checks if the purported version has a corresponding tag
+ in the upstream repository.
+ """
+ repo = self.application.repository(srv_path)
+ try:
+ shell.eval("git", "--git-dir", repo, "rev-parse", self.app_version.scripts_tag, '--')
+ except shell.CallError:
+ raise NoTagError(self.app_version.scripts_tag)
+
+ def verifyGit(self, srv_path):
+ """
+ Checks if the autoinstall's Git repository makes sense,
+ checking if the tag is parseable and corresponds to
+ a real application, and if the tag in this repository
+ corresponds to the one in the remote repository.
+ """
+ with util.ChangeDirectory(self.location):
+ repo = self.application.repository(srv_path)
+ def repo_rev_parse(tag):
+ return shell.eval("git", "--git-dir", repo, "rev-parse", tag)
+ def self_rev_parse(tag):
+ try:
+ return shell.safeCall("git", "rev-parse", tag, strip=True)
+ except shell.CallError:
+ raise NoLocalTagError(tag)
+ def compare_tags(tag):
+ return repo_rev_parse(tag) == self_rev_parse(tag)
+ if not compare_tags(self.app_version.pristine_tag):
+ raise InconsistentPristineTagError(self.app_version.pristine_tag)
+ if not compare_tags(self.app_version.scripts_tag):
+ raise InconsistentScriptsTagError(self.app_version.scripts_tag)
+ parent = repo_rev_parse(self.app_version.scripts_tag)
+ merge_base = shell.safeCall("git", "merge-base", parent, "HEAD", strip=True)
+ if merge_base != parent:
+ raise HeadNotDescendantError(self.app_version.scripts_tag)
+
+ def verifyConfigured(self):
+ """
+ Checks if the autoinstall is configured running.
+ """
+ if not self.configured:
+ raise NotConfiguredError(self.location)
+
+ @chdir_to_location
+ def verifyVersion(self):
+ """
+ Checks if our version and the version number recorded in a file
+ are consistent.
+ """
+ real = self.application.detectVersion(self)
+ if not real:
+ raise VersionDetectionError
+ elif not str(real) == self.app_version.pristine_tag.partition('-')[2]:
+ raise VersionMismatchError(real, self.version)
+
+ @property
+ @chdir_to_location
+ def configured(self):
+ """Whether or not an autoinstall has been configured/installed for use."""
+ return self.application.checkConfig(self)
+ @property
+ def migrated(self):
+ """Whether or not the autoinstalls has been migrated."""
+ return os.path.isdir(self.scripts_dir)