summaryrefslogtreecommitdiffstats
path: root/rpmbuild-remote.py
blob: 9b887f322ab0372b1ae4b8bec699388e35db5396 (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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from iniparse import INIConfig
import logging
import paramiko
import optparse
import sys
import os

LOG = logging.getLogger('rpmbuild-remote')
LOG.addHandler(logging.StreamHandler())

def get_parser():
    """Return a commandline parser"""
    parser = optparse.OptionParser(usage="%prog [options]... <files>...")
    home = os.path.expanduser("~")
    parser.set_conflict_handler("resolve")
    parser.add_option("-c", "--config",
            action="store", type="string", dest="config",
            default=os.path.join(home,".rpmbuild-remote"),
            help="Configuration file to use for the build. "
                 "[Default: ~/.rpmbuild-remote")
    parser.add_option("-s", "--system",
            action="store", type="string", dest="system",
            help="The remote machine to use (defined in config file)")
    parser.add_option("-u", "--user",
            action="store", type="string", dest="user",
            default=os.getlogin(),
            help="The username on the remote system [Default: current user]")
    parser.add_option("-h", "--host",
            action="store", type="string", dest="host",
            help="The hostname/IP of the remote system")
    parser.add_option("-p", "--port",
            action="store", type="int", dest="port",
            default=21,
            help="The port to use on the remote system [Default: 21")
    parser.add_option("-d", "--dest",
            action="store", type="string", dest="dest",
            default=os.path.join(home, "rpmbuild-remote"),
            help="Directory to place resulting files "
                 "[Default: ~/rpmbuild-remote/]")
    parser.add_option("-m", "--mock",
            action="store", type="string", dest="mock",
            default="",
            help="Use mock (only applies to SRPM files) [Default: No mock "
                 "builds (uses rpmbuild --rebuild otherwise)]")
    return parser

def main():
    parser = get_parser()
    opts, args = parser.parse_args()
    jobs = []
    for arg in args:
        ext = os.path.splitext(arg)[1]
        if ext == '.srpm' or ext == '.spec':
            jobs.append([arg])
        elif ext not in ('.gz', '.tgz', '.bz2', '.patch'):
            LOG.warning("Uncommon source extension %s for file %s. "
                        "Please double check files." % (ext, arg))
        elif len(jobs) == 0:
            LOG.error("Source file given without spec file.")
            sys.exit(1)
        else:
            jobs[-1].append(arg)

if __name__ == '__main__':
    main()