-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.py
66 lines (52 loc) · 1.9 KB
/
events.py
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
import time
import logging
import os
from natsort import natsorted
class EventHandler():
def __init__(self,photos,videos,test):
self.photos = photos
self.videos = videos
self.test = test
def new_record_name(self,suffix,type):
event = self._event_name()
return self._concat_name(event,suffix,type)
def strip(self,event_path):
return event_path.split("/")[-1]
def new_test_record_name(self,suffix,type):
event = self.test
return self._concat_name(event,suffix,type)
def list(self,type,ignore=None):
if type == 'v':
abs_to_event = os.path.abspath(self.videos)
events = natsorted(os.listdir(self.videos))
elif type == 'p':
abs_to_event = os.path.abspath(self.photos)
events = natsorted(os.listdir(self.photos))
else:
raise ValueError('Unknown suffix for event')
# put most recent event first
events.reverse()
if ignore:
for i in ignore:
try:
events.remove(i)
except ValueError as e:
logging.warning(f'List events: {e}')
return [os.path.join(abs_to_event,event) for event in events]
def _concat_name(self,event,suffix,type):
name = self._record_name()
if type == 'v':
path = os.path.join(self.videos,event)
elif type == 'p':
path = os.path.join(self.photos,event)
else:
raise ValueError('Unknown suffix for record')
os.makedirs(path,exist_ok=True)
name = f'{name}.{suffix}'
name = os.path.join(path,name)
return name
def _event_name(self):
time.strftime('%Y-%m-%d_%H', time.localtime())
return time.strftime('%Y-%m-%d_%H', time.localtime())
def _record_name(self):
return time.strftime('%M:%S', time.localtime())