summaryrefslogtreecommitdiff
path: root/firehose_call.py
diff options
context:
space:
mode:
authorWill Holland <william.holland@codethink.co.uk>2015-09-09 15:53:20 +0100
committerWill Holland <william.holland@codethink.co.uk>2015-09-09 15:53:20 +0100
commit809f54fb56662d2c0adc30eff921f7457229c264 (patch)
tree662940fcb58da1515206e4dbb5e7fc783adfbab5 /firehose_call.py
parentc0a0d9713e9d9e1da8bd15fdad3d948a4728665c (diff)
downloadbuildslave-scripts-809f54fb56662d2c0adc30eff921f7457229c264.tar.gz
Add python script to call firehose
This calls firehose with a set of config files taken from firehose_mappings.py determined by a repo given to firehose_call.py as an argument
Diffstat (limited to 'firehose_call.py')
-rw-r--r--firehose_call.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/firehose_call.py b/firehose_call.py
new file mode 100644
index 0000000..c9ec3f5
--- /dev/null
+++ b/firehose_call.py
@@ -0,0 +1,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)