-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcapture_now.py
More file actions
129 lines (105 loc) · 3.61 KB
/
capture_now.py
File metadata and controls
129 lines (105 loc) · 3.61 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
'''
capture_now.py:
Manual entry point of the capturing system.
Argv[1]: {Current Semester}
Argv[2]: {Current Course}
Argv[3]: {Duration in sec}
'''
import sys
import os
import signal
import json
import time
from datetime import datetime
from pathlib import Path
import utils
import config
import init_setup
import lec_cap, bb_cap, wb_cap, comp_cap
import subprocess
NOT_SET = 0
DISABLED = 1
LECTURE = 2
WHITEBOARD = 3
BLACKBOARD = 4
COMPUTER = 5
RECORDING_FOLDER = str(Path.home()) + '/recordings/'
def signal_handler(signal, frame):
'''Force quit when detected Ctrl+C'''
print('Exiting...')
os._exit(0)
signal.signal(signal.SIGINT, signal_handler)
def main():
args = sys.argv[1:]
if len(args) != 3:
utils.log('ERR ', 'Invalid Arguments')
return
capture(args)
return
def capture(args):
'''captures according to config file'''
if not config.load_all_config() or not config.is_config_valid():
utils.log('WARN', 'Hardware not configured. Running init setup GUI...')
init_setup.main()
utils.log('WARN', 'Please restart the program.')
exit(0)
then = datetime.utcnow()
os.chdir(os.path.dirname(__file__))
utils.log('INFO', 'Preparing saving path...')
time_str = then.strftime("%m-%d-%y--%H-%M-%S")
save_path = RECORDING_FOLDER + 'readyToUpload/' + args[0] + '/' + args[1] + '/' + time_str + '/'
if not os.path.exists(save_path):
os.makedirs(save_path)
os.makedirs(save_path+'whiteboard/')
os.makedirs(save_path+'blackboard/')
os.makedirs(save_path+'computer/')
elif not os.path.exists(save_path+'whiteboard/'):
os.makedirs(save_path+'whiteboard/')
elif not os.path.exists(save_path+'blackboard/'):
os.makedirs(save_path+'blackboard/')
elif not os.path.exists(save_path+'computer/'):
os.makedirs(save_path+'computer/')
utils.log('INFO', 'Saving to ' + save_path)
utils.log('INFO', 'Start capturing ' + str(args))
conf = config.load_all_config()
wb_count = 0
com_count = 0
for value in conf.values():
if str(value) is str(WHITEBOARD):
wb_count += 1
elif str(value) is str(COMPUTER):
com_count += 1
utils.writeINFO(save_path, wb_count, com_count, args)
st = None
for device, type in conf.items():
utils.log('INFO', 'Triggerring ' + device)
type = int(type)
if type == LECTURE:
utils.log('INFO', ' LECTURE')
st = lec_cap.trigger_cap(device, args, save_path)
elif type == WHITEBOARD:
utils.log('INFO', ' WHITEBOARD')
wb_cap.trigger_cap(device, args, save_path)
elif type == BLACKBOARD:
utils.log('INFO', ' BLACKBOARD')
bb_cap.trigger_cap(device, args, save_path)
elif type == COMPUTER:
utils.log('INFO', ' COMPUTER')
comp_cap.trigger_cap(device, args, save_path)
# if st:
# _, err = st.communicate()
# utils.log('INFO', 'LecCap Error: '+str(err))
while (datetime.utcnow() - then).total_seconds() < args[2] + 1:
utils.print_progress((datetime.utcnow() - then).total_seconds(), args[2])
pass
print()
utils.log('INFO', "Capturing successful, uploading all lectures")
with open('./logs/upload.log', 'a+') as f:
pu = subprocess.Popen("./scripts/uploadAll.sh", stdout=f, stderr=f, shell=True, cwd=str(os.getcwd()))
utils.log('INFO', "Uploading...")
_, er = pu.communicate()
utils.log('INFO', "Return code: "+str(pu.returncode))
return '0'
if __name__ == '__main__':
main()