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/python/invirt/builder.py

    r2834 r3028  
    2929    return os.path.join(_REPO_DIR, 'invirt/packages', '%s.git' % package)
    3030
     31def ensureValidRepo(package):
     32    """Perform some basic sanity checks that the requested repo is in a
     33    subdirectory of _REPO_DIR/invirt/packages.  This prevents weirdness
     34    such as submitting a package like '../prod/...git'.  Also ensures that
     35    the repo exists."""
     36    # TODO: this might be easier just to regex
     37    repo = os.path.abspath(getRepo(package))
     38    parent_dir = os.path.dirname(repo)
     39    prefix = os.path.join(_REPO_DIR, 'invirt/packages')
     40    if not parent_dir.startswith(prefix):
     41        raise InvalidBuild('Invalid package name %s' % package)
     42    elif not os.path.exists(repo):
     43        raise InvalidBuild('Nonexisting package %s' % package)
    3144
    3245def pocketToGit(pocket):
     
    4356    """Return the contents of a path from a git ref in a package."""
    4457    return c.captureOutput(['git', 'cat-file', 'blob', '%s:%s' % (ref, path)],
    45                          cwd=getRepo(package))
     58                           cwd=getRepo(package))
    4659
    4760
     
    8699    it returns True.
    87100    """
     101    ensureValidRepo(package)
    88102    package_repo = getRepo(package)
    89103    new_version = getVersion(package, commit)
     
    97111        b = pocketToGit(p)
    98112        current_commit = c.captureOutput(['git', 'rev-parse', b],
    99                                        cwd=package_repo)
     113                                         cwd=package_repo).strip()
    100114        current_version = getVersion(package, b)
    101115
     
    104118                ret = p
    105119            else:
    106                 raise InvalidBuild('Version %s of %s already available in '
     120                raise InvalidBuild('Version %s of %s already available is in '
    107121                                   'pocket %s from commit %s' %
    108122                                   (new_version, package, p, current_commit))
    109123
    110     if config.build.pockets[pocket].get('allow_backtracking', False):
     124    if not config.build.pockets[pocket].get('allow_backtracking', False):
    111125        branch = pocketToGit(pocket)
    112126        current_version = getVersion(package, branch)
Note: See TracChangeset for help on using the changeset viewer.