1+ import os
2+ import json
3+ import pytz
4+ from glob import glob
5+ from dateutil import parser
6+ from datetime import datetime , timedelta
7+ from git import Repo , PushInfo
8+
9+ folder = os .path .dirname (os .path .abspath (__file__ ))
10+
11+ repo = Repo (folder + '/../../mission' )
12+ mission_origin = repo .remote ('origin' )
13+
14+
15+ def get_sorted_catalogs ():
16+ all = glob (folder + '/../../mission/sessions/*' )
17+
18+ all_sorted = []
19+ for i in all :
20+ if i .split ('/' )[- 1 ].isdigit ():
21+ all_sorted .append (i )
22+
23+ return sorted (all_sorted , key = lambda x : int (x .split ('/' )[- 1 ]))
24+
25+
26+ sessions = get_sorted_catalogs ()
27+
28+ last_non_auto = None
29+
30+ for i in sessions :
31+ session_nr = int (i .split ('/' )[- 1 ])
32+ file = os .path .join (i , 'data.json' )
33+ if not os .path .isfile (file ):
34+ continue
35+
36+ data = json .loads (open (file ).read ())['Session' ]
37+ if data ['short_description' ] == 'Automatic session.' :
38+ continue
39+
40+ date = parser .parse (data ['start_time_iso_with_zone' ]).astimezone (pytz .utc ).replace (tzinfo = None )
41+
42+ if date < datetime .utcnow ():
43+ last_non_auto = [session_nr , data ]
44+ continue
45+
46+ # `date` is next upcoming non-auto session
47+ start = last_non_auto [0 ]
48+ end = session_nr
49+ print "Generating telemetry download between session {} and {}!" .format (start , end )
50+
51+ template = None
52+
53+ if data ['short_description' ].find ("Power cycle EPS A." ) != - 1 :
54+ print "Power cycle A!"
55+ template = 'power_cycle_A.template'
56+ elif data ['short_description' ].find ("Power cycle EPS B." ) != - 1 :
57+ print "Power cycle B!"
58+ template = 'power_cycle_B.template'
59+ elif data ['short_description' ].find ("Telemetry download." ) != - 1 :
60+ print "!!!!!! Just telemetry download! Make sure this is correct !!!!!!"
61+ template = 'telemetry_download.template'
62+ else :
63+ print "!!!!!! Incorrect description !!!!!!"
64+ exit (1 )
65+
66+ template = folder + '/tasklist_templates/' + template
67+ output = folder + '/../../mission/sessions/' + str (end ) + '/tasklist.py'
68+ os .system ("python2 " + folder + "/generate_tasklist.py -s {} -e {} -t {} -o {}" .format (start , end , template , output ))
69+
70+ branch = 'session_' + str (end )
71+ repo .git .checkout ('master' )
72+ mission_origin .pull (rebase = True )
73+ repo .git .checkout ('HEAD' , b = branch )
74+ repo .git .add ('sessions/' + str (end ) + '/tasklist.py' )
75+ repo .git .commit (m = branch )
76+ repo .git .push ('--set-upstream' , 'origin' , branch )
77+
78+ exit (0 )
79+
0 commit comments