Use version as the tag name
[invirt/packages/invirt-dev.git] / invirtibuilder
index ca12398..d152b18 100755 (executable)
@@ -93,13 +93,13 @@ def sanitizeVersion(version):
     """Sanitize a Debian package version for use as a git tag.
 
     This function strips the epoch from the version number and
     """Sanitize a Debian package version for use as a git tag.
 
     This function strips the epoch from the version number and
-    replaces any tildes with periods."""
-    if v.debian_version:
+    replaces any tildes with underscores."""
+    if version.debian_version:
         v = '%s-%s' % (version.upstream_version,
                        version.debian_version)
     else:
         v = version.upstream_version
         v = '%s-%s' % (version.upstream_version,
                        version.debian_version)
     else:
         v = version.upstream_version
-    return v.replace('~', '.')
+    return v.replace('~', '_')
 
 
 def aptCopy(package, commit, dst_pocket, src_pocket):
 
 
 def aptCopy(package, commit, dst_pocket, src_pocket):
@@ -152,7 +152,8 @@ def tagSubmodule(pocket, package, commit, principal, version, env):
                                         principal))
 
         c.captureOutput(
                                         principal))
 
         c.captureOutput(
-            ['git', 'tag', '-m', tag_msg, commit],
+            ['git', 'tag', '-m', tag_msg, '--', sanitizeVersion(version),
+             commit],
             env=env,
             cwd=b.getRepo(package))
 
             env=env,
             cwd=b.getRepo(package))
 
@@ -166,13 +167,19 @@ def updateSubmoduleBranch(pocket, package, commit):
 
 def uploadBuild(pocket, workdir):
     """Upload all build products in the work directory."""
 
 def uploadBuild(pocket, workdir):
     """Upload all build products in the work directory."""
+    force = config.build.pockets[pocket].get('allow_backtracking', False)
     apt = b.pocketToApt(pocket)
     for changes in glob.glob(os.path.join(workdir, '*.changes')):
     apt = b.pocketToApt(pocket)
     for changes in glob.glob(os.path.join(workdir, '*.changes')):
-        c.captureOutput(['reprepro-env',
-                       '--ignore=wrongdistribution',
-                       'include',
-                       apt,
-                       changes])
+        upload = ['reprepro-env', '--ignore=wrongdistribution',
+                  'include', apt, changes]
+        try:
+            c.captureOutput(upload)
+        except subprocess.CalledProcessError, e:
+            if not force:
+                raise
+            package = deb822.Changes(open(changes).read())['Binary']
+            c.captureOutput(['reprepro-env', 'remove', apt, package])
+            c.captureOutput(upload)
 
 
 def updateSuperproject(pocket, package, commit, principal, version, env):
 
 
 def updateSuperproject(pocket, package, commit, principal, version, env):
@@ -283,19 +290,31 @@ def build():
             b.ensureValidPackage(package)
             db.commit = commit = b.canonicalize_commit(package, commit)
             src = b.validateBuild(pocket, package, commit)
             b.ensureValidPackage(package)
             db.commit = commit = b.canonicalize_commit(package, commit)
             src = b.validateBuild(pocket, package, commit)
-
-            db.version = str(b.getVersion(package, commit))
+            version = b.getVersion(package, commit)
+            db.version = str(version)
             b.runHook('pre-build', [str(db.build_id), db.pocket, db.package,
                                     db.commit, db.principal, db.version, str(db.inserted_at)])
 
             b.runHook('pre-build', [str(db.build_id), db.pocket, db.package,
                                     db.commit, db.principal, db.version, str(db.inserted_at)])
 
+            env = dict(os.environ)
+            env['GIT_COMMITTER_NAME'] = config.build.tagger.name
+            env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email
+
             # If validateBuild returns something other than True, then
             # it means we should copy from that pocket to our pocket.
             #
             # (If the validation failed, validateBuild would have
             # raised an exception)
             if src != True:
             # If validateBuild returns something other than True, then
             # it means we should copy from that pocket to our pocket.
             #
             # (If the validation failed, validateBuild would have
             # raised an exception)
             if src != True:
+                # TODO: cut out this code duplication
+                db.failed_stage = 'tagging submodule before copying package'
+                tagSubmodule(pocket, package, commit, principal, version, env)
+                db.failed_stage = 'updating submodule branches before copying package'
+                updateSubmoduleBranch(pocket, package, commit)
+                db.failed_stage = 'updating superproject before copying package'
+                updateSuperproject(pocket, package, commit, principal, version, env)
                 db.failed_stage = 'copying package from another pocket'
                 aptCopy(package, commit, pocket, src)
                 db.failed_stage = 'copying package from another pocket'
                 aptCopy(package, commit, pocket, src)
+                
             # If we can't copy the package from somewhere, but
             # validateBuild didn't raise an exception, then we need to
             # do the build ourselves
             # If we can't copy the package from somewhere, but
             # validateBuild didn't raise an exception, then we need to
             # do the build ourselves
@@ -327,14 +346,8 @@ def build():
                         for log in glob.glob(os.path.join(workdir, 'build-*.log')):
                             os.copy(log, logdir)
 
                         for log in glob.glob(os.path.join(workdir, 'build-*.log')):
                             os.copy(log, logdir)
 
-                    db.failed_stage = 'processing metadata'
-                    env = dict(os.environ)
-                    env['GIT_COMMITTER_NAME'] = config.build.tagger.name
-                    env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email
-                    version = b.getVersion(package, commit)
-
                     db.failed_stage = 'tagging submodule'
                     db.failed_stage = 'tagging submodule'
-                    tagSubmodule(pocket, package, principal, version, env)
+                    tagSubmodule(pocket, package, commit, principal, version, env)
                     db.failed_stage = 'updating submodule branches'
                     updateSubmoduleBranch(pocket, package, commit)
                     db.failed_stage = 'updating superproject'
                     db.failed_stage = 'updating submodule branches'
                     updateSubmoduleBranch(pocket, package, commit)
                     db.failed_stage = 'updating superproject'