summaryrefslogtreecommitdiff
path: root/firehose_call.py
blob: c9ec3f52292b54ebed4a79da6999b2255e2698c1 (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
# takes a repo as $1 and calls firehose for each config the repo appears in

#cd /home/williamholland/src/firehose
#./firehose.sh examples/*.yaml --log=/dev/stdout --log-level=debug

FIREHOSE_DIR = '/home/williamholland/src/firehose'
LOGFILE = '/home/williamholland/orchestration/trigger_log'
LOGFILE = './foo'

from firehose_mappings import mapping

log_file = open(LOGFILE,'a')

def log(msg):
    ''' write message to log file with timestamp and script name '''
    import datetime
    global log_file
    dt = str(datetime.datetime.now()).split('.')[0]
    log_file.write("[%s] Firehose Trigger: %s\n" % (dt, msg))

def firehose_cmd(config,loglevel='debug',log='/dev/stdout'):
    ''' take list of firehose configs filename and return a firehose command with that
    config '''
    cmd = [
            "./firehose.sh",
            "--log-level=%s" % loglevel,
            "--log=%s" % log,
        ] + config
    return cmd

if __name__ == '__main__':
    import sys, subprocess, os

    try:
        repo = sys.argv[1]
    except:
        log("Called without being given a repo")
        print "firehose_map.py requires a repo argument"
        exit(1)

    try:
        configs = mapping[repo]
    except:
        log("Repo unknown: %s" % repo)
        exit(1)

    os.chdir(FIREHOSE_DIR)
    exit_val = subprocess.call(firehose_cmd(configs))
    if not exit_val:
        log("Successful")
        exit(exit_val)
    else:
        log("Unsuccessful")
        exit(exit_val)