summaryrefslogtreecommitdiff
path: root/cdistvm
blob: 55b9e517aad34b86ba5a5a7c9e0bc0f42335e523 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python

import argparse
import subprocess
import shlex
import time
import os
import tempfile
import shutil

class Error(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return self.value
    def __repr__(self):
        return str(self)

parser = argparse.ArgumentParser()
parser.add_argument('command')
parser.add_argument('-p', '--project', help='project name')
parser.add_argument('--minor', help='minor version number bump', action='store_true')
parser.add_argument('--micro', help='micro version number bump', action='store_true')
parser.add_argument('--major', help='major version to return with latest', type=int)
parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
parser.add_argument('-o', '--output', help='output directory', default='.')
parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
parser.add_argument('-t', '--target', help='target')
parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
parser.add_argument('-w', '--work', help='override default work directory')
parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
args = parser.parse_args()

cdist_cmd = 'cdist %s -t host ' % args.command
if args.project is not None:
    cdist_cmd += '-p %s ' % args.project
if args.minor is True:
    cdist_cmd += '--minor '
if args.micro is True:
    cdist_cmd += '--micro '
if args.major is True:
    cdist_cmd += '--major '
if args.checkout is not None:
    cdist_cmd += '--checkout %s ' % args.checkout
if args.output is not None:
    cdist_cmd += '--output cdistvm '
if args.quiet is True:
    cdist_cmd += '--quiet '
if args.keep is True:
    cdist_cmd += '--keep '
if args.debug is True:
    cdist_cmd += '--debug '
if args.work is not None:
    cdist_cmd += '--work %s ' % args.work
if args.git_prefix is not None:
    cdist_cmd += '--git-prefix %s ' % args.git_prefix

def command(c):
    r = os.system(c)
    if (r >> 8):
        raise Error('command %s failed' % c)

ports = { 'fedora-22-32': 2000,
          'fedora-22-64': 2001,
          'fedora-23-32': 2002,
          'fedora-23-64': 2003,
          'arch-64': 2004,
          'fedora-24-32': 2005,
          'fedora-24-64': 2006,
          'fedora-25-32': 2007,
          'fedora-25-64': 2008,
        }

vbox = subprocess.Popen('vboxheadless --startvm %s' % args.target, shell=True)

ok = False
while ok == False:
    time.sleep(10)
    try:
        command('ssh -p %d carl@localhost "rm -rf cdistvm /var/tmp/tmp*"' % ports[args.target])
        ok = True
    except Error as e:
        print('Ignoring: %s' % e)
        pass

command('ssh -p %d carl@localhost %s' % (ports[args.target], cdist_cmd))
if args.command in ['package', 'doxygen', 'manual', 'changelog', 'pot']:
    tmp = tempfile.mkdtemp()
    command('scp -r -P %d carl@localhost:cdistvm/* %s/' % (ports[args.target], tmp))
    command('scp -r %s/* %s/' % (tmp, args.output))
    shutil.rmtree(tmp)

try:
    command('ssh -p %d carl@localhost "sudo /sbin/poweroff"' % ports[args.target])
except Error:
    pass

print("wait for vm to terminate...")
vbox.wait()