-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalign_daemon.py
executable file
·59 lines (46 loc) · 2.06 KB
/
align_daemon.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
#!/usr/bin/env python3
import simpledaemon
import logging
import time, os
from daemon import Daemon
from aligner import align_file_list
from voxolab.resilientsession import ResilientSession
from voxolab.models import ProcessType
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class AlignDaemon(simpledaemon.Daemon):
if(os.path.isfile(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'daemon.conf'))):
default_conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'daemon.conf')
else:
default_conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'decode_daemon.conf')
section = 'align'
def run(self):
logger.info('Start daemon')
print('run')
output_dir = self.config_parser.get('align', 'output_dir')
token = self.config_parser.get('http', 'token')
if (not os.path.exists(output_dir)):
os.makedirs(output_dir)
if (not os.path.exists(os.path.join(output_dir, 'results'))):
os.makedirs(os.path.join(output_dir, 'results'))
if (not os.path.exists(os.path.join(output_dir, 'download'))):
os.makedirs(os.path.join(output_dir, 'download'))
if (not os.path.exists(os.path.join(output_dir, 'done'))):
os.makedirs(os.path.join(output_dir, 'done'))
session = ResilientSession()
session.headers.update({'Authentication-Token': token})
process_list_url = self.config_parser.get('align', 'process_list_url').format(ProcessType.TranscriptionAlignment)
while True:
align_file_list(
process_list_url,
self.config_parser.get('align', 'download_url'),
self.config_parser.get('align', 'update_process_url'),
self.config_parser.get('align', 'upload_url'),
token,
session,
output_dir,
self.config_parser.get('align', 'mwer_segmenter_bin')
)
time.sleep(5)
if __name__ == '__main__':
AlignDaemon().main()