Fixes to invirtibuilder for case of missing package in super-repo, missing
[invirt/packages/invirt-dev.git] / python / invirt / builder.py
index 2e2e405..8e24faf 100644 (file)
@@ -19,10 +19,27 @@ _REPO_DIR = '/srv/git'
 _LOG_DIR = '/var/log/invirt/builds'
 _HOOKS_DIR = '/usr/share/invirt-dev/build-hooks'
 
+_DEFAULT_DISTRIBUTION = 'hardy'
+
 
 class InvalidBuild(ValueError):
     pass
 
+_DISTRO_TO_SUFFIX = {
+    'etch': '~debian4.0',
+    'lenny': '~debian5.0',
+    'squeeze': '~debian6.0',
+
+    'hardy': '~ubuntu8.04',
+    'lucid': '~ubuntu10.04',
+    'maverick': '~ubuntu10.10',
+    'natty': '~ubuntu11.04',
+    'oneiric': '~ubuntu11.10',
+    'precise': '~ubuntu12.04',
+    }
+
+def distroToSuffix(distro):
+    return _DISTRO_TO_SUFFIX.get(distro, '~'+distro)
 
 def getRepo(package):
     """Return the path to the git repo for a given package."""
@@ -59,6 +76,9 @@ def pocketToApt(pocket):
     """Map a pocket in the configuration to an apt repo pocket."""
     return getattr(getattr(config.build.pockets, pocket), 'apt', pocket)
 
+def pocketToDistro(pocket):
+    """Map a pocket in the configuration to the distro we build for."""
+    return getattr(getattr(config.build.pockets, pocket), 'distro', _DEFAULT_DISTRIBUTION)
 
 def getGitFile(package, ref, path):
     """Return the contents of a path from a git ref in a package."""
@@ -86,6 +106,13 @@ def getVersion(package, ref):
     """Get the version of a given package at a particular ref."""
     return getChangelog(package, ref).get_version()
 
+def pocketExists(pocket, repo):
+    branch = pocketToGit(pocket)
+    try:
+        c.captureOutput(['git', 'rev-parse', branch], cwd=repo)
+    except subprocess.CalledProcessError:
+        return False
+    return True
 
 def validateBuild(pocket, package, commit):
     """Given the parameters of a new build, validate that build.
@@ -116,6 +143,7 @@ def validateBuild(pocket, package, commit):
     ensureValidPackage(package)
     package_repo = getRepo(package)
     new_version = getVersion(package, commit)
+    new_distro = pocketToDistro(pocket)
 
     ret = True
 
@@ -132,8 +160,12 @@ def validateBuild(pocket, package, commit):
             continue
 
         current_version = getVersion(package, b)
+        current_distro = pocketToDistro(p)
+
+        # NB: Neither current_version nor new_version will have the
+        # distro-specific prefix.
 
-        if current_version == new_version:
+        if current_version == new_version and current_distro == new_distro:
             if current_commit == commit:
                 ret = p
             else:
@@ -142,6 +174,9 @@ def validateBuild(pocket, package, commit):
                                    (new_version, package, p, current_commit))
 
     if not config.build.pockets[pocket].get('allow_backtracking', False):
+        if not pocketExists(pocket, package_repo):
+            return True
+
         branch = pocketToGit(pocket)
         current_version = getVersion(package, branch)
         if new_version <= current_version: