1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)
|