+ def verify(self, no_touch=False):
+ """
+ Checks if this is an autoinstall, throws an exception if there
+ are problems. If ``no_touch`` is ``True``, it will not attempt
+ edit the installation.
+ """
+ with util.ChangeDirectory(self.location):
+ has_git = os.path.isdir(".git")
+ has_wizard = os.path.isdir(".wizard")
+ if not has_wizard and os.path.isdir(".scripts"):
+ # LEGACY
+ os.symlink(".scripts", ".wizard")
+ has_wizard = True
+ if not has_git and has_wizard:
+ raise CorruptedAutoinstallError(self.location)
+ elif has_git and not has_wizard:
+ raise AlreadyVersionedError(self.location)
+ # LEGACY
+ elif not has_git and not has_wizard:
+ if os.path.isfile(".scripts-version"):
+ raise NotMigratedError(self.location)
+ else:
+ raise NotAutoinstallError(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.wizard_tag, '--')
+ except shell.CallError:
+ raise NoTagError(self.app_version.wizard_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.wizard_tag):
+ # Causes remastering
+ raise InconsistentWizardTagError(self.app_version.wizard_tag)
+ parent = repo_rev_parse(self.app_version.wizard_tag)
+ merge_base = shell.safeCall("git", "merge-base", parent, "HEAD", strip=True)
+ if merge_base != parent:
+ # Causes remastering
+ raise HeadNotDescendantError(self.app_version.wizard_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.detectVersion()
+ if not str(real) == self.app_version.pristine_tag.partition('-')[2]:
+ raise VersionMismatchError(real, self.version)
+
+ @chdir_to_location
+ def detectVersion(self):
+ """
+ Returns the real version, based on filesystem, of install.
+
+ Throws a :class:`VersionDetectionError` if we couldn't figure out
+ what the real version was.
+ """
+ real = self.application.detectVersion(self)
+ if not real:
+ raise VersionDetectionError
+ return real