ibridgesgui 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ibridgesgui/__init__.py +1 -0
- ibridgesgui/__main__.py +164 -0
- ibridgesgui/_version.py +16 -0
- ibridgesgui/browser.py +625 -0
- ibridgesgui/config.py +250 -0
- ibridgesgui/gui_utils.py +118 -0
- ibridgesgui/icons/arrow-left.png +0 -0
- ibridgesgui/icons/arrow-right.png +0 -0
- ibridgesgui/icons/arrow-up.png +0 -0
- ibridgesgui/icons/home.png +0 -0
- ibridgesgui/icons/iBridges.ico +0 -0
- ibridgesgui/icons/loading_circle.gif +0 -0
- ibridgesgui/icons/nosync.png +0 -0
- ibridgesgui/icons/refresh.png +0 -0
- ibridgesgui/icons/syncing.png +0 -0
- ibridgesgui/info.py +53 -0
- ibridgesgui/irods_tree_model.py +158 -0
- ibridgesgui/login.py +101 -0
- ibridgesgui/popup_widgets.py +237 -0
- ibridgesgui/search.py +285 -0
- ibridgesgui/sync.py +289 -0
- ibridgesgui/threads.py +251 -0
- ibridgesgui/ui_files/.py +118 -0
- ibridgesgui/ui_files/ExampleTab.py +87 -0
- ibridgesgui/ui_files/ExampleTab.ui +93 -0
- ibridgesgui/ui_files/MainMenu.py +121 -0
- ibridgesgui/ui_files/MainMenu.ui +171 -0
- ibridgesgui/ui_files/__init__.py +1 -0
- ibridgesgui/ui_files/configCheck.py +96 -0
- ibridgesgui/ui_files/configCheck.ui +142 -0
- ibridgesgui/ui_files/createCollection.py +82 -0
- ibridgesgui/ui_files/createCollection.ui +153 -0
- ibridgesgui/ui_files/dataTransferState.py +114 -0
- ibridgesgui/ui_files/dataTransferState.ui +187 -0
- ibridgesgui/ui_files/irodsLogin.py +134 -0
- ibridgesgui/ui_files/irodsLogin.ui +237 -0
- ibridgesgui/ui_files/renameItem.py +77 -0
- ibridgesgui/ui_files/renameItem.ui +151 -0
- ibridgesgui/ui_files/tabBrowser.py +525 -0
- ibridgesgui/ui_files/tabBrowser.ui +829 -0
- ibridgesgui/ui_files/tabInfo.py +207 -0
- ibridgesgui/ui_files/tabInfo.ui +356 -0
- ibridgesgui/ui_files/tabSearch.py +233 -0
- ibridgesgui/ui_files/tabSearch.ui +400 -0
- ibridgesgui/ui_files/tabSync.py +223 -0
- ibridgesgui/ui_files/tabSync.ui +481 -0
- ibridgesgui/ui_files/tabUpDownload.py +303 -0
- ibridgesgui/ui_files/tabUpDownload.ui +460 -0
- ibridgesgui-0.2.0.dist-info/LICENSE +674 -0
- ibridgesgui-0.2.0.dist-info/METADATA +787 -0
- ibridgesgui-0.2.0.dist-info/RECORD +54 -0
- ibridgesgui-0.2.0.dist-info/WHEEL +5 -0
- ibridgesgui-0.2.0.dist-info/entry_points.txt +2 -0
- ibridgesgui-0.2.0.dist-info/top_level.txt +1 -0
ibridgesgui/sync.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""Sync tab."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import PyQt6.uic
|
|
8
|
+
from ibridges import IrodsPath
|
|
9
|
+
from PyQt6 import QtCore, QtGui
|
|
10
|
+
|
|
11
|
+
from ibridgesgui.gui_utils import UI_FILE_DIR, populate_table, prep_session_for_copy
|
|
12
|
+
from ibridgesgui.irods_tree_model import IrodsTreeModel
|
|
13
|
+
from ibridgesgui.popup_widgets import CreateCollection, CreateDirectory
|
|
14
|
+
from ibridgesgui.threads import SyncThread, TransferDataThread
|
|
15
|
+
from ibridgesgui.ui_files.tabSync import Ui_tabSync
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Sync(PyQt6.QtWidgets.QWidget, Ui_tabSync):
|
|
19
|
+
"""Sync view."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, session, app_name):
|
|
22
|
+
"""Initialise data synchronisation between iRODS and local.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
session : ibridges.Session
|
|
27
|
+
The iRODS session object
|
|
28
|
+
app_name : str
|
|
29
|
+
The name of the app and corresponding logger
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
super().__init__()
|
|
33
|
+
if getattr(sys, "frozen", False):
|
|
34
|
+
super().setupUi(self)
|
|
35
|
+
else:
|
|
36
|
+
PyQt6.uic.loadUi(UI_FILE_DIR / "tabSync.ui", self)
|
|
37
|
+
|
|
38
|
+
self.logger = logging.getLogger(app_name)
|
|
39
|
+
self.session = session
|
|
40
|
+
|
|
41
|
+
# globals for starting diff and sync
|
|
42
|
+
self.sync_diff_thread = None
|
|
43
|
+
self.sync_data_thread = None
|
|
44
|
+
self.sync_source = "" # irods or local
|
|
45
|
+
self.refresh_irods_index = None
|
|
46
|
+
self.diffs = None # output of dry_run
|
|
47
|
+
|
|
48
|
+
# widget memeber and their functionlity
|
|
49
|
+
self.local_to_irods_button.setToolTip("Local to iRODS")
|
|
50
|
+
self.local_to_irods_button.clicked.connect(self.local_to_irods)
|
|
51
|
+
self.irods_to_local_button.setToolTip("iRODS to Local")
|
|
52
|
+
self.irods_to_local_button.clicked.connect(self.irods_to_local)
|
|
53
|
+
self.create_coll_button.clicked.connect(self.create_collection)
|
|
54
|
+
self.create_dir_button.clicked.connect(self.create_dir)
|
|
55
|
+
self.sync_button.hide()
|
|
56
|
+
self.sync_button.clicked.connect(self._start_data_sync)
|
|
57
|
+
self._init_local_fs_tree()
|
|
58
|
+
self._init_irods_tree()
|
|
59
|
+
|
|
60
|
+
def _init_local_fs_tree(self):
|
|
61
|
+
"""Create local FS tree."""
|
|
62
|
+
self.local_fs_model = QtGui.QFileSystemModel(self.local_fs_tree)
|
|
63
|
+
self.local_fs_tree.setModel(self.local_fs_model)
|
|
64
|
+
home_location = QtCore.QStandardPaths.standardLocations(
|
|
65
|
+
QtCore.QStandardPaths.StandardLocation.HomeLocation
|
|
66
|
+
)[0]
|
|
67
|
+
index = self.local_fs_model.setRootPath(home_location)
|
|
68
|
+
self.local_fs_tree.setCurrentIndex(index)
|
|
69
|
+
|
|
70
|
+
# hide unnecessary information
|
|
71
|
+
self.local_fs_tree.setColumnHidden(1, True)
|
|
72
|
+
self.local_fs_tree.setColumnHidden(2, True)
|
|
73
|
+
self.local_fs_tree.setColumnHidden(3, True)
|
|
74
|
+
|
|
75
|
+
def _init_irods_tree(self):
|
|
76
|
+
root = self.irods_root()
|
|
77
|
+
self.irods_model = IrodsTreeModel(self.irods_tree, root)
|
|
78
|
+
self.irods_tree.setModel(self.irods_model)
|
|
79
|
+
self.irods_tree.expanded.connect(self.irods_model.refresh_subtree)
|
|
80
|
+
self.irods_model.init_tree()
|
|
81
|
+
|
|
82
|
+
# hide unnecessary information
|
|
83
|
+
self.irods_tree.setColumnHidden(1, True)
|
|
84
|
+
self.irods_tree.setColumnHidden(2, True)
|
|
85
|
+
self.irods_tree.setColumnHidden(3, True)
|
|
86
|
+
self.irods_tree.setColumnHidden(4, True)
|
|
87
|
+
self.irods_tree.setColumnHidden(5, True)
|
|
88
|
+
|
|
89
|
+
def irods_root(self):
|
|
90
|
+
"""Retrieve lowest visible level in the iRODS tree for the user."""
|
|
91
|
+
lowest = IrodsPath(self.session).absolute()
|
|
92
|
+
while lowest.parent.exists():
|
|
93
|
+
lowest = lowest.parent
|
|
94
|
+
return lowest
|
|
95
|
+
|
|
96
|
+
def create_collection(self):
|
|
97
|
+
"""Create a new collection in current collection."""
|
|
98
|
+
self.error_label.clear()
|
|
99
|
+
indexes = self.irods_tree.selectedIndexes()
|
|
100
|
+
if len(indexes) == 0:
|
|
101
|
+
self.error_label.setText("Please select a parent colection.")
|
|
102
|
+
return
|
|
103
|
+
|
|
104
|
+
parent = self.irods_model.irods_path_from_tree_index(indexes[0])
|
|
105
|
+
if parent.collection_exists():
|
|
106
|
+
coll_widget = CreateCollection(parent, self.logger)
|
|
107
|
+
coll_widget.exec()
|
|
108
|
+
self.irods_model.refresh_subtree(indexes[0])
|
|
109
|
+
else:
|
|
110
|
+
self.error_label.setText("Please select a parent collection, not a data object.")
|
|
111
|
+
|
|
112
|
+
def create_dir(self):
|
|
113
|
+
"""Create a directory/folder on the local filesystem."""
|
|
114
|
+
self.error_label.clear()
|
|
115
|
+
indexes = self.local_fs_tree.selectedIndexes()
|
|
116
|
+
if len(indexes) == 0:
|
|
117
|
+
self.error_label.setText("Please select a parent directory.")
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
parent = self.local_fs_model.filePath(indexes[0])
|
|
121
|
+
if Path(parent).is_dir():
|
|
122
|
+
dir_widget = CreateDirectory(parent)
|
|
123
|
+
dir_widget.exec()
|
|
124
|
+
else:
|
|
125
|
+
self.error_label.setText("Please select a parent directory, not a file.")
|
|
126
|
+
|
|
127
|
+
def sync_diff(self):
|
|
128
|
+
"""Prepare and call the sync thread to calculate diffs."""
|
|
129
|
+
paths = self._gather_info_for_transfer()
|
|
130
|
+
if paths is None:
|
|
131
|
+
return
|
|
132
|
+
local_path, irods_path, _, _ = paths
|
|
133
|
+
|
|
134
|
+
# User info
|
|
135
|
+
self.error_label.setText("Calculating difference ...")
|
|
136
|
+
if self.sync_source == "local":
|
|
137
|
+
self.logger.info(
|
|
138
|
+
"Calculating difference from %s to %s", str(local_path), str(irods_path)
|
|
139
|
+
)
|
|
140
|
+
else:
|
|
141
|
+
self.logger.info(
|
|
142
|
+
"Calculating difference from %s to %s", str(irods_path), str(local_path)
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# start sync thread
|
|
146
|
+
if self.sync_source == "local":
|
|
147
|
+
self._start_sync_diff(local_path, irods_path)
|
|
148
|
+
else:
|
|
149
|
+
self._start_sync_diff(irods_path, local_path)
|
|
150
|
+
|
|
151
|
+
def local_to_irods(self):
|
|
152
|
+
"""Start sync from local to irods."""
|
|
153
|
+
self.sync_source = "local"
|
|
154
|
+
self.sync_diff()
|
|
155
|
+
|
|
156
|
+
def irods_to_local(self):
|
|
157
|
+
"""Start sync from irods to local."""
|
|
158
|
+
self.sync_source = "irods"
|
|
159
|
+
self.sync_diff()
|
|
160
|
+
|
|
161
|
+
def _gather_info_for_transfer(self):
|
|
162
|
+
self.error_label.clear()
|
|
163
|
+
self.diff_table.setRowCount(0)
|
|
164
|
+
# Retrieve local fs path
|
|
165
|
+
fs_selection = self.local_fs_tree.selectedIndexes()
|
|
166
|
+
if len(fs_selection) == 0:
|
|
167
|
+
self.error_label.setText("Please select a directory.")
|
|
168
|
+
return None
|
|
169
|
+
fs_index = fs_selection[0]
|
|
170
|
+
local_path = Path(self.local_fs_model.filePath(fs_index))
|
|
171
|
+
if local_path.is_file():
|
|
172
|
+
self.error_label.setText("Please select a directory, not a file.")
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
# Retrieve irods path
|
|
176
|
+
irods_selection = self.irods_tree.selectedIndexes()
|
|
177
|
+
if len(irods_selection) == 0:
|
|
178
|
+
self.error_label.setText("Please select a collection.")
|
|
179
|
+
return None
|
|
180
|
+
irods_index = irods_selection[0]
|
|
181
|
+
self.refresh_irods_index = irods_index
|
|
182
|
+
irods_path = self.irods_model.irods_path_from_tree_index(irods_index)
|
|
183
|
+
if irods_path.dataobject_exists():
|
|
184
|
+
self.error_label.setText("Please select a collection, not a data object.")
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
return local_path, irods_path, fs_index, irods_index
|
|
188
|
+
|
|
189
|
+
def _enable_buttons(self, enable):
|
|
190
|
+
self.local_to_irods_button.setEnabled(enable)
|
|
191
|
+
self.irods_to_local_button.setEnabled(enable)
|
|
192
|
+
self.create_coll_button.setEnabled(enable)
|
|
193
|
+
self.create_dir_button.setEnabled(enable)
|
|
194
|
+
|
|
195
|
+
def _start_data_sync(self):
|
|
196
|
+
self._enable_buttons(False)
|
|
197
|
+
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.WaitCursor))
|
|
198
|
+
self.error_label.setText("Synchronising data ....")
|
|
199
|
+
|
|
200
|
+
env_path = prep_session_for_copy(self.session, self.error_label)
|
|
201
|
+
if env_path is None:
|
|
202
|
+
return
|
|
203
|
+
try:
|
|
204
|
+
self.sync_data_thread = TransferDataThread(
|
|
205
|
+
env_path, self.logger, self.diffs, overwrite=True
|
|
206
|
+
)
|
|
207
|
+
except Exception:
|
|
208
|
+
self.error_label.setText(
|
|
209
|
+
"Could not instantiate a new session from{env_path}. Check configuration."
|
|
210
|
+
)
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
self.sync_data_thread.current_progress.connect(self._sync_data_status)
|
|
214
|
+
self.sync_data_thread.succeeded.connect(self._sync_data_end)
|
|
215
|
+
self.sync_data_thread.finished.connect(self._finish_sync_data)
|
|
216
|
+
self.sync_data_thread.start()
|
|
217
|
+
|
|
218
|
+
def _start_sync_diff(self, source, target):
|
|
219
|
+
self.sync_button.hide()
|
|
220
|
+
self.error_label.clear()
|
|
221
|
+
self.diff_table.setRowCount(0)
|
|
222
|
+
self._enable_buttons(False)
|
|
223
|
+
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.WaitCursor))
|
|
224
|
+
|
|
225
|
+
self.error_label.setText("Calculating differences ....")
|
|
226
|
+
|
|
227
|
+
# check if session comes from env file in ibridges config
|
|
228
|
+
env_path = prep_session_for_copy(self.session, self.error_label)
|
|
229
|
+
if env_path is None:
|
|
230
|
+
return
|
|
231
|
+
try:
|
|
232
|
+
self.sync_diff_thread = SyncThread(env_path, self.logger, source, target, dry_run=True)
|
|
233
|
+
except Exception:
|
|
234
|
+
self.error_label.setText(
|
|
235
|
+
"Could not instantiate a new session from{env_path}.Check configuration."
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
return
|
|
239
|
+
self.sync_diff_thread.succeeded.connect(self._sync_diff_end)
|
|
240
|
+
self.sync_diff_thread.finished.connect(self._finish_sync_diff)
|
|
241
|
+
self.sync_diff_thread.start()
|
|
242
|
+
|
|
243
|
+
def _finish_sync_diff(self):
|
|
244
|
+
self._enable_buttons(True)
|
|
245
|
+
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor))
|
|
246
|
+
if self.sync_diff_thread:
|
|
247
|
+
del self.sync_diff_thread
|
|
248
|
+
|
|
249
|
+
def _finish_sync_data(self):
|
|
250
|
+
self._enable_buttons(True)
|
|
251
|
+
self.sync_button.hide()
|
|
252
|
+
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor))
|
|
253
|
+
if self.sync_data_thread:
|
|
254
|
+
del self.sync_data_thread
|
|
255
|
+
|
|
256
|
+
def _sync_data_end(self, thread_output: dict):
|
|
257
|
+
if thread_output["error"] != "":
|
|
258
|
+
self.error_label.setText(thread_output["error"])
|
|
259
|
+
self.sync_source = ""
|
|
260
|
+
self.refresh_irods_index = None
|
|
261
|
+
return
|
|
262
|
+
self.error_label.clear()
|
|
263
|
+
|
|
264
|
+
if self.refresh_irods_index is not None:
|
|
265
|
+
self.irods_model.refresh_subtree(self.refresh_irods_index)
|
|
266
|
+
self.error_label.setText("Data synchronisation complete.")
|
|
267
|
+
|
|
268
|
+
def _sync_data_status(self, state):
|
|
269
|
+
self.error_label.setText(state)
|
|
270
|
+
|
|
271
|
+
def _sync_diff_end(self, thread_output: dict):
|
|
272
|
+
if thread_output["error"] != "":
|
|
273
|
+
self.error_label.setText(thread_output["error"])
|
|
274
|
+
self.sync_source = ""
|
|
275
|
+
self.refresh_irods_index = None
|
|
276
|
+
return
|
|
277
|
+
|
|
278
|
+
self.error_label.clear()
|
|
279
|
+
table_data = thread_output["result"]["upload"] + thread_output["result"]["download"]
|
|
280
|
+
|
|
281
|
+
populate_table(self.diff_table, len(table_data), table_data)
|
|
282
|
+
if len(table_data) == 0:
|
|
283
|
+
self.error_label.setText("Data is already synchronised.")
|
|
284
|
+
self.sync_source = ""
|
|
285
|
+
self.refresh_irods_index = None
|
|
286
|
+
else:
|
|
287
|
+
self.diffs = thread_output["result"]
|
|
288
|
+
self.sync_button.show()
|
|
289
|
+
self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor))
|
ibridgesgui/threads.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""Thread classes for length iBridges functions."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from ibridges import IrodsPath, Session, download, search_data, sync, upload
|
|
6
|
+
from irods.exception import CAT_NO_ACCESS_PERMISSION, NetworkException
|
|
7
|
+
from PyQt6.QtCore import QThread, pyqtSignal
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SearchThread(QThread):
|
|
11
|
+
"""Start iRODS search in an own thread using the same iRODS session."""
|
|
12
|
+
|
|
13
|
+
succeeded = pyqtSignal(dict)
|
|
14
|
+
|
|
15
|
+
def __init__(self, logger, ienv_path, path: str, checksum: str, key_vals: dict):
|
|
16
|
+
"""Pass searh parameters."""
|
|
17
|
+
super().__init__()
|
|
18
|
+
self.logger = logger
|
|
19
|
+
self.thread_session = Session(irods_env=ienv_path)
|
|
20
|
+
self.logger.debug("Search thread: created new session")
|
|
21
|
+
self.sync_thread = None
|
|
22
|
+
self.path = path
|
|
23
|
+
self.checksum = checksum
|
|
24
|
+
self.key_vals = key_vals
|
|
25
|
+
|
|
26
|
+
def _delete_session(self):
|
|
27
|
+
self.thread_session.close()
|
|
28
|
+
if self.thread_session.irods_session is None:
|
|
29
|
+
self.logger.debug("Search thread: Thread session successfully deleted.")
|
|
30
|
+
else:
|
|
31
|
+
self.logger.debug("Search thread: Thread session still exists.")
|
|
32
|
+
|
|
33
|
+
def run(self):
|
|
34
|
+
"""Run the thread."""
|
|
35
|
+
search_out = {}
|
|
36
|
+
try:
|
|
37
|
+
search_out["results"] = search_data(
|
|
38
|
+
self.thread_session, path=self.path, checksum=self.checksum, key_vals=self.key_vals
|
|
39
|
+
)
|
|
40
|
+
self._delete_session()
|
|
41
|
+
except NetworkException:
|
|
42
|
+
self._delete_session()
|
|
43
|
+
search_out["error"] = "Search takes too long. Please provide more parameters."
|
|
44
|
+
self.succeeded.emit(search_out)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TransferDataThread(QThread):
|
|
48
|
+
"""Transfer data between local and iRODS."""
|
|
49
|
+
|
|
50
|
+
succeeded = pyqtSignal(dict)
|
|
51
|
+
current_progress = pyqtSignal(str)
|
|
52
|
+
|
|
53
|
+
def __init__(self, ienv_path: Path, logger, diffs: dict, overwrite: bool):
|
|
54
|
+
"""Pass parameters.
|
|
55
|
+
|
|
56
|
+
ienv_path : Path
|
|
57
|
+
path to the irods_environment.json to create a new session.
|
|
58
|
+
logger : logging.Logger
|
|
59
|
+
Logger
|
|
60
|
+
diffs : dict
|
|
61
|
+
A dict object containing four keys:
|
|
62
|
+
'create_dir' : Create local directories when sync from iRODS to local
|
|
63
|
+
'create_collection' : Create collections when sync from local to iRODS
|
|
64
|
+
'upload' : Tuple(local path, iRODS path) when sync from local to iRODS
|
|
65
|
+
'download' : Tuple(iRODS path, local path) when sync from iRODS to local
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
super().__init__()
|
|
69
|
+
|
|
70
|
+
self.logger = logger
|
|
71
|
+
self.thread_session = Session(irods_env=ienv_path)
|
|
72
|
+
self.logger.debug("Transfer data thread: Created new session.")
|
|
73
|
+
self.diffs = diffs
|
|
74
|
+
self.overwrite = overwrite
|
|
75
|
+
|
|
76
|
+
def _delete_session(self):
|
|
77
|
+
self.thread_session.close()
|
|
78
|
+
if self.thread_session.irods_session is None:
|
|
79
|
+
self.logger.debug("Transfer data thread: Thread session successfully deleted.")
|
|
80
|
+
else:
|
|
81
|
+
self.logger.debug("Transfer data thread: Thread session still exists.")
|
|
82
|
+
|
|
83
|
+
def run(self):
|
|
84
|
+
"""Run the thread."""
|
|
85
|
+
obj_count = 0
|
|
86
|
+
obj_failed = 0
|
|
87
|
+
file_count = 0
|
|
88
|
+
file_failed = 0
|
|
89
|
+
transfer_out = {}
|
|
90
|
+
transfer_out["error"] = ""
|
|
91
|
+
|
|
92
|
+
for coll in self.diffs["create_collection"]:
|
|
93
|
+
try:
|
|
94
|
+
IrodsPath.create_collection(self.thread_session, coll)
|
|
95
|
+
self.logger.info("Transfer data thread: Created collection %s", coll)
|
|
96
|
+
except Exception as error:
|
|
97
|
+
self.logger.exception(
|
|
98
|
+
"Transfer data thread: Could not create %s; %s", coll, repr(error)
|
|
99
|
+
)
|
|
100
|
+
transfer_out["error"] = (
|
|
101
|
+
transfer_out["error"] + f"\nTransfer failed Cannot create {coll}: {repr(error)}"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
for folder in self.diffs["create_dir"]:
|
|
105
|
+
print(f"create {folder}")
|
|
106
|
+
try:
|
|
107
|
+
Path(folder).mkdir(parents=True, exist_ok=True)
|
|
108
|
+
self.logger.info("Transfer data thread: Created folder %s", folder)
|
|
109
|
+
except Exception as error:
|
|
110
|
+
self.logger.exception(
|
|
111
|
+
"Transfer data thread: Could not create %s; %s", folder, repr(error)
|
|
112
|
+
)
|
|
113
|
+
transfer_out["error"] = (
|
|
114
|
+
transfer_out["error"]
|
|
115
|
+
+ f"\nTransfer failed Cannot create {folder}: {repr(error)}"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
for local_path, irods_path in self.diffs["upload"]:
|
|
119
|
+
try:
|
|
120
|
+
upload(
|
|
121
|
+
self.thread_session,
|
|
122
|
+
local_path,
|
|
123
|
+
irods_path,
|
|
124
|
+
resc_name=self.diffs["resc_name"],
|
|
125
|
+
overwrite=self.overwrite,
|
|
126
|
+
options=self.diffs["options"],
|
|
127
|
+
)
|
|
128
|
+
obj_count += 1
|
|
129
|
+
self.logger.info(
|
|
130
|
+
"Transfer data thread: Transfer %s --> %s, overwrite %s",
|
|
131
|
+
local_path,
|
|
132
|
+
irods_path,
|
|
133
|
+
self.overwrite,
|
|
134
|
+
)
|
|
135
|
+
except Exception as error:
|
|
136
|
+
obj_failed += 1
|
|
137
|
+
self.logger.exception(
|
|
138
|
+
"Transfer data thread: Could not transfer %s --> %s; %s",
|
|
139
|
+
local_path,
|
|
140
|
+
irods_path,
|
|
141
|
+
repr(error),
|
|
142
|
+
)
|
|
143
|
+
transfer_out["error"] = (
|
|
144
|
+
transfer_out["error"]
|
|
145
|
+
+ f"\nTransfer failed, cannot upload {str(local_path)}: {repr(error)}"
|
|
146
|
+
)
|
|
147
|
+
emit_string = f"{obj_count} of {len(self.diffs['upload'])} files"
|
|
148
|
+
emit_string += f" transferred, failed: {obj_failed}."
|
|
149
|
+
self.current_progress.emit(emit_string)
|
|
150
|
+
|
|
151
|
+
for irods_path, local_path in self.diffs["download"]:
|
|
152
|
+
try:
|
|
153
|
+
download(
|
|
154
|
+
self.thread_session,
|
|
155
|
+
irods_path,
|
|
156
|
+
local_path,
|
|
157
|
+
resc_name=self.diffs["resc_name"],
|
|
158
|
+
overwrite=self.overwrite,
|
|
159
|
+
options=self.diffs["options"],
|
|
160
|
+
)
|
|
161
|
+
file_count += 1
|
|
162
|
+
self.logger.info(
|
|
163
|
+
"Transfer data thread: Transfer %s --> %s, overwrite %s",
|
|
164
|
+
irods_path,
|
|
165
|
+
local_path,
|
|
166
|
+
self.overwrite,
|
|
167
|
+
)
|
|
168
|
+
except Exception as error:
|
|
169
|
+
file_failed += 1
|
|
170
|
+
self.logger.exception(
|
|
171
|
+
"Transfer data thread: Could not transfer %s --> %s; %s",
|
|
172
|
+
irods_path,
|
|
173
|
+
local_path,
|
|
174
|
+
repr(error),
|
|
175
|
+
)
|
|
176
|
+
transfer_out["error"] = (
|
|
177
|
+
transfer_out["error"]
|
|
178
|
+
+ f"\nTransfer failed, cannot download {str(irods_path)}: {repr(error)}"
|
|
179
|
+
)
|
|
180
|
+
emit_string = f"{file_count} of {len(self.diffs['download'])} data objects"
|
|
181
|
+
emit_string += f" transferred, failed: {file_failed}."
|
|
182
|
+
self.current_progress.emit(emit_string)
|
|
183
|
+
|
|
184
|
+
self._delete_session()
|
|
185
|
+
self.succeeded.emit(transfer_out)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class SyncThread(QThread):
|
|
189
|
+
"""Sync between iRODS and local FS."""
|
|
190
|
+
|
|
191
|
+
succeeded = pyqtSignal(dict)
|
|
192
|
+
|
|
193
|
+
def __init__(self, ienv_path, logger, source, target, dry_run: bool):
|
|
194
|
+
"""Pass download parameters."""
|
|
195
|
+
super().__init__()
|
|
196
|
+
|
|
197
|
+
self.logger = logger
|
|
198
|
+
self.thread_session = Session(irods_env=ienv_path)
|
|
199
|
+
self.logger.debug("Sync thread: created new session")
|
|
200
|
+
self.source = source
|
|
201
|
+
self.target = target
|
|
202
|
+
self.dry_run = dry_run
|
|
203
|
+
|
|
204
|
+
def _delete_session(self):
|
|
205
|
+
self.thread_session.close()
|
|
206
|
+
if self.thread_session.irods_session is None:
|
|
207
|
+
self.logger.debug("Sync thread: Thread session successfully deleted.")
|
|
208
|
+
else:
|
|
209
|
+
self.logger.debug("Sync thread: Thread session still exists.")
|
|
210
|
+
|
|
211
|
+
def run(self):
|
|
212
|
+
"""Run the thread."""
|
|
213
|
+
sync_out = {}
|
|
214
|
+
sync_out["error"] = ""
|
|
215
|
+
|
|
216
|
+
try:
|
|
217
|
+
result = sync(
|
|
218
|
+
self.thread_session,
|
|
219
|
+
self.source,
|
|
220
|
+
self.target,
|
|
221
|
+
dry_run=self.dry_run,
|
|
222
|
+
copy_empty_folders=True,
|
|
223
|
+
)
|
|
224
|
+
self.logger.info(
|
|
225
|
+
"Sync %s to %s, dry_run %s", str(self.source), str(self.target), str(self.dry_run)
|
|
226
|
+
)
|
|
227
|
+
if self.dry_run:
|
|
228
|
+
sync_out["result"] = result
|
|
229
|
+
|
|
230
|
+
except PermissionError as error:
|
|
231
|
+
sync_out["error"] = f"Sync failed. No access to {error.filename}."
|
|
232
|
+
self.logger.exception(
|
|
233
|
+
"Sync failed: %s --> %s; %s", str(self.source), str(self.target), repr(error)
|
|
234
|
+
)
|
|
235
|
+
except CAT_NO_ACCESS_PERMISSION as error:
|
|
236
|
+
sync_out["error"] = (
|
|
237
|
+
"There is data in the iRODS collection which you are not allowed to access."
|
|
238
|
+
)
|
|
239
|
+
self.logger.exception(
|
|
240
|
+
"Sync failed: %s --> %s; %s", str(self.source), str(self.target), repr(error)
|
|
241
|
+
)
|
|
242
|
+
except Exception as error:
|
|
243
|
+
self.logger.exception(
|
|
244
|
+
"Sync failed: %s --> %s; %s", str(self.source), str(self.target), repr(error)
|
|
245
|
+
)
|
|
246
|
+
sync_out["error"] = (
|
|
247
|
+
sync_out["error"]
|
|
248
|
+
+ f"\nSync failed: {str(self.source)} --> {str(self.target)}: {repr(error)}"
|
|
249
|
+
)
|
|
250
|
+
self._delete_session()
|
|
251
|
+
self.succeeded.emit(sync_out)
|
ibridgesgui/ui_files/.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Form implementation generated from reading ui file 'ibridgesgui/ui_files/MainMenu.ui'
|
|
2
|
+
#
|
|
3
|
+
# Created by: PyQt6 UI code generator 6.6.1
|
|
4
|
+
#
|
|
5
|
+
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
|
6
|
+
# run again. Do not edit this file unless you know what you are doing.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
from PyQt6 import QtCore, QtGui, QtWidgets
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Ui_MainWindow(object):
|
|
13
|
+
def setupUi(self, MainWindow):
|
|
14
|
+
MainWindow.setObjectName("MainWindow")
|
|
15
|
+
MainWindow.resize(1300, 850)
|
|
16
|
+
MainWindow.setMinimumSize(QtCore.QSize(1300, 850))
|
|
17
|
+
MainWindow.setStyleSheet("QWidget\n"
|
|
18
|
+
"{\n"
|
|
19
|
+
" color: rgb(86, 184, 139);\n"
|
|
20
|
+
" background-color: rgb(54, 54, 54);\n"
|
|
21
|
+
" selection-background-color: rgb(58, 152, 112);\n"
|
|
22
|
+
" font: 16pt;\n"
|
|
23
|
+
"}\n"
|
|
24
|
+
"\n"
|
|
25
|
+
"QTabBar::tab:top:selected {\n"
|
|
26
|
+
" background-color: rgb(58, 152, 112);\n"
|
|
27
|
+
" color: rgb(54, 54, 54);\n"
|
|
28
|
+
"}\n"
|
|
29
|
+
"\n"
|
|
30
|
+
"QLabel#error_label\n"
|
|
31
|
+
"{\n"
|
|
32
|
+
" color: rgb(217, 174, 23);\n"
|
|
33
|
+
" font: 18pt;\n"
|
|
34
|
+
"}\n"
|
|
35
|
+
"")
|
|
36
|
+
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
|
|
37
|
+
self.centralwidget.setStyleSheet("")
|
|
38
|
+
self.centralwidget.setObjectName("centralwidget")
|
|
39
|
+
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
|
|
40
|
+
self.verticalLayout.setObjectName("verticalLayout")
|
|
41
|
+
self.tab_widget = QtWidgets.QTabWidget(parent=self.centralwidget)
|
|
42
|
+
self.tab_widget.setMinimumSize(QtCore.QSize(600, 300))
|
|
43
|
+
font = QtGui.QFont()
|
|
44
|
+
font.setPointSize(16)
|
|
45
|
+
font.setBold(False)
|
|
46
|
+
font.setItalic(False)
|
|
47
|
+
self.tab_widget.setFont(font)
|
|
48
|
+
self.tab_widget.setObjectName("tab_widget")
|
|
49
|
+
self.verticalLayout.addWidget(self.tab_widget)
|
|
50
|
+
self.error_label = QtWidgets.QLabel(parent=self.centralwidget)
|
|
51
|
+
self.error_label.setText("")
|
|
52
|
+
self.error_label.setObjectName("error_label")
|
|
53
|
+
self.verticalLayout.addWidget(self.error_label)
|
|
54
|
+
MainWindow.setCentralWidget(self.centralwidget)
|
|
55
|
+
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
|
|
56
|
+
self.menubar.setGeometry(QtCore.QRect(0, 0, 1300, 24))
|
|
57
|
+
font = QtGui.QFont()
|
|
58
|
+
font.setPointSize(16)
|
|
59
|
+
font.setBold(False)
|
|
60
|
+
font.setItalic(False)
|
|
61
|
+
self.menubar.setFont(font)
|
|
62
|
+
self.menubar.setObjectName("menubar")
|
|
63
|
+
self.main_menu = QtWidgets.QMenu(parent=self.menubar)
|
|
64
|
+
font = QtGui.QFont()
|
|
65
|
+
font.setPointSize(16)
|
|
66
|
+
font.setBold(False)
|
|
67
|
+
font.setItalic(False)
|
|
68
|
+
self.main_menu.setFont(font)
|
|
69
|
+
self.main_menu.setObjectName("main_menu")
|
|
70
|
+
self.config_menu = QtWidgets.QMenu(parent=self.menubar)
|
|
71
|
+
self.config_menu.setObjectName("config_menu")
|
|
72
|
+
MainWindow.setMenuBar(self.menubar)
|
|
73
|
+
self.action_close_session = QtGui.QAction(parent=MainWindow)
|
|
74
|
+
font = QtGui.QFont()
|
|
75
|
+
self.action_close_session.setFont(font)
|
|
76
|
+
self.action_close_session.setObjectName("action_close_session")
|
|
77
|
+
self.action_exit = QtGui.QAction(parent=MainWindow)
|
|
78
|
+
font = QtGui.QFont()
|
|
79
|
+
self.action_exit.setFont(font)
|
|
80
|
+
self.action_exit.setObjectName("action_exit")
|
|
81
|
+
self.actionSearch = QtGui.QAction(parent=MainWindow)
|
|
82
|
+
font = QtGui.QFont()
|
|
83
|
+
self.actionSearch.setFont(font)
|
|
84
|
+
self.actionSearch.setObjectName("actionSearch")
|
|
85
|
+
self.actionSaveConfig = QtGui.QAction(parent=MainWindow)
|
|
86
|
+
font = QtGui.QFont()
|
|
87
|
+
self.actionSaveConfig.setFont(font)
|
|
88
|
+
self.actionSaveConfig.setObjectName("actionSaveConfig")
|
|
89
|
+
self.action_connect = QtGui.QAction(parent=MainWindow)
|
|
90
|
+
self.action_connect.setObjectName("action_connect")
|
|
91
|
+
self.action_check_configuration = QtGui.QAction(parent=MainWindow)
|
|
92
|
+
self.action_check_configuration.setObjectName("action_check_configuration")
|
|
93
|
+
self.action_add_configuration = QtGui.QAction(parent=MainWindow)
|
|
94
|
+
self.action_add_configuration.setObjectName("action_add_configuration")
|
|
95
|
+
self.main_menu.addAction(self.action_connect)
|
|
96
|
+
self.main_menu.addAction(self.action_close_session)
|
|
97
|
+
self.main_menu.addAction(self.action_exit)
|
|
98
|
+
self.config_menu.addAction(self.action_check_configuration)
|
|
99
|
+
self.config_menu.addAction(self.action_add_configuration)
|
|
100
|
+
self.menubar.addAction(self.main_menu.menuAction())
|
|
101
|
+
self.menubar.addAction(self.config_menu.menuAction())
|
|
102
|
+
|
|
103
|
+
self.retranslateUi(MainWindow)
|
|
104
|
+
self.tab_widget.setCurrentIndex(-1)
|
|
105
|
+
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
|
106
|
+
|
|
107
|
+
def retranslateUi(self, MainWindow):
|
|
108
|
+
_translate = QtCore.QCoreApplication.translate
|
|
109
|
+
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
|
110
|
+
self.main_menu.setTitle(_translate("MainWindow", "Connect"))
|
|
111
|
+
self.config_menu.setTitle(_translate("MainWindow", "Configure"))
|
|
112
|
+
self.action_close_session.setText(_translate("MainWindow", "Close Connection"))
|
|
113
|
+
self.action_exit.setText(_translate("MainWindow", "Exit iBridges"))
|
|
114
|
+
self.actionSearch.setText(_translate("MainWindow", "Search"))
|
|
115
|
+
self.actionSaveConfig.setText(_translate("MainWindow", "Save configuration"))
|
|
116
|
+
self.action_connect.setText(_translate("MainWindow", "Connect to iRODS"))
|
|
117
|
+
self.action_check_configuration.setText(_translate("MainWindow", "Check Configuration"))
|
|
118
|
+
self.action_add_configuration.setText(_translate("MainWindow", "Add Configuration"))
|