diff options
Diffstat (limited to 'rpmci/rpmci_spec_vcs_main.py')
-rw-r--r-- | rpmci/rpmci_spec_vcs_main.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/rpmci/rpmci_spec_vcs_main.py b/rpmci/rpmci_spec_vcs_main.py new file mode 100644 index 0000000..935de5b --- /dev/null +++ b/rpmci/rpmci_spec_vcs_main.py @@ -0,0 +1,77 @@ +#!/usr/bin/python + +# rpmci_spec_vcs_main.py: +# Implementation of rpmci-spec-vcs +# +# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php) +# Copyright (C) 2010 Red Hat, Inc. +# Written by Colin Walters <walters@verbum.org> + +import os +import sys +import time +import shutil +import optparse +import logging +import subprocess + +import glib +import gobject +import gio + +from . import lame_vcs_abstraction +from . import spec + +def _get_spec(options): + dirpath = os.getcwd() + specpath = None + for filename in os.listdir(dirpath): + if filename.endswith('.spec'): + specpath = os.path.join(dirpath, filename) + break + if specpath is None: + raise SystemExit("Couldn't find .spec file in %r" % (dirpath, )) + return specpath + +def set_revision(options, args): + if len(args) == 0: + options.print_usage(): + sys.exit(1) + + revision = args[0] + vcsdir = options.vcsdir or os.getcwd() + + specpath = _get_spec(options) + spec_obj = spec.Spec(specpath) + vcs_url = spec_obj.get_vcs() + + vcs = lame_vcs_abstraction.VCS.new_from_spec(vcs_url) + resolved_id = vcs.resolve_id(revision) + prefix = '%s-%s' % (spec.get_name(), resolved_id) + target_file = os.path.join(os.getcwd(), '%s.tar.bz2' % (prefix, )) + vcs.export_archive(resolved_id, prefix, target_file, sys.stdout) + + + +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)") + + (options, args) = opts.parse_args() + + if len(args) != 1: + opts.print_usage() + sys.exit(1) + + verb = args[0] + + if verb == 'set-revision': + set_revision(opts, args[1:]) + else: + opts.print_usage() + sys.exit(1) + + sys.exit(0) |