import os
+import subprocess
from debian_bundle import changelog
-from debian_bundle import deb822
import invirt.common as c
from invirt.config import structs as config
_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."""
"""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."""
"""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.
ensureValidPackage(package)
package_repo = getRepo(package)
new_version = getVersion(package, commit)
+ new_distro = pocketToDistro(pocket)
ret = True
continue
b = pocketToGit(p)
- current_commit = c.captureOutput(['git', 'rev-parse', b],
- cwd=package_repo).strip()
+ try:
+ current_commit = c.captureOutput(['git', 'rev-parse', b],
+ cwd=package_repo).strip()
+ except subprocess.CalledProcessError:
+ # Guess we haven't created this pocket yet
+ continue
+
current_version = getVersion(package, b)
+ current_distro = pocketToDistro(p)
- if current_version == new_version:
+ # NB: Neither current_version nor new_version will have the
+ # distro-specific prefix.
+
+ if current_version == new_version and current_distro == new_distro:
if current_commit == commit:
ret = p
else:
(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:
# Almost by definition, A is a fast-forward of B if B..A is
# empty
- if not c.captureOutput(['git', 'rev-list', '%s..%s' % (commit, branch)],
- cwd=package_repo):
+ if c.captureOutput(['git', 'rev-list', '%s..%s' % (commit, branch)],
+ cwd=package_repo):
raise InvalidBuild('New commit %s of %s is not a fast-forward of'
'commit currently in pocket %s' %
(commit, package, pocket))