Ignore:
Timestamp:
Jul 5, 2010, 2:01:45 AM (14 years ago)
Author:
gdb
Message:

Make invirtibuilder work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-dev/invirtibuilder

    r2838 r3028  
    3030
    3131import contextlib
     32import glob
    3233import os
    3334import re
    3435import shutil
    3536import subprocess
     37import tempfile
     38import traceback
    3639
    3740import pyinotify
    3841
     42from debian_bundle import deb822
     43
    3944import invirt.builder as b
     45import invirt.common as c
    4046from invirt import database
     47from invirt.config import structs as config
    4148
    4249
     
    5259    """
    5360    return deb822.Deb822.iter_paragraphs(
    54         getGitFile(package, ref, 'debian/control').split('\n'))
     61        b.getGitFile(package, ref, 'debian/control').split('\n'))
    5562
    5663
     
    7279def getDscName(package, ref):
    7380    """Return the .dsc file that will be generated for this package."""
    74     v = getVersion(package, ref)
     81    v = b.getVersion(package, ref)
    7582    if v.debian_version:
    7683        v_str = '%s-%s' % (v.upstream_version,
     
    96103
    97104
    98 def aptCopy(packages, dst_pocket, src_pocket):
     105def aptCopy(package, commit, dst_pocket, src_pocket):
    99106    """Copy a package from one pocket to another."""
    100107    binaries = getBinaries(package, commit)
    101     cpatureOutput(['reprepro-env', 'copy',
    102                    b.pocketToApt(dst_pocket),
    103                    b.pocketToApt(src_pocket),
    104                    package] + binaries)
     108    c.captureOutput(['reprepro-env', 'copy',
     109                     b.pocketToApt(dst_pocket),
     110                     b.pocketToApt(src_pocket),
     111                     package] + binaries)
    105112
    106113
     
    123130
    124131
    125 def tagSubmodule(pocket, package, ref, principal):
     132def tagSubmodule(pocket, package, principal, version, env):
    126133    """Tag a new version of a submodule.
    127134
     
    139146    """
    140147    if not config.build.pockets[pocket].get('allow_backtracking', False):
    141         env = dict(os.environ)
    142148        branch = b.pocketToGit(pocket)
    143         version = b.getVersion(package, ref)
    144 
    145         env['GIT_COMMITTER_NAME'] = config.build.tagger.name
    146         env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email
    147149        tag_msg = ('Tag %s of %s\n\n'
    148150                   'Requested by %s' % (version.full_version,
     
    160162    branch = b.pocketToGit(pocket)
    161163    c.captureOutput(
    162         ['git', 'update-ref', 'refs/heads/%s' % branch, ref])
     164        ['git', 'update-ref', 'refs/heads/%s' % branch, ref], cwd=b.getRepo(package))
    163165
    164166
     
    168170    for changes in glob.glob(os.path.join(workdir, '*.changes')):
    169171        c.captureOutput(['reprepro-env',
     172                       '--ignore=wrongdistribution',
    170173                       'include',
    171                        '--ignore=wrongdistribution',
    172174                       apt,
    173175                       changes])
    174176
    175177
    176 def updateSuperproject(pocket, package, commit, principal):
     178def updateSuperproject(pocket, package, commit, principal, version, env):
    177179    """Update the superproject.
    178180
     
    186188    branch = b.pocketToGit(pocket)
    187189    tree = c.captureOutput(['git', 'ls-tree', branch],
    188                          cwd=superproject)
     190                           cwd=superproject).strip()
    189191
    190192    new_tree = re.compile(
    191193        r'^(160000 commit )[0-9a-f]*(\t%s)$' % package, re.M).sub(
    192         r'\1%s\2' % commit,
     194        r'\g<1>%s\g<2>' % commit,
    193195        tree)
    194196
    195     new_tree_id = c.captureOutput(['git', 'mktree'],
    196                                 cwd=superproject,
    197                                 stdin_str=new_tree)
     197    new_tree_id = c.captureOutput(['git', 'mktree', '--missing'],
     198                                  cwd=superproject,
     199                                  stdin_str=new_tree).strip()
    198200
    199201    commit_msg = ('Update %s to version %s\n\n'
     
    202204                                       principal))
    203205    new_commit = c.captureOutput(
    204         ['git', 'commit-tree', new_tree_hash, '-p', branch],
     206        ['git', 'commit-tree', new_tree_id, '-p', branch],
    205207        cwd=superproject,
    206208        env=env,
    207         stdin_str=commit_msg)
     209        stdin_str=commit_msg).strip()
    208210
    209211    c.captureOutput(
     
    211213        cwd=superproject)
    212214
     215
     216def makeReadable(workdir):
     217    os.chmod(workdir, 0755)
    213218
    214219@contextlib.contextmanager
     
    228233            ['git', 'archive',
    229234             '--remote=file://%s' % b.getRepo(package),
    230              '--prefix=%s' % package,
     235             '--prefix=%s/' % package,
    231236             commit,
    232237             ],
     
    278283        db.principal = principal
    279284        database.session.save_or_update(db)
    280         database.commit()
    281 
    282         database.begin()
     285        database.session.commit()
     286
     287        database.session.begin()
    283288
    284289        try:
    285290            db.failed_stage = 'validating job'
    286             src = validateBuild(pocket, package, commit)
     291            src = b.validateBuild(pocket, package, commit)
     292            # Don't expand the commit in the DB until we're sure the user
     293            # isn't trying to be tricky.
     294            db.commit = commit = c.captureOutput(['git', 'rev-parse', commit],
     295                                                 cwd=b.getRepo(package)).strip()
    287296
    288297            db.version = str(b.getVersion(package, commit))
     
    295304            if src != True:
    296305                db.failed_stage = 'copying package from another pocket'
    297                 aptCopy(packages, pocket, src)
     306                aptCopy(package, commit, pocket, src)
    298307            # If we can't copy the package from somewhere, but
    299308            # validateBuild didn't raise an exception, then we need to
     
    320329                        sbuildAll(package, commit, workdir)
    321330                    finally:
    322                         logdir = os.path.join(b._LOG_DIR, db.build_id)
     331                        logdir = os.path.join(b._LOG_DIR, str(db.build_id))
    323332                        if not os.path.exists(logdir):
    324333                            os.makedirs(logdir)
     
    326335                        for log in glob.glob(os.path.join(workdir, '*.build')):
    327336                            os.copy2(log, logdir)
     337
     338                    db.failed_stage = 'processing metadata'
     339                    env = dict(os.environ)
     340                    env['GIT_COMMITTER_NAME'] = config.build.tagger.name
     341                    env['GIT_COMMITTER_EMAIL'] = config.build.tagger.email
     342                    version = b.getVersion(package, commit)
     343
    328344                    db.failed_stage = 'tagging submodule'
    329                     tagSubmodule(pocket, package, commit, principal)
     345                    tagSubmodule(pocket, package, principal, version, env)
    330346                    db.failed_stage = 'updating submodule branches'
    331347                    updateSubmoduleBranch(pocket, package, commit)
    332348                    db.failed_stage = 'updating superproject'
    333                     updateSuperproject(pocket, package, commit, principal)
     349                    updateSuperproject(pocket, package, commit, principal, version, env)
     350                    db.failed_stage = 'relaxing permissions on workdir'
     351                    makeReadable(workdir)
    334352                    db.failed_stage = 'uploading packages to apt repo'
    335353                    uploadBuild(pocket, workdir)
Note: See TracChangeset for help on using the changeset viewer.