summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-10-05 16:08:18 -0400
committerColin Walters <walters@verbum.org>2010-10-05 16:08:18 -0400
commitd85946d3e787ce675f9d485ac8d966e3763c9a13 (patch)
tree9703a9ddd8545a77a345a1c8612bd3f52a4cef11
parent1c907887574b423485b2df0e130673dc09c6aca5 (diff)
downloadrpmci-d85946d3e787ce675f9d485ac8d966e3763c9a13.tar.gz
rpmci-d85946d3e787ce675f9d485ac8d966e3763c9a13.tar.xz
rpmci-d85946d3e787ce675f9d485ac8d966e3763c9a13.zip
rpmci-spec-vcs: initial work
-rwxr-xr-xrpmci-spec-vcs20
-rw-r--r--rpmci/lame_vcs_abstraction.py18
-rw-r--r--rpmci/rpmci_spec_vcs_main.py77
3 files changed, 109 insertions, 6 deletions
diff --git a/rpmci-spec-vcs b/rpmci-spec-vcs
new file mode 100755
index 0000000..338e121
--- /dev/null
+++ b/rpmci-spec-vcs
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+# rpmci-spec-vcs:
+# Operations on spec files
+#
+# 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
+
+if os.path.isdir('.git'):
+ sys.path.insert(0, os.getcwd())
+
+import rpmci
+from rpmci.rpmci_spec_vcs_main import main
+
+if __name__ == '__main__':
+ main()
diff --git a/rpmci/lame_vcs_abstraction.py b/rpmci/lame_vcs_abstraction.py
index 2d5314e..f798d67 100644
--- a/rpmci/lame_vcs_abstraction.py
+++ b/rpmci/lame_vcs_abstraction.py
@@ -59,7 +59,7 @@ class Vcs(object):
"""Update directory from the latest upstream"""
raise Exception("not implemented")
- def export_archive(self, prefix, target_filename):
+ def export_archive(self, commit_id, prefix, target_filename):
"""Export a tarball with minimal (or no) version control data."""
raise Exception("not implemented")
@@ -68,6 +68,9 @@ class Vcs(object):
def get_id(self):
raise Exception("not implemented")
+
+ def resolve_id(self):
+ raise Exception("not implemented")
def get_abbreviated_id(self):
raise Exception("not implemented")
@@ -117,13 +120,12 @@ class GitVcs(Vcs):
assert self._dir is not None
return self._vcs_exec_async(['git', 'pull', '-r'], logfile, on_exited)
- def export_archive(self, prefix, target_filename, logfile):
+ def export_archive(self, commit_id, prefix, target_filename, log_output_stream):
if not prefix.endswith('/'):
prefix += '/'
- args = ['git', 'archive', '--format=tar', '--prefix=%s' % (prefix,), 'HEAD']
+ args = ['git', 'archive', '--format=tar', '--prefix=%s' % (prefix,), commit_id]
logging.info("Synchronously executing: %r" % (args, ))
- log_f = open(logfile, 'w')
- gitproc = subprocess.Popen(args, cwd=src_directory, stdout=subprocess.PIPE, stderr=log_f)
+ gitproc = subprocess.Popen(args, cwd=src_directory, stdout=subprocess.PIPE, stderr=log_output_stream)
if target_filename.endswith('.bz2'):
zipbin = 'bzip2'
elif target_filename.endswith('.gz'):
@@ -133,7 +135,7 @@ 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_f)
+ zipproc = subprocess.Popen(args, cwd=src_directory, stdout=f, stdin=gitproc.stdout, stderr=log_output_stream)
zipproc.wait()
def get_commit_as_patch(self, commitid, destfile):
@@ -145,6 +147,10 @@ class GitVcs(Vcs):
def get_id(self):
output = self._vcs_exec_sync_log_error(['git', 'show', '--format=%H'])
return output.split('\n')[0]
+
+ def resolve_id(self, commit_id):
+ output = self._vcs_exec_sync_log_error(['git', 'rev-parse', commit_id])
+ return output.split('\n')[0]
def get_abbreviated_id(self):
full_id = self.get_id()
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)