blob: 6a473e787557fb1f1c11f914bbf447c4e4cea8d6 [file] [log] [blame]
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +01001#!/usr/bin/python
2
3from mixpanel import Mixpanel
4
5import sys
6import getpass
7import socket
8import subprocess
9import os
10
11from os.path import expanduser
12home = expanduser("~")
13
14try:
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)
57except Exception,e:
58 print str(e)
59 pass