ostbuild: Lots more

This commit is contained in:
Colin Walters 2012-05-01 16:45:34 -04:00
parent b845e0a2bb
commit 938f4eaf44
10 changed files with 81 additions and 9 deletions

View File

@ -34,6 +34,7 @@ pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/builtin_resolve.py \
src/ostbuild/pyostbuild/builtin_modify_snapshot.py \
src/ostbuild/pyostbuild/builtin_tree_to_bin.py \
src/ostbuild/pyostbuild/builtin_shadow_repo_init.py \
src/ostbuild/pyostbuild/builtin_status.py \
src/ostbuild/pyostbuild/builtins.py \
src/ostbuild/pyostbuild/filemonitor.py \

View File

@ -63,7 +63,9 @@ class OstbuildBranchPrefix(builtins.Builtin):
fatal("Mismatched name %r in snapshot" % (name, ))
target['name'] = name.replace(orig_prefix, args.newprefix)
db.store(forked_snapshot)
path = db.store(forked_snapshot)
log("Saved %r" % (path, ))
run_sync(['ostbuild', 'prefix', args.newprefix],
log_initiation=False, log_success=False)

View File

@ -95,7 +95,7 @@ class OstbuildBuildComponents(builtins.Builtin):
else:
log("No previous build for '%s' found" % (name, ))
checkoutdir = os.path.join(self.workdir, 'src')
checkoutdir = os.path.join(self.workdir, 'checkouts')
component_src = os.path.join(checkoutdir, basename)
run_sync(['ostbuild', 'checkout', '--snapshot=' + self.snapshot_path,
'--clean', '--overwrite', basename], cwd=checkoutdir)

View File

@ -72,8 +72,10 @@ class OstbuildCheckout(builtins.Builtin):
if is_dirty:
# Kind of a hack, but...
if os.path.lexists(checkoutdir):
if os.path.islink(checkoutdir):
os.unlink(checkoutdir)
if args.overwrite and os.path.isdir(checkoutdir):
shutil.rmtree(checkoutdir)
os.symlink(uri, checkoutdir)
else:
vcs.get_vcs_checkout(self.mirrordir, keytype, uri, checkoutdir,

View File

@ -139,7 +139,6 @@ class OstbuildResolve(builtins.Builtin):
self.args = args
self.parse_config()
self.repo = ostbuildrc.get_key('repo')
self.manifest = json.load(open(args.manifest))
self.prefix = self.manifest['prefix']

View File

@ -0,0 +1,52 @@
# Copyright (C) 2012 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import os,sys,stat,subprocess,tempfile,re,shutil
from StringIO import StringIO
import json
import select,time
import argparse
from . import builtins
from .ostbuildlog import log, fatal
from . import fileutil
from .subprocess_helpers import run_sync, run_sync_get_output
class OstbuildShadowRepoInit(builtins.Builtin):
name = "shadow-repo-init"
short_description = "Initialize a user-mode shadow repository for /ostree/repo"
def __init__(self):
builtins.Builtin.__init__(self)
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
args = parser.parse_args(argv)
self.parse_config()
path = os.path.join(self.workdir, 'shadow-repo')
fileutil.ensure_dir(path)
if os.path.isdir(os.path.join(path, 'objects')):
log("Shadow repository '%s' appears to already exist" % (path, ))
else:
run_sync(['ostree', '--repo=' + path, 'init', '--archive'])
run_sync(['ostree', '--repo=' + path, 'config', 'set', 'core.parent', '/ostree/repo'])
log("Created shadow repository: %s" % (path, ))
builtins.register(OstbuildShadowRepoInit)

View File

@ -169,10 +169,21 @@ class Builtin(object):
self._bin_snapshots = self.create_db('bin-snapshot')
return self._bin_snapshots
def _init_repo(self):
repo = ostbuildrc.get_key('repo', default=None)
if repo is not None:
self.repo = repo
else:
shadow_path = os.path.join(self.workdir, 'shadow-repo')
if os.path.isdir(shadow_path):
self.repo = shadow_path
else:
fatal("No repository configured, and shadow-repo not found. Use \"ostbuild shadow-repo-init\" to make one")
def parse_snapshot(self, prefix, path):
if prefix is not None:
self.prefix = prefix
self.repo = ostbuildrc.get_key('repo')
self._init_repo()
if path is None:
latest_path = self.get_src_snapshot_db().get_latest_path()
if latest_path is None:
@ -183,12 +194,12 @@ class Builtin(object):
self.snapshot = json.load(open(self.snapshot_path))
src_ver = self.snapshot['00ostree-src-snapshot-version']
if src_ver != 0:
fatal("Unhandled 00ostree-src-snapshot-version \"%d\", expected 0", src_ver)
fatal("Unhandled 00ostree-src-snapshot-version \"%d\", expected 0" % (src_ver, ))
def parse_bin_snapshot(self, prefix, path):
if prefix is not None:
self.prefix = prefix
self.repo = ostbuildrc.get_key('repo')
self._init_repo()
if path is None:
latest_path = self.get_bin_snapshot_db().get_latest_path()
if latest_path is None:
@ -199,7 +210,7 @@ class Builtin(object):
self.bin_snapshot = json.load(open(self.bin_snapshot_path))
bin_ver = self.bin_snapshot['00ostree-bin-snapshot-version']
if bin_ver != 0:
fatal("Unhandled 00ostree-bin-snapshot-version \"%d\", expected 0", bin_ver)
fatal("Unhandled 00ostree-bin-snapshot-version \"%d\", expected 0" % (bin_ver, ))
def execute(self, args):
raise NotImplementedError()

View File

@ -97,6 +97,7 @@ class JsonDB(object):
if latest is not None:
if digest == latest[2]:
os.unlink(tmppath)
return latest[3]
latest_version = (latest[0], latest[1])
else:

View File

@ -34,6 +34,7 @@ from . import builtin_prefix
from . import builtin_resolve
from . import builtin_modify_snapshot
from . import builtin_tree_to_bin
from . import builtin_shadow_repo_init
from . import builtin_status
def usage(ecode):

View File

@ -51,17 +51,20 @@ def get_vcs_checkout(mirrordir, keytype, uri, dest, branch, overwrite=True):
tmp_dest = dest + '.tmp'
if os.path.isdir(tmp_dest):
shutil.rmtree(tmp_dest)
if os.path.islink(dest):
os.unlink(dest)
if os.path.isdir(dest):
if overwrite:
shutil.rmtree(dest)
else:
tmp_dest = dest
if not os.path.isdir(tmp_dest):
run_sync(['git', 'clone', '-q',
run_sync(['git', 'clone', '-q', '--origin', 'localmirror',
'--no-checkout', module_mirror, tmp_dest])
else:
run_sync(['git', 'fetch'], cwd=tmp_dest)
run_sync(['git', 'checkout', '-q', branch], cwd=tmp_dest)
run_sync(['git', 'remote', 'add', 'upstream', uri], cwd=tmp_dest)
run_sync(['git', 'submodule', 'init'], cwd=tmp_dest)
have_submodules = _fixup_submodule_references(mirrordir, tmp_dest)
if have_submodules: