diff options
author | Colin Walters <walters@verbum.org> | 2010-10-06 13:40:45 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-10-06 13:40:45 -0400 |
commit | 759d66c95624cbb03e58f95066f7ba6b178d29c0 (patch) | |
tree | a61cb7cbcbacbaa64b52543b9d89940d45e9e183 | |
parent | d85946d3e787ce675f9d485ac8d966e3763c9a13 (diff) | |
download | rpmci-759d66c95624cbb03e58f95066f7ba6b178d29c0.tar.gz rpmci-759d66c95624cbb03e58f95066f7ba6b178d29c0.tar.xz rpmci-759d66c95624cbb03e58f95066f7ba6b178d29c0.zip |
rpmci-spec-vcs: Make set-revision look plausible
-rw-r--r-- | rpmci/lame_vcs_abstraction.py | 10 | ||||
-rw-r--r-- | rpmci/rpmci_spec_vcs_main.py | 25 |
2 files changed, 25 insertions, 10 deletions
diff --git a/rpmci/lame_vcs_abstraction.py b/rpmci/lame_vcs_abstraction.py index f798d67..d1ca557 100644 --- a/rpmci/lame_vcs_abstraction.py +++ b/rpmci/lame_vcs_abstraction.py @@ -121,11 +121,12 @@ class GitVcs(Vcs): return self._vcs_exec_async(['git', 'pull', '-r'], logfile, on_exited) def export_archive(self, commit_id, prefix, target_filename, log_output_stream): + assert self._dir is not None if not prefix.endswith('/'): prefix += '/' args = ['git', 'archive', '--format=tar', '--prefix=%s' % (prefix,), commit_id] logging.info("Synchronously executing: %r" % (args, )) - gitproc = subprocess.Popen(args, cwd=src_directory, stdout=subprocess.PIPE, stderr=log_output_stream) + gitproc = subprocess.Popen(args, cwd=self._dir, stdout=subprocess.PIPE, stderr=log_output_stream) if target_filename.endswith('.bz2'): zipbin = 'bzip2' elif target_filename.endswith('.gz'): @@ -135,27 +136,32 @@ class GitVcs(Vcs): args = [zipbin, '-c'] logging.info("Synchronously executing: %r" % (args, )) f = open(target_filename, 'w') - zipproc = subprocess.Popen(args, cwd=src_directory, stdout=f, stdin=gitproc.stdout, stderr=log_output_stream) + zipproc = subprocess.Popen(args, cwd=self._dir, stdout=f, stdin=gitproc.stdout, stderr=log_output_stream) zipproc.wait() def get_commit_as_patch(self, commitid, destfile): + assert self._dir is not None output = self._vcs_exec_sync_log_error(['git', 'format-patch', '--stdout', commitid + '^..' + commitid]) f = open(destfile, 'w') f.write(output) f.close() def get_id(self): + assert self._dir is not None output = self._vcs_exec_sync_log_error(['git', 'show', '--format=%H']) return output.split('\n')[0] def resolve_id(self, commit_id): + assert self._dir is not None output = self._vcs_exec_sync_log_error(['git', 'rev-parse', commit_id]) return output.split('\n')[0] def get_abbreviated_id(self): + assert self._dir is not None full_id = self.get_id() return full_id[0:8] def get_commit_summary_as_filename(self, commitid): + assert self._dir is not None output = self._vcs_exec_sync_log_error(['git', 'show', '--format=%f', commitid]) return output.split('\n')[0] diff --git a/rpmci/rpmci_spec_vcs_main.py b/rpmci/rpmci_spec_vcs_main.py index 935de5b..1e0ded2 100644 --- a/rpmci/rpmci_spec_vcs_main.py +++ b/rpmci/rpmci_spec_vcs_main.py @@ -14,6 +14,7 @@ import shutil import optparse import logging import subprocess +import datetime import glib import gobject @@ -35,7 +36,8 @@ def _get_spec(options): def set_revision(options, args): if len(args) == 0: - options.print_usage(): + print "usage: set-revision COMMITID" + options.print_usage() sys.exit(1) revision = args[0] @@ -45,31 +47,38 @@ def set_revision(options, args): spec_obj = spec.Spec(specpath) vcs_url = spec_obj.get_vcs() - vcs = lame_vcs_abstraction.VCS.new_from_spec(vcs_url) + vcs = lame_vcs_abstraction.Vcs.new_from_spec(vcs_url) + vcs.set_directory(vcsdir) resolved_id = vcs.resolve_id(revision) - prefix = '%s-%s' % (spec.get_name(), resolved_id) + name = os.path.basename(spec_obj.get_name()) + prefix = '%s-%s' % (name, resolved_id) target_file = os.path.join(os.getcwd(), '%s.tar.bz2' % (prefix, )) - vcs.export_archive(resolved_id, prefix, target_file, sys.stdout) + vcs.export_archive(resolved_id, prefix, target_file, sys.stderr) - + now = datetime.datetime.now() + alphatag = "%s%s%s" % (now.strftime("%Y%m%d"), vcs.vcstype, resolved_id) + spec_obj.increment_release_snapshot(alphatag) + spec_obj.set_source(prefix, os.path.basename(target_file)) + spec_obj.save() def main(): glib.threads_init() opts = optparse.OptionParser("usage: %prog [options] ACTION [args]") opts.add_option('', '--debug', action='store_true', help="Print verbose debugging") - opts.add_option('', '--vcsdir', action='store', help="Path to repository (defaults to current dir)") + opts.add_option('', '--vcsdir', action='store', dest="vcsdir", + default=None, help="Path to repository (defaults to current dir)") (options, args) = opts.parse_args() - if len(args) != 1: + if len(args) < 1: opts.print_usage() sys.exit(1) verb = args[0] if verb == 'set-revision': - set_revision(opts, args[1:]) + set_revision(options, args[1:]) else: opts.print_usage() sys.exit(1) |