Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | from mixpanel import Mixpanel |
| 4 | |
| 5 | import sys |
| 6 | import getpass |
| 7 | import socket |
| 8 | import subprocess |
| 9 | import os |
| 10 | |
| 11 | from os.path import expanduser |
| 12 | home = expanduser("~") |
| 13 | |
| 14 | try: |
| 15 | mp = Mixpanel("7d5ca3b3ff870dbeda89c9d5af59e9e9") |
| 16 | hostname = socket.gethostname() |
| 17 | |
| 18 | context = {} |
| 19 | context['debian-version'] = open('/etc/debian_version').read().strip() |
| 20 | |
| 21 | |
| 22 | os.chdir(home+'/cord/orchestration/xos') |
| 23 | p = subprocess.Popen(['git','rev-parse','HEAD'], stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE) |
| 24 | |
| 25 | git_hash,err = p.communicate() |
| 26 | |
| 27 | context['last-commit'] = git_hash |
| 28 | |
| 29 | config = open(home + '/cord/build/config/cord_in_a_box.yml').read().splitlines() |
| 30 | for l in config: |
| 31 | if 'cord_profile:' in l: |
| 32 | context['profile'] = l.rstrip().rsplit(' ')[-1].replace("'","") |
| 33 | |
| 34 | context['user'] = getpass.getuser() |
| 35 | |
| 36 | name = '' |
| 37 | idx=0 |
| 38 | lst = hostname.split('.') |
| 39 | lst.reverse() |
| 40 | for i in lst: |
| 41 | name='.'.join([name,i]).lstrip('.') |
| 42 | |
| 43 | context['level-%d'%idx] = name |
| 44 | idx+=1 |
| 45 | |
| 46 | if (len(sys.argv)>2 and 'finish' in sys.argv[2]): |
| 47 | logfile = open(home + '/cord/install.out').read().splitlines() |
| 48 | snapshot = logfile[-20:] |
| 49 | snapshot = filter(lambda x:x, snapshot) |
| 50 | context['snapshot'] = snapshot |
| 51 | |
| 52 | try: |
| 53 | build_id = open('/tmp/cord-build').read().rstrip() |
| 54 | except: |
| 55 | build_id = context['user'] + name |
| 56 | mp.track(build_id, sys.argv[1], context) |
| 57 | except Exception,e: |
| 58 | print str(e) |
| 59 | pass |