forked from norc-heal/heal-data-pkg-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_pkgshareablewidget.py
More file actions
234 lines (176 loc) · 17 KB
/
Copy pathlayout_pkgshareablewidget.py
File metadata and controls
234 lines (176 loc) · 17 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import csv, codecs # base python, no pip install needed
import os # base python, no pip install needed
from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport
from PyQt5.QtGui import QImage, QPainter
from PyQt5.QtGui import QTextCursor
from PyQt5.QtCore import QFile, Qt
import sys # base python, no pip install needed
from PyQt5.QtWidgets import QDialog, QApplication, QFileDialog
from PyQt5.uic import loadUi
from pathlib import Path # base python, no pip install needed
from healdata_utils.cli import convert_to_vlmd
#from frictionless import plugins # frictionless already installed as a healdata_utils dependency, no pip install needed
#from frictionless.plugins import remote
#from frictionless import describe
import pandas as pd # pandas already installed as a healdata_utils dependency, no pip install needed
import json # base python, no pip install needed
import pipe
import dsc_pkg_utils # local module, no pip install needed
from layout_csveditwidget import CSVEditWindow
import version_check
import version_update_tracker
import schema_results_tracker
from healdata_utils.validators.jsonschema import validate_against_jsonschema
import pkg_shareable_data
class PkgShareableWindow(QtWidgets.QMainWindow):
def __init__(self, workingDataPkgDirDisplay):
super().__init__()
self.w = None # No external window yet.
self.pkgPath = None # Initialize with no working data package directory path
self.workingDataPkgDirDisplay = workingDataPkgDirDisplay
widget = QtWidgets.QWidget()
# self.buttonCheckPkgVersions = QtWidgets.QPushButton(text="Check Package Versions",parent=self)
# self.buttonCheckPkgVersions.clicked.connect(self.check_pkg_versions)
self.explainShareablePkg = QtWidgets.QLabel(text = "<b>Prepare your data package for submission to a public data repository by creating a \"shareable\" version of your Data Package.</b><br><br>Your \"Shareable Data Package(s)\" will have the same structure as your study folder, but contain only the study files/resources you intend to share. You can create more than one \"flavor\" of Shareable Data Package. Available \"flavors\" of Shareable Data Package include:<br>1. <b>Open-access, Now</b> - Includes files that have been set as ONLY open-access, and files that have been set as temporary-private and open-access IF the access date is earlier than today's date<br>2. <b>Managed-access, Now</b> - Includes files that have been set as ONLY open-access or ONLY managed-access, and files that have been set as temporary-private AND open-access or managed-access IF the access date is earlier than today's date<br>3. <b>Open-access, By Specified Date</b> - Includes files that have been set as ONLY open-access, and files that have been set as temporary-private and open-access IF the access date is earlier than the user-specified date (usually, a date in the future)<br>4. <b>Managed-access, By Specified Date</b> - Includes files that have been set as ONLY open-access or ONLY managed-access, and files that have been set as temporary-private AND open-access or managed-access IF the access date is earlier than the user-specified date (usually, a date in the future)", parent=self)
self.dateEdit = QtWidgets.QDateEdit(calendarPopup=True,parent=self)
self.dateEdit.setCalendarPopup(True)
self.dateEdit.setDateTime(QtCore.QDateTime.currentDateTime())
self.dateEdit.setStyleSheet("background-color: lightgreen")
self.labelDateEdit = QtWidgets.QLabel(text = "<b>If creating a flavor of Shareable Data Package that requires a user-specified date, please set the user-specified date here:</b><br>(Click the arrow all the way on the right to pop out a calendar widget)", parent=self)
self.labelDateEdit.setStyleSheet("background-color: lightgreen")
self.buttonOpenAccessNow = QtWidgets.QPushButton(text="Open Access, Now",parent=self)
self.buttonOpenAccessNow.clicked.connect(self.open_access_now)
self.buttonManagedAccessNow = QtWidgets.QPushButton(text="Managed Access, Now",parent=self)
self.buttonManagedAccessNow.clicked.connect(self.managed_access_now)
self.buttonOpenAccessByDate = QtWidgets.QPushButton(text="Open Access, By Specified Date",parent=self)
self.buttonOpenAccessByDate.clicked.connect(self.open_access_by_date)
self.buttonManagedAccessByDate = QtWidgets.QPushButton(text="Managed Access, By Specified Date",parent=self)
self.buttonManagedAccessByDate.clicked.connect(self.managed_access_by_date)
# maybe switch Line edit to this: https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QPlainTextEdit.html#more
#self.userMessageBox = QtWidgets.QLineEdit(parent=self)
self.userMessageBox = QtWidgets.QTextEdit(parent=self)
self.userMessageBox.setReadOnly(True)
self.labelUserMessageBox = QtWidgets.QLabel(text = "User Status Message Box:", parent=self)
layout = QtWidgets.QVBoxLayout()
#layout.addWidget(self.buttonCheckPkgVersions)
layout.addWidget(self.explainShareablePkg)
layout.addWidget(self.labelDateEdit)
layout.addWidget(self.dateEdit)
layout.addWidget(self.buttonOpenAccessNow)
layout.addWidget(self.buttonManagedAccessNow)
layout.addWidget(self.buttonOpenAccessByDate)
layout.addWidget(self.buttonManagedAccessByDate)
layout.addWidget(self.labelUserMessageBox)
layout.addWidget(self.userMessageBox)
widget.setLayout(layout)
self.setCentralWidget(widget)
def open_access_now(self):
print("creating shareable data pkg with flavor: open-access-now")
# check if user has set a working data package dir - if not exit gracefully with informative message
if not dsc_pkg_utils.getWorkingDataPkgDir(self=self):
return
messageText = "<br>Working on creating your shareable data package...<br>"
saveFormat = '<span style="color:black;">{}</span>'
self.userMessageBox.append(saveFormat.format(messageText))
self.userMessageBox.moveCursor(QTextCursor.End)
QApplication.processEvents() # print accumulated user status messages
shareableDir, shareablePkgDir, exitStatus, failType = pkg_shareable_data.createShareableDataPkg(
workingDataPkgDir=self.workingDataPkgDir,
flavor="open-access-now"
)
if exitStatus:
print("success")
messageText = "<br>Success - Your shareable data package was created! This \"open-access-now\" shareable data package contains:<br><br>1. Study files - all study files set as open-access as of today's date<br>2. Standard data package metadata - experiment tracker, resource tracker, and any data dictionary(s) and results tracker(s) that have been set as open-access as of today's date<br><br>You'll find your shareable data package directory at: " + shareableDir + "<br><br>There is also a readme file and an \"overview\" resource tracker with an indicator of which files are shared in this shareable data package at that location.<br><br>Your shareable data package directory's path is: " + shareablePkgDir + "<br><br>You should:<br><br>1. Inspect your shareable data package, then zip it up once you are satisfied that the correct files have been shared<br>2. Share your zipped up shareable data package directory as open access at your selected data repository<br>3. Share your readme file and \"overview\" resource tracker as open access at your selected data repository<br>"
errorFormat = '<span style="color:green;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
else:
print("failure")
messageText = "<br>Failure - Your shareable data package was NOT created!<br>"
if failType == "dirExists":
messageText = messageText + "<br>It looks like you've already created an \"open-access-now\" shareable data package today. If you want to overwrite the original version you will have to first delete the original version. The original version of this shareable data package can be found at: " + shareablePkgDir + "<br>"
errorFormat = '<span style="color:red;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
def managed_access_now(self):
print("creating shareable data pkg with flavor: managed-access-now")
# check if user has set a working data package dir - if not exit gracefully with informative message
if not dsc_pkg_utils.getWorkingDataPkgDir(self=self):
return
messageText = "<br>Working on creating your shareable data package...<br>"
saveFormat = '<span style="color:black;">{}</span>'
self.userMessageBox.append(saveFormat.format(messageText))
self.userMessageBox.moveCursor(QTextCursor.End)
QApplication.processEvents() # print accumulated user status messages
shareableDir, shareablePkgDir, exitStatus, failType = pkg_shareable_data.createShareableDataPkg(
workingDataPkgDir=self.workingDataPkgDir,
flavor="managed-access-now"
)
if exitStatus:
print("success")
messageText = "<br>Success - Your shareable data package was created! This \"managed-access-now\" shareable data package contains:<br><br>1. Study files - all study files set as open-access or managed-access as of today's date<br>2. Standard data package metadata - experiment tracker, resource tracker, and any data dictionary(s) and results tracker(s) that have been set as open-access or managed-access as of today's date<br><br>You'll find your shareable data package directory at: " + shareableDir + "<br><br>There is also a readme file and an \"overview\" resource tracker with an indicator of which files are shared in this shareable data package at that location.<br> Your shareable data package directory's path is: " + shareablePkgDir + "<br><br>You should:<br><br>1. Inspect your shareable data package, then zip it up once you are satisfied that the correct files have been shared<br>2. Share your zipped up shareable data package directory as managed access at your selected data repository<br>3. Share your readme file and \"overview\" resource tracker as open access at your selected data repository<br>"
errorFormat = '<span style="color:green;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
else:
print("failure")
messageText = "<br>Failure - Your shareable data package was NOT created!<br>"
if failType == "dirExists":
messageText = messageText + "<br>It looks like you've already created a \"managed-access-now\" shareable data package today. If you want to overwrite the original version you will have to first delete the original version. The original version of this shareable data package can be found at: " + shareablePkgDir + "<br>"
errorFormat = '<span style="color:red;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
def open_access_by_date(self):
print("creating shareable data pkg with flavor: open-access-by-date")
byDate = self.dateEdit.date().toString("MM/dd/yyyy")
print("byDate: ",byDate)
# check if user has set a working data package dir - if not exit gracefully with informative message
if not dsc_pkg_utils.getWorkingDataPkgDir(self=self):
return
messageText = "<br>Working on creating your shareable data package...<br>"
saveFormat = '<span style="color:black;">{}</span>'
self.userMessageBox.append(saveFormat.format(messageText))
self.userMessageBox.moveCursor(QTextCursor.End)
QApplication.processEvents() # print accumulated user status messages
shareableDir, shareablePkgDir, exitStatus, failType = pkg_shareable_data.createShareableDataPkg(
workingDataPkgDir=self.workingDataPkgDir,
flavor="open-access-by-date",
byDate=byDate
)
if exitStatus:
print("success")
messageText = "<br>Success - Your shareable data package was created! This \"open-access-by-date\" shareable data package contains:<br><br>1. Study files - all study files set as open-access as of " + byDate + "<br>2. Standard data package metadata - experiment tracker, resource tracker, and any data dictionary(s) and results tracker(s) that have been set as open-access as of " + byDate + "<br><br>You'll find your shareable data package directory at: " + shareableDir + "<br><br>There is also a readme file and an \"overview\" resource tracker with an indicator of which files are shared in this shareable data package at that location.<br><br>Your shareable data package directory's path is: " + shareablePkgDir + "<br><br> You should:<br><br>1. Inspect your shareable data package, then zip it up once you are satisfied that the correct files have been shared<br>2. Share your zipped up shareable data package directory as open access but under embargo until " + byDate + " at your selected data repository<br>3. Share your readme file and \"overview\" resource tracker as open access at your selected data repository<br>"
errorFormat = '<span style="color:green;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
else:
print("failure")
messageText = "<br>Failure - Your shareable data package was NOT created!<br>"
if failType == "dirExists":
messageText = messageText + "<br>It looks like you've already created an \"open-access-by-date\" shareable data package with a \"by date\" of " + byDate + " today. If you want to overwrite the original version you will have to first delete the original version. The original version of this shareable data package can be found at: " + shareablePkgDir + "<br>"
errorFormat = '<span style="color:red;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
def managed_access_by_date(self):
print("creating shareable data pkg with flavor: managed-access-by-date")
byDate = self.dateEdit.date().toString("MM/dd/yyyy")
print("byDate: ",byDate)
# check if user has set a working data package dir - if not exit gracefully with informative message
if not dsc_pkg_utils.getWorkingDataPkgDir(self=self):
return
messageText = "<br>Working on creating your shareable data package...<br>"
saveFormat = '<span style="color:black;">{}</span>'
self.userMessageBox.append(saveFormat.format(messageText))
self.userMessageBox.moveCursor(QTextCursor.End)
QApplication.processEvents() # print accumulated user status messages
shareableDir, shareablePkgDir, exitStatus, failType = pkg_shareable_data.createShareableDataPkg(
workingDataPkgDir=self.workingDataPkgDir,
flavor="managed-access-by-date",
byDate=byDate
)
if exitStatus:
print("success")
messageText = "<br>Success - Your shareable data package was created! This \"managed-access-by-date\" shareable data package contains:<br><br>1. Study files - all study files set as open-access or managed-access as of " + byDate + "<br>2. Standard data package metadata - experiment tracker, resource tracker, and any data dictionary(s) and results tracker(s) that have been set as open-access or managed-access as of " + byDate + "<br><br>You'll find your shareable data package directory at: " + shareableDir + "<br><br>There is also a readme file and an \"overview\" resource tracker with an indicator of which files are shared in this shareable data package at that location.<br><br>Your shareable data package directory's path is: " + shareablePkgDir + "<br><br> You should:<br><br>1. Inspect your shareable data package, then zip it up once you are satisfied that the correct files have been shared<br>2. Share your zipped up shareable data package directory as managed access but under embargo until " + byDate + " at your selected data repository<br>3. Share your readme file and \"overview\" resource tracker as open access at your selected data repository<br>"
errorFormat = '<span style="color:green;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))
else:
print("failure")
messageText = "<br>Failure - Your shareable data package was NOT created!<br>"
if failType == "dirExists":
messageText = messageText + "<br>It looks like you've already created a \"managed-access-by-date\" shareable data package with a \"by date\" of " + byDate + " today. If you want to overwrite the original version you will have to first delete the original version. The original version of this shareable data package can be found at: " + shareablePkgDir + "<br>"
errorFormat = '<span style="color:red;">{}</span>'
self.userMessageBox.append(errorFormat.format(messageText))