forked from valschmidt/oeci_data_manager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathodm_ui.py
219 lines (190 loc) · 7.14 KB
/
odm_ui.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python3
import sys
import pathlib
from PyQt5.QtWidgets import QApplication, QInputDialog, QMainWindow, QTreeWidgetItem, QProgressDialog
from PyQt5 import uic
from PyQt5 import QtCore
from config import ConfigPath
from project import Project
from file_info import FileInfo
from hash_handler import HashHandler
from ros_bag_handler import RosBagHandler
from ros_bag_index_handler import RosBagIndexHandler
from drix_deployments import DrixDeployments
class OECIDataManager(QMainWindow):
handlers = [HashHandler, RosBagIndexHandler, RosBagHandler]
def __init__(self):
super().__init__()
self.config = None
uic.loadUi(pathlib.Path(__file__).parent/'odm_ui.ui', self)
self.menuProject.triggered.connect(self.on_project_action)
self.scanPushButton.clicked.connect(self.on_scan_clicked)
self.processPushButton.clicked.connect(self.on_process_clicked)
self.fileTreeWidget.itemSelectionChanged.connect(self.on_file_tree_selection_changed)
self.fileTreeWidget.setStyleSheet('QTreeWidget#fileTreeWidget::item {background-color: none;}')
self.progress_dialog = None
def set_config(self, config):
self.config = config
def on_project_action(self, action):
if action.text() == 'Select Project':
projects = self.config.get_projects()
d = QInputDialog(self)
p_list = []
for p in projects:
p_list.append(p.label)
d.setComboBoxItems(p_list)
d.setModal(True)
if d.exec():
for p in projects:
if p.label == d.textValue():
self.set_project(p)
def on_scan_progress(self, scan_count):
if self.progress_dialog is not None:
self.progress_dialog.setValue(scan_count)
if self.progress_dialog.wasCanceled():
return True
#QApplication.processEvents()
return False
def on_scan_clicked(self):
if self.progress_dialog is not None:
return
i = self.fileTreeWidget.topLevelItem(0)
if i is not None:
project = i.data(0,100)
QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
project.scan_source()
stats = project.generate_file_stats()
total_count = stats['total']['count']
self.progress_dialog = QProgressDialog()
self.progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
self.progress_dialog.setMaximum(total_count)
self.progress_dialog.show()
project.scan(OECIDataManager.handlers, 1, self.on_scan_progress)
self.progress_dialog.cancel()
self.progress_dialog = None
self.update_stats(project, self.projectStats)
self.update_files()
QApplication.restoreOverrideCursor()
def on_process_progress(self, processed_size):
if self.progress_dialog is not None:
self.progress_dialog.setValue(processed_size/1024)
if self.progress_dialog.wasCanceled():
return True
#QApplication.processEvents()
return False
def on_process_clicked(self):
if self.progress_dialog is not None:
return
i = self.fileTreeWidget.topLevelItem(0)
if i is not None:
project = i.data(0,100)
QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
pcount = self.processCountSpinBox.value()
print(pcount, 'jobs')
stats = project.generate_file_stats()
need_processing_size = stats['needs_processing']['size']
self.progress_dialog = QProgressDialog()
self.progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
self.progress_dialog.setMaximum(need_processing_size/1024)
self.progress_dialog.show()
project.process(OECIDataManager.handlers, pcount, self.on_process_progress)
project.generate_manifest()
dgen = DrixDeployments(project)
dgen.generate()
self.progress_dialog.cancel()
self.progress_dialog = None
self.update_stats(project, self.projectStats)
self.update_files()
QApplication.restoreOverrideCursor()
def set_project(self, project: Project):
QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.fileTreeWidget.clear()
project.load()
root = QTreeWidgetItem(self.fileTreeWidget,(project.label,))
root.setData(0,100,project)
self.update_stats(project, self.projectStats)
self.update_files()
QApplication.restoreOverrideCursor()
def project(self) -> Project:
root = self.fileTreeWidget.topLevelItem(0)
if root is not None:
project = root.data(0,100)
if isinstance(project, Project):
return project
return None
def update_files(self):
root = self.fileTreeWidget.topLevelItem(0)
if root is not None:
project = root.data(0,100)
for f in project():
current_item = root
new_item = False
current_path = None
for level in f.local_path.parts:
child = None
if current_path is None:
current_path = pathlib.Path(level)
else:
current_path = current_path/level
for c in range(current_item.childCount()):
child = current_item.child(c)
if child.text(0) == level:
break
else:
child = None
if child is None:
child = QTreeWidgetItem(current_item, (level,))
child.setData(0,100,current_path)
current_item.sortChildren(0, QtCore.Qt.AscendingOrder)
new_item = True
current_item = child
if new_item:
current_item.setData(0,100,f)
s = f.status()
if s == 'up-to-date':
current_item.setBackground(0, QtCore.Qt.green)
elif s == 'modified' or s == 'needs processing':
current_item.setBackground(0, QtCore.Qt.yellow)
elif s == 'missing':
current_item.setBackground(0, QtCore.Qt.red)
else:
current_item.setBackground(0, QtCore.Qt.lightGray)
def update_stats(self, project, widget, path = None):
stats = project.generate_file_stats(path)
widget.update_stats(stats)
def on_file_tree_selection_changed(self):
i = self.fileTreeWidget.currentItem()
self.metaTreeWidget.clear()
if i is None:
self.selectedDisplayLabel.setText('(none)')
self.selectedStats.clear_stats()
return
d = i.data(0,100)
if isinstance(d, pathlib.Path):
self.selectedDisplayLabel.setText(str(d))
self.update_stats(self.project(), self.selectedStats, d)
elif isinstance(d, FileInfo):
self.selectedDisplayLabel.setText(str(d.local_path.name))
self.selectedStats.clear_stats()
if d.meta is not None:
self.populate_meta_tree(self.metaTreeWidget, d.meta)
else:
self.selectedDisplayLabel.setText('(none)')
self.selectedStats.clear_stats()
def populate_meta_tree(self, parent, item):
for key in item:
value = item[key]
if isinstance(value, list):
key_item = QTreeWidgetItem(parent,(key,))
for li in value:
QTreeWidgetItem(key_item, (str(li),))
elif isinstance(value, dict):
self.populate_meta_tree(QTreeWidgetItem(parent, (key,)),value)
else:
QTreeWidgetItem(parent, (key+': '+str(value),))
def launch(config):
app = QApplication(sys.argv)
window = OECIDataManager()
window.set_config(config)
window.show()
sys.exit(app.exec_())