summaryrefslogtreecommitdiffstats
path: root/rpmci/rpmci_inject_rebuild_main.py
blob: eb1373f23895f975944a1f53fe7d1dfa3432212b (plain)
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
#!/usr/bin/python

# rpmci_inject_rebuild_main.py:
# Implementation of rpmci-inject-rebuild
#
# 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
from ConfigParser import SafeConfigParser
import subprocess
import datetime

import glib
import gobject
import gio

from . import artifact
from . import msgqueue

def inject_rebuild(options, config, module):
    artifact_set = artifact.ArtifactSet.from_config(config)
    target = None
    for target_iter in artifact_set.get_build_targets():
        if target_iter.module == module:
            target = target_iter
            break
    if target is None:
        raise SystemExit("Couldn't find module %r in configuration" % (module, ))
    upstream_url = artifact.upstream_vcs_url_for_build_target(config, target)

    vcs_msgqueue_dir = config.get('VCS', 'msgqueue')
    vcs_msgqueue = msgqueue.MessageQueue(vcs_msgqueue_dir)
    msg = msgqueue.Message(None, {'type': 'update'}, {'url': upstream_url})
    vcs_msgqueue.append(msg)
    print "Wrote %s" % (msg.ident, )

def main():
    glib.threads_init()

    opts = optparse.OptionParser("usage: %prog [options] ACTION [args]")
    opts.add_option('-c', '--config', dest='config', help="Path to configuration file")
    opts.add_option('', '--debug', action='store_true', help="Print verbose debugging")

    (options, args) = opts.parse_args()

    if options.config is None:
        print "Must specify --config"
        sys.exit(1)

    config = SafeConfigParser({'home': os.environ['HOME']})
    config.read(options.config)
    level = logging.DEBUG if options.debug else logging.INFO
    logging.basicConfig(stream=sys.stderr, level=level)

    if len(args) < 1:
        print "Must specify module to be rebuilt"
        opts.print_usage()
        sys.exit(1)

    module = args[0]

    inject_rebuild(options, config, module)

    sys.exit(0)