Passed
Push — master ( b4b259...5acf24 )
by Simon
05:13
created

ProgressBoard.create_lock()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import os
7
import uuid
8
9
from ...data_tools import DataCollector
10
from .progress_io import ProgressIO
11
12
13
class ProgressBoard:
14
    def __init__(self, filter_file=None):
15
        self.filter_file = filter_file
16
17
        self.uuid = uuid.uuid4().hex
18
        self.search_ids = []
19
        self._io_ = ProgressIO(verbosity=False)
20
21
    def create_lock(self, search_id):
22
        path = self._io_.get_lock_file_path(search_id)
23
        if not os.path.exists(path):
24
            os.mknod(path)
25
26
    def init_paths(self, search_id, search_space):
27
        self._io_.remove_progress(search_id)
28
        self.create_lock(search_id)
29
        data_c = DataCollector(self._io_.get_progress_data_path(search_id))
30
31
        self.search_ids.append(search_id)
32
        if self.filter_file:
33
            self._io_.create_filter(search_id, search_space)
34
35
        return data_c
36
37
    def open_dashboard(self):
38
        abspath = os.path.abspath(__file__)
39
        dir_ = os.path.dirname(abspath)
40
41
        paths = " ".join(self.search_ids)
42
        open_streamlit = "streamlit run " + dir_ + "/run_streamlit.py " + paths
43
44
        # from: https://stackoverflow.com/questions/7574841/open-a-terminal-from-python
45
        os.system('gnome-terminal -x bash -c " ' + open_streamlit + ' " ')
46