-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_gui.py
1822 lines (1468 loc) · 110 KB
/
main_gui.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from lxml import etree
from loguru import logger
import webbrowser
import atexit
import os
import platform
import shutil
import errno
import datetime
import pprint
# High DPI Scaling aktivieren (Windows-spezifisch)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
# Import der Module zur Verwaltung der Sitzungs-, Provider- und Moduldaten
from gui_session import handle_session_data
from gui_session import get_version_info
from modules.common.helpers.normalize_filename import process_filenames
from modules.common.provider_metadata.handle_provider_metadata import create_provider_template
from modules.common.provider_metadata.handle_provider_metadata import get_provider_metadata
from modules.common.provider_metadata.handle_provider_metadata import write_provider_metadata
from modules.common.provider_metadata.handle_provider_metadata import write_provider_modules
from modules.common.provider_metadata.handle_provider_metadata import load_provider_modules
from modules.common.provider_metadata.handle_provider_metadata import write_provider_rights
from modules.common.provider_metadata.handle_provider_metadata import load_provider_rights
from modules.common.provider_metadata.handle_provider_metadata import write_provider_aggregator_info
from modules.common.provider_metadata.handle_provider_metadata import load_provider_aggregator_info
from modules.common.provider_metadata.handle_provider_metadata import load_provider_mapping_definition
from modules.common.provider_metadata.handle_provider_metadata import write_provider_mapping_definition
from modules.common.provider_metadata.handle_provider_script_sets import get_provider_sets
from modules.common.provider_metadata.handle_provider_script_sets import read_provider_set
from modules.common.provider_metadata.handle_provider_script_sets import save_provider_set
from modules.common.provider_metadata.handle_provider_script_sets import delete_provider_set
from modules.connectors import mapping_definition
from modules.common import get_analysis_path
from gui_components import get_module_metadata
from gui_session import handle_thread_actions
# Import der UI-Templates:
from gui_components.ui_templates.main_window import Ui_MainWindow
from gui_components.ui_templates.about_dialog import Ui_aboutDialog
from gui_components.ui_templates.html_info_dialog import Ui_htmlInfoDialog
from gui_components.ui_templates.provider_metadata_dialog import Ui_providerMetadataDialog
from gui_components.ui_templates.provider_scripts_dialog import Ui_providerScriptsDialog
from gui_components.ui_templates.provider_scripts_save_dialog import Ui_providerScriptsSaveDialog
from gui_components.ui_templates.new_provider_dialog import Ui_newProviderDialog
from gui_components.ui_templates.mets_settings_dialog import Ui_metsSettingsDialog
from gui_components.ui_templates.preview_testset_dialog import Ui_previewTestsetDialog
from gui_components.ui_templates.id_enrichment_dialog import Ui_idEnrichmentDialog
from gui_components.ui_templates.transformation_status_dialog import Ui_transformationStatusDialog
from gui_components.ui_templates.analysis_status_dialog import Ui_analysisStatusDialog
from gui_components.ui_templates.analysis_htmlview_dialog import Ui_analysisHtmlViewDialog
from gui_components.ui_templates.oai_input_dialog import Ui_oaiInputDialog
from gui_components.ui_templates.oai_sets_dialog import Ui_oaiSetsDialog
from gui_components.ui_templates.provider_rights_dialog import Ui_provider_rights_Dialog
from gui_components.ui_templates.provider_aggregator_dialog import Ui_provider_aggregator_Dialog
from gui_components.ui_templates.ddbid_generation_dialog import Ui_ddbidGenerationDialog
from gui_components.ui_templates.processing_status_dialog import Ui_processingStatusDialog
from gui_components.ui_templates.mapping_definition_dialog import Ui_mappingDefinitionDialog
from gui_components.ui_templates.mapping_selection_dialog import Ui_mappingSelectionDialog
from gui_components.ui_templates.validation_dialog import Ui_validationDialog
from gui_components.ui_templates.validation_status_dialog import Ui_validationStatusDialog
from gui_components.ui_templates.provider_scripts_configure_user_interaction_dialog import Ui_providerScriptsConfigureUserInteractionDialog
from gui_components.ui_templates.provider_scripts_configure_maintenance_function_dialog import Ui_providerScriptsConfigureMaintenanceFunctionDialog
# Import der Haupt-Prozesssteuerungsmodule:
import transformation_p1
import transformation_p2
# Import der Anreicherungs- und ID-Generierungsmodule:
from utils import enrich_with_uuids
from modules.analysis.identifiers import generate_ddbid_list
# Import des Moduls zum Harvesting:
from modules.common.oai import fetch_oai_records
# Import des Validierungsmoduls:
from modules.analysis.validation import handle_validify_validation
# Import der Cloud-Prozessierung:
from modules.common.cloud import handle_cloud_processing
# Logging einrichten:
root_path = os.path.abspath(".")
logfile_path = "{}/session.log".format(root_path)
logger.remove()
logger.add(sys.stderr, level="DEBUG")
logger.add(logfile_path, rotation="10 MB")
class WorkerSignals(QtCore.QObject):
# Qt Signals zur Kommunikation zwischen GUI und Prozessierung (Threads) definieren
finished = QtCore.pyqtSignal()
error = QtCore.pyqtSignal(tuple)
status = QtCore.pyqtSignal(str)
result = QtCore.pyqtSignal(object)
class Worker(QtCore.QRunnable):
# Definition einer Klasse, die instanziiert werden kann, um Funktionen als Thread einzurichten
def __init__(self, fn, *args, **kwargs):
super(Worker, self).__init__()
self.fn = fn
self.args = args
self.kwargs = kwargs
self.signals = WorkerSignals()
@QtCore.pyqtSlot()
def run(self):
self.fn(*self.args, **self.kwargs)
@logger.catch
class MappingLibraryMainGui(Ui_MainWindow):
def __init__(self, MainWindow):
Ui_MainWindow.__init__(self)
self.setupUi(MainWindow)
self.threadpool = QtCore.QThreadPool() # Threading initialisieren
logger.info("Plattform: Python {}".format(sys.version))
logger.info("Verfügbare CPU-Threads für Multi-Threading: %d" % self.threadpool.maxThreadCount())
# Initialisierung der Versionsinformationen:
self.version_data = get_version_info.load_version_info_from_xml()
logger.info("Data Preparation Tool (Version {}, Branch {}, Git-Revision {}): Neue GUI-Sitzung gestartet.".format(self.version_data["version-number"], self.version_data["branch"], self.version_data["revision"]))
# Initialisierung der Sitzungsvariablen:
self.session_data = None
handle_session_data.prepare_first_run() # Sitzungsdaten vorbereiten
self.session_load_from_xml() # Laden der Sitzungsdaten aus gui_session/session.xml
self.analysis_path = ""
self.analysis_type = ""
self.worker_start = 0
self.worker_end = 0
self.worker_duration = 0
self.processing_status_updater = QtCore.QTimer()
self.root_path = os.path.abspath(".")
self.processing_status_path = os.path.abspath("gui_session/processing_status.xml")
self.currentWebViewUrl = "about:blank"
self.provider_script_sets = []
self.provider_script_set_assignment = {}
self.edit_existing_provider_script_list_item = None
# Initialisierung Qt Custom Data Rules zur MVC-Umsetzung des Providerskript-Dialogs
# Vgl. https://stackoverflow.com/a/40021010/6703963
self.provider_script_isil_role = QtCore.Qt.UserRole + 2
self.provider_script_id_role = QtCore.Qt.UserRole + 3
self.provider_script_name_role = QtCore.Qt.UserRole + 4
self.provider_script_description_role = QtCore.Qt.UserRole + 5
self.provider_script_config_role = QtCore.Qt.UserRole + 6
# Synchronisierung der Sitzungsvariablen mit der UI:
self.session_synchronize_with_gui()
# Befüllen der Provider-Liste:
self.provider_list = []
self.get_provider_list()
provider_preset = self.comboBox_provider.findText(self.session_data["provider"], QtCore.Qt.MatchFixedString)
if provider_preset >= 0:
self.comboBox_provider.setCurrentIndex(provider_preset)
else: # "Provider"-Wert (ISIL) in den Session-Daten mit der Combobox-Auswahl überschreiben, sofern es für den Wert aus der session.xml keinen Input-Ordner (mehr) gibt
self.session_data["provider"] = self.comboBox_provider.currentText()
self.comboBox_provider.currentIndexChanged.connect(self.set_provider_from_list)
self.toolButton_refresh_providers.clicked.connect(self.get_provider_list)
# Übernahme der über GUI-Widgets durchgeführten Änderungen in session_data:
self.checkBox_binaries.clicked.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.checkBox_binaries.isChecked(), "process_binaries"))
self.checkBox_metsmods.clicked.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.checkBox_metsmods.isChecked(), "enable_mets_generation"))
self.checkBox_tektonik_enrichment.clicked.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.checkBox_tektonik_enrichment.isChecked(), "enable_tektonik_enrichment"))
self.checkBox_analysis.clicked.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.checkBox_analysis.isChecked(), "enable_metadata_analysis"))
self.checkBox_metadata_previews.clicked.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.checkBox_metadata_previews.isChecked(), "enable_metadata_preview"))
self.menuToggleRightsInfo.toggled.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.menuToggleRightsInfo.isChecked(), "enrich_rights_info"))
self.menuToggleDdb2017Preprocessing.toggled.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.menuToggleDdb2017Preprocessing.isChecked(), "enable_ddb2017_preprocessing"))
self.menuToggleAggregatorInfo.toggled.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.menuToggleAggregatorInfo.isChecked(), "enrich_aggregator_info"))
self.menuToggleObsoleteObjects.toggled.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.menuToggleObsoleteObjects.isChecked(), "handle_obsolete_objects"))
self.menuToggleMappingDefinition.toggled.connect(lambda: handle_session_data.write_gui_change_to_session_data(self.session_data, self.menuToggleMappingDefinition.isChecked(), "apply_mapping_definition"))
# Initialisieren weiterer UI-Elemente:
self.aboutDialog = QtWidgets.QDialog()
self.aboutDialog_ui = Ui_aboutDialog()
self.aboutDialog_ui.setupUi(self.aboutDialog)
self.htmlInfoDialog = QtWidgets.QDialog()
self.htmlInfoDialog_ui = Ui_htmlInfoDialog()
self.htmlInfoDialog_ui.setupUi(self.htmlInfoDialog)
self.providerMetadataDialog = QtWidgets.QDialog()
self.providerMetadataDialog_ui = Ui_providerMetadataDialog()
self.providerMetadataDialog_ui.setupUi(self.providerMetadataDialog)
self.providerScriptsDialog = QtWidgets.QDialog()
self.providerScriptsDialog_ui = Ui_providerScriptsDialog()
self.providerScriptsDialog_ui.setupUi(self.providerScriptsDialog)
self.providerScriptSaveDialog = QtWidgets.QDialog()
self.providerScriptSaveDialog_ui = Ui_providerScriptsSaveDialog()
self.providerScriptSaveDialog_ui.setupUi(self.providerScriptSaveDialog)
self.providerScriptsConfigureUserInteractionDialog = QtWidgets.QDialog()
self.providerScriptsConfigureUserInteractionDialog_ui = Ui_providerScriptsConfigureUserInteractionDialog()
self.providerScriptsConfigureUserInteractionDialog_ui.setupUi(self.providerScriptsConfigureUserInteractionDialog)
self.providerScriptsConfigureMaintenanceFunctionDialog = QtWidgets.QDialog()
self.providerScriptsConfigureMaintenanceFunctionDialog_ui = Ui_providerScriptsConfigureMaintenanceFunctionDialog()
self.providerScriptsConfigureMaintenanceFunctionDialog_ui.setupUi(self.providerScriptsConfigureMaintenanceFunctionDialog)
self.newProviderDialog = QtWidgets.QDialog()
self.newProviderDialog_ui = Ui_newProviderDialog()
self.newProviderDialog_ui.setupUi(self.newProviderDialog)
self.metsSettingsDialog = QtWidgets.QDialog()
self.metsSettingsDialog_ui = Ui_metsSettingsDialog()
self.metsSettingsDialog_ui.setupUi(self.metsSettingsDialog)
self.previewTestsetDialog = QtWidgets.QDialog()
self.previewTestsetDialog_ui = Ui_previewTestsetDialog()
self.previewTestsetDialog_ui.setupUi(self.previewTestsetDialog)
self.idEnrichmentDialog = QtWidgets.QDialog()
self.idEnrichmentDialog_ui = Ui_idEnrichmentDialog()
self.idEnrichmentDialog_ui.setupUi(self.idEnrichmentDialog)
self.transformationStatusDialog = QtWidgets.QDialog()
self.transformationStatusDialog_ui = Ui_transformationStatusDialog()
self.transformationStatusDialog_ui.setupUi(self.transformationStatusDialog)
self.analysisStatusDialog = QtWidgets.QDialog()
self.analysisStatusDialog_ui = Ui_analysisStatusDialog()
self.analysisStatusDialog_ui.setupUi(self.analysisStatusDialog)
self.validationStatusDialog = QtWidgets.QDialog()
self.validationStatusDialog_ui = Ui_validationStatusDialog()
self.validationStatusDialog_ui.setupUi(self.validationStatusDialog)
self.validationDialog = QtWidgets.QDialog()
self.validationDialog_ui = Ui_validationDialog()
self.validationDialog_ui.setupUi(self.validationDialog)
self.analysisHtmlViewDialog = QtWidgets.QDialog()
self.analysisHtmlViewDialog_ui = Ui_analysisHtmlViewDialog()
self.analysisHtmlViewDialog_ui.setupUi(self.analysisHtmlViewDialog)
self.oaiInputDialog = QtWidgets.QDialog()
self.oaiInputDialog_ui = Ui_oaiInputDialog()
self.oaiInputDialog_ui.setupUi(self.oaiInputDialog)
self.oaiSetsDialog = QtWidgets.QDialog()
self.oaiSetsDialog_ui = Ui_oaiSetsDialog()
self.oaiSetsDialog_ui.setupUi(self.oaiSetsDialog)
self.providerRightsDialog = QtWidgets.QDialog()
self.providerRightsDialog_ui = Ui_provider_rights_Dialog()
self.providerRightsDialog_ui.setupUi(self.providerRightsDialog)
self.providerAggregatorDialog = QtWidgets.QDialog()
self.providerAggregatorDialog_ui = Ui_provider_aggregator_Dialog()
self.providerAggregatorDialog_ui.setupUi(self.providerAggregatorDialog)
self.ddbidGenerationDialog = QtWidgets.QDialog()
self.ddbidGenerationDialog_ui = Ui_ddbidGenerationDialog()
self.ddbidGenerationDialog_ui.setupUi(self.ddbidGenerationDialog)
self.processingStatusDialog = QtWidgets.QDialog()
self.processingStatusDialog_ui = Ui_processingStatusDialog()
self.processingStatusDialog_ui.setupUi(self.processingStatusDialog)
self.mappingDefinitionDialog = QtWidgets.QDialog()
self.mappingDefinitionDialog_ui = Ui_mappingDefinitionDialog()
self.mappingDefinitionDialog_ui.setupUi(self.mappingDefinitionDialog)
self.mappingSelectionDialog = QtWidgets.QDialog()
self.mappingSelectionDialog_ui = Ui_mappingSelectionDialog()
self.mappingSelectionDialog_ui.setupUi(self.mappingSelectionDialog)
# Einblenden des Intro-Dialogs, falls es sich um den ersten Start des Tools handelt:
if handle_session_data.synchronize_with_gui(self.session_data["firstrun"]) is True:
self.open_intro_dialog()
self.session_data["firstrun"] = "False" # bei den nachfolgenden Programmstarts soll das Fenster nicht mehr angezeigt werden
# Versionsinformationen synchronisieren:
self.aboutDialog_ui.label_about_dialog_version.setText("Version {} ({})".format(self.version_data["version-number"], self.version_data["branch"]))
self.aboutDialog_ui.label_about_dialog_revision.setText("Revision: {}".format(self.version_data["revision"]))
# Felder im METS-Einstellungsdialog synchronisieren:
self.metsSettingsDialog_ui.lineEdit_mets_application_profile.setText(self.session_data["mets_application_profile"])
self.metsSettingsDialog_ui.lineEdit_mets_logo_url.setText(self.session_data["mets_logo_url"])
self.metsSettingsDialog_ui.lineEdit_mets_mail_address.setText(self.session_data["mets_mail_address"])
self.metsSettingsDialog_ui.lineEdit_mets_url_prefix.setText(self.session_data["mets_url_prefix"])
# Prozesssteuerung:
self.pushButton_startTransformation.clicked.connect(self.handle_transformation_p1) # Start der Transformation
self.pushButton_startAnalyse.clicked.connect(self.handle_transformation_p2) # Start der Analyse
# Menüpunkte im Hauptfenster:
self.pushButton_provider_metadata.clicked.connect(self.open_provider_metadata_dialog)
self.pushButton_provider_scripts.clicked.connect(self.open_provider_scripts_dialog)
self.toolButton_new_provider.clicked.connect(lambda: self.newProviderDialog.show())
self.toolButton_metsmods_settings_dialog.clicked.connect(lambda: self.metsSettingsDialog.show())
self.toolButton_preview_testset.clicked.connect(self.open_preview_testset_dialog)
self.menuInfoAbout.triggered.connect(self.open_about_dialog)
self.menuInfoIntroscreen.triggered.connect(self.open_intro_dialog)
self.menuInfoDDBpro.triggered.connect(lambda: self.open_in_browser("https://pro.deutsche-digitale-bibliothek.de/fachstelle-archiv"))
self.action_fetch_from_oai.triggered.connect(lambda: self.oaiInputDialog.show())
self.action_submit_cloud_transformation_job.triggered.connect(lambda: self.handle_cloud_transformation())
self.actionData_Preparation_Tool_beenden.triggered.connect(lambda: sys.exit())
self.actionLoadStandards.triggered.connect(self.session_load_defaults)
self.menuEnrichIDs.triggered.connect(lambda: self.idEnrichmentDialog.show())
self.menuRightsInfo.triggered.connect(lambda: self.open_rights_info_dialog())
self.menuAggregatorInfo.triggered.connect(lambda: self.open_aggregator_info_dialog())
self.menuGenerateDDBIDs.triggered.connect(lambda: self.ddbidGenerationDialog.show())
self.menuMappingDefinition.triggered.connect(lambda: self.open_mapping_definition_dialog())
self.menuSelectMappingDefinition.triggered.connect(lambda: self.open_mapping_selection_dialog())
self.menuOpenValidationDialog.triggered.connect(lambda: self.validationDialog.show())
# Menüpunkte im About-Dialog:
self.aboutDialog_ui.buttonOpenGithub.clicked.connect(lambda: self.open_in_browser("https://github.com/Deutsche-Digitale-Bibliothek/ddblabs-datapreparationtool"))
self.aboutDialog_ui.pushButton_opensource_components.clicked.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(os.path.abspath("./gui_components/ui_templates/resources/html/thirdparty.html"))))
# Menüpunkte im Dialog "Neuer Provider":
self.newProviderDialog_ui.buttonBox_new_provider.accepted.connect(self.create_new_provider)
# Menüpunkte im Dialog "Archiv-Metadaten bearbeiten":
self.providerMetadataDialog_ui.buttonBox_provider_metadata.accepted.connect(self.save_provider_data)
# Menüpunkte im Dialog "Providerspezifische Anpassungen":
self.providerScriptsDialog_ui.buttonBox_providerspecific_modules.accepted.connect(self.save_provider_modules)
self.providerScriptsDialog_ui.comboBox_select_saved_providerscript_definition.currentIndexChanged.connect(self.update_provider_script_set_description)
self.providerScriptsDialog_ui.toolButton_apply_definition.clicked.connect(self.apply_provider_script_set)
self.providerScriptsDialog_ui.toolButton_delete_definition.clicked.connect(self.delete_provider_script_set)
self.providerScriptsDialog_ui.pushButton_save_definition.clicked.connect(lambda: self.providerScriptSaveDialog.show())
self.providerScriptsDialog_ui.pushButton_add_to_workflow.clicked.connect(self.add_provider_script_selection_to_workflow)
self.providerScriptsDialog_ui.pushButton_remove_item_from_workflow.clicked.connect(self.remove_provider_script_from_workflow)
self.providerScriptsDialog_ui.toolButton_add_pause_to_workflow.clicked.connect(self.open_provider_scripts_configure_user_interaction_dialog)
self.providerScriptsDialog_ui.toolButton_add_transformation_settings_change.clicked.connect(self.open_provider_scripts_configure_maintenance_dialog)
self.providerScriptsDialog_ui.toolButton_configure_workflow_element.clicked.connect(self.trigger_provider_scripts_configuration_dialog)
self.providerScriptsDialog_ui.listWidget_providerscript_workflow.itemSelectionChanged.connect(self.toggle_workflow_element_configurability)
# Menüpunkte im Dialog "Providerspezifische Anpassungen" --> "Neue Zuordnung speichern":
self.providerScriptSaveDialog_ui.buttonBox_save_providerscript_set.accepted.connect(self.create_provider_script_set)
# Menüpunkte im Dialog "Providerspezifische Anpassungen" --> "Vorprozessierungsschritt konfigurieren":
self.providerScriptsConfigureMaintenanceFunctionDialog_ui.buttonBox_providerscripts_maintenance_configuration.accepted.connect(self.save_provider_scripts_maintenance_config)
# Menüpunkte im Dialog "Providerspezifische Anpassungen" --> "Nutzerinteraktion konfigurieren":
self.providerScriptsConfigureUserInteractionDialog_ui.buttonBox_providerscripts_user_interaction_configuration.accepted.connect(self.save_provider_script_user_interaction_config)
# Menüpunkte im Dialog "Einstellungen zur METS/MODS-Generierung":
self.metsSettingsDialog_ui.buttonBox_mets_settings.accepted.connect(self.save_mets_settings)
# Menüpunkte im Dialog "Testset für Voransichten":
self.previewTestsetDialog_ui.buttonBox_preview_testset.accepted.connect(self.save_preview_testset)
# Menüpunkte im Dialog "Identifier anreichern":
self.idEnrichmentDialog_ui.toolButton_id_enrichment_path.clicked.connect(lambda: self.add_files_to_list_widget(self.idEnrichmentDialog_ui.listWidget_id_enrichment_files)) # Slot-Signal-Verbindungen in die Hauptklasse verschoben, damit die Connections nicht mehrfach gesetzt (durch mehrmaliges Öffnen und damit Ausführen von open_id_enrichment_dialog) und somit mehrfach ausgeführt werden
self.idEnrichmentDialog_ui.toolButton_id_enrichment_remove_entry.clicked.connect(
lambda: self.remove_listwidget_entry(self.idEnrichmentDialog_ui.listWidget_id_enrichment_files))
self.idEnrichmentDialog_ui.buttonBox_id_enrichment.accepted.connect(self.handle_id_enrichment)
# Menüpunkte im Transformations-Status-Dialog:
self.transformationStatusDialog_ui.pushButton_open_transformation_output.clicked.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(os.path.abspath("./data_output" + "/" + self.session_data["provider"].replace("-", "_")))))
self.transformationStatusDialog_ui.pushButton_analysis_after_transformation.clicked.connect(self.bootstrap_p2_after_p1)
self.transformationStatusDialog_ui.toolButton_transformation_error_show_log.clicked.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(os.path.abspath("./session.log"))))
self.transformationStatusDialog_ui.pushButton_cancel_transformation_process.clicked.connect(lambda: self.processing_cleanup("transformation_p1"))
# Menüpunkte im Analyse-Status-Dialog:
self.analysisStatusDialog_ui.pushButton_statistics.clicked.connect(lambda: self.handle_analysis_htmlview_dialog("statistics"))
self.analysisStatusDialog_ui.pushButton_technical_validation.clicked.connect(lambda: self.handle_analysis_htmlview_dialog("technical_validation"))
self.analysisStatusDialog_ui.pushButton_html_previews.clicked.connect(lambda: self.handle_analysis_htmlview_dialog("html_previews"))
self.analysisStatusDialog_ui.toolButton_analysis_error_show_log.clicked.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(os.path.abspath("./session.log"))))
self.analysisStatusDialog_ui.pushButton_cancel_analysis_process.clicked.connect(lambda: self.processing_cleanup("transformation_p2"))
# Menüpunkte im Validierungs-Status-Dialog:
self.validationStatusDialog_ui.pushButton_open_validation_results.clicked.connect(lambda: self.handle_analysis_htmlview_dialog("validify_validation"))
self.validationStatusDialog_ui.pushButton_cancel_validation_process.clicked.connect(lambda: self.processing_cleanup("validation"))
# Menüpunkte im Dialog "Analyseergebnisse":
self.analysisHtmlViewDialog_ui.pushButton_open_statistics_in_browser.clicked.connect(lambda: self.open_in_browser(self.currentWebViewUrl))
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.currentIndexChanged.connect(self.load_web_view_url)
self.analysisHtmlViewDialog_ui.comboBox_filter_type.currentIndexChanged.connect(self.get_filtered_preview_list)
# Menüpunkte im OAI-Input-Dialog:
self.oaiInputDialog_ui.buttonBox.accepted.connect(self.fetch_from_oai)
self.oaiInputDialog_ui.toolButton_list_available_sets.clicked.connect(self.get_oai_sets)
# Menüpunkte im Provider-Rights-Dialog:
self.providerRightsDialog_ui.buttonBox.accepted.connect(lambda: self.close_rights_info_dialog())
self.providerRightsDialog_ui.toolButton_open_rights_info.clicked.connect(lambda: self.open_in_browser("https://pro.deutsche-digitale-bibliothek.de/lizenzen-und-rechtehinweise-der-lizenzkorb-der-deutschen-digitalen-bibliothek"))
# Menüpunkte im Provider-Aggregator-Dialog:
self.providerAggregatorDialog_ui.buttonBox.accepted.connect(lambda: self.close_aggregator_info_dialog())
# Menüpunkte im DDB-ID-Generierungs-Dialog:
self.ddbidGenerationDialog_ui.toolButton_ddbid_generation_path.clicked.connect(lambda: self.add_files_to_list_widget(self.ddbidGenerationDialog_ui.listWidget_ddbid_generation_files))
self.ddbidGenerationDialog_ui.toolButton_ddbid_generation_remove_entry.clicked.connect(lambda: self.remove_listwidget_entry(self.ddbidGenerationDialog_ui.listWidget_ddbid_generation_files))
self.ddbidGenerationDialog_ui.buttonBox_ddbid_generation.accepted.connect(lambda: self.handle_ddb_id_generation())
# Menüpunkte im Mapping-Definition-Dialog:
self.mappingDefinitionDialog_ui.pushButton_add_row.clicked.connect(lambda: self.mapping_definition_create_row(None, None, None, None, None))
self.mappingDefinitionDialog_ui.pushButton_delete_row.clicked.connect(lambda: self.mapping_definition_delete_row())
self.mappingDefinitionDialog_ui.buttonBox.accepted.connect(self.mapping_definition_write_def)
# Menüpunkte im Mapping-Selection-Dialog:
self.mappingSelectionDialog_ui.buttonBox.accepted.connect(self.close_mapping_selection_dialog)
# Menüpunkte im Validierungs-Dialog:
self.validationDialog_ui.toolButton_select_files.clicked.connect(lambda: self.add_files_to_list_widget(self.validationDialog_ui.listWidget_validation_files))
self.validationDialog_ui.toolButton_remove_file_entry.clicked.connect(lambda: self.remove_listwidget_entry(self.validationDialog_ui.listWidget_validation_files))
self.validationDialog_ui.buttonBox_validation_dialog.accepted.connect(lambda: self.bootstrap_validation())
# Um beim Beenden des Programms (ob über den Menüpunkt Datei->Beenden oder auf anderem Wege) u.a. die Sitzungsdaten zuverlässig zu speichern, wird ein Hook registriert:
atexit.register(lambda: self.exit_application())
def handle_transformation_p1(self):
logger.info("transformation_p1 wurde durch GUI aufgerufen.")
# Deaktivieren der Eingabemöglichkeiten während der Prozessierung:
self.disable_processing_controls()
self.statusbar.showMessage("Transformation gestartet.")
self.transformationStatusDialog_ui.frame_transformation_error.setVisible(False)
self.transformationStatusDialog_ui.label_transformation_status.setText("")
self.transformationStatusDialog.show()
self.transformationStatusDialog_ui.stackedWidget.setCurrentIndex(0)
# Abruf der Status-Info zur Anzeige in der GUI:
self.processing_status_updater.timeout.connect(lambda: update_status_p1())
self.processing_status_updater.start(1000)
# Zurücksetzen des Thread-Status
handle_thread_actions.save_to_xml("reset_actions", self.root_path)
# Initialisieren des Workers, um die Transformation in einem separaten Thread zu starten
worker_p1 = Worker(lambda: transformation_p1.run_transformation_p1(root_path=self.root_path, session_data=self.session_data, is_gui_session=True))
worker_p1.signals.destroyed.connect(lambda: finished_p1())
self.worker_start = datetime.datetime.now()
self.threadpool.start(worker_p1)
def update_status_p1():
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
processing_step = processing_status["processing_step"]
status_message = processing_status["status_message"]
raise_user_interaction = processing_status["raise_user_interaction"]
user_interaction_message = processing_status["user_interaction_message"]
user_interaction_input_files = processing_status["user_interaction_input_files"]
if processing_step is not None:
self.transformationStatusDialog_ui.progressBar.setValue(int(processing_step))
self.transformationStatusDialog_ui.label_transformation_status.setText(status_message)
if raise_user_interaction != "0":
# Pausieren der Prozessierung für Workflow-Modul "Nutzerinteraktion"
self.processing_status_updater.stop()
if user_interaction_message is not None:
self.transformationStatusDialog_ui.plainTextEdit_user_interaction_description.setPlainText(user_interaction_message)
self.transformationStatusDialog_ui.stackedWidget.setCurrentIndex(2)
self.transformationStatusDialog_ui.pushButton_user_interaction_open_files.disconnect()
self.transformationStatusDialog_ui.pushButton_user_interaction_continue.disconnect()
self.transformationStatusDialog_ui.pushButton_user_interaction_open_files.clicked.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(user_interaction_input_files)))
self.transformationStatusDialog_ui.pushButton_user_interaction_continue.clicked.connect(lambda: continue_after_user_interaction_p1())
def continue_after_user_interaction_p1():
# Fortsetzen der Prozessierung nach Abschluss der Nutzerinteraktion
handle_session_data.write_processing_status(root_path, raise_user_interaction="0")
self.transformationStatusDialog_ui.stackedWidget.setCurrentIndex(0)
self.processing_status_updater.start(1000)
def finished_p1():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.processing_status_updater.stop()
self.worker_end = datetime.datetime.now()
self.worker_duration = str(self.worker_end-self.worker_start)
logger.info("Prozessierungsdauer: {}".format(self.worker_duration))
self.transformationStatusDialog_ui.label_transformation_duration.setText(self.worker_duration)
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
if processing_status["error_status"] != "0":
self.transformationStatusDialog_ui.frame_transformation_error.setVisible(True)
self.statusbar.showMessage("Transformation abgeschlossen.")
self.enable_processing_controls()
self.transformationStatusDialog_ui.stackedWidget.setCurrentIndex(1)
def handle_transformation_p2(self):
provider_path = get_analysis_path.get_path(self.session_data)
if os.path.isdir(provider_path + "/" + "findbuch"):
logger.info("transformation_p2 wurde durch GUI aufgerufen.")
# Deaktivieren der Eingabemöglichkeiten während der Prozessierung:
self.disable_processing_controls()
self.statusbar.showMessage("Analyse gestartet.")
self.analysisStatusDialog_ui.frame_preview_duration.setVisible(False)
if self.session_data["preview_testset_ids"] is None and self.session_data["enable_metadata_preview"] == "True":
self.analysisStatusDialog_ui.frame_preview_duration.setVisible(True)
self.analysisStatusDialog_ui.frame_analysis_error.setVisible(False)
self.analysisStatusDialog_ui.label_analysis_status.setText("")
self.analysisStatusDialog.show()
self.analysisStatusDialog_ui.stackedWidget.setCurrentIndex(0)
# Abruf der Status-Info zur Anzeige in der GUI:
self.processing_status_updater.timeout.connect(lambda: update_status_p2())
self.processing_status_updater.start(1000)
# Zurücksetzen des Thread-Status
handle_thread_actions.save_to_xml("reset_actions", self.root_path)
# Initialisieren des Workers, um die Analyse in einem separaten Thread zu starten
worker_p2 = Worker(lambda: transformation_p2.run_transformation_p2(root_path=self.root_path, session_data=self.session_data, is_gui_session=True))
worker_p2.signals.destroyed.connect(lambda: finished_p2())
self.worker_start = datetime.datetime.now()
self.threadpool.start(worker_p2)
else:
logger.info("transformation_p2 wurde nicht ausgeführt, da für den Provider {} keine Output-Dateien existieren.".format(self.session_data["provider"]))
self.statusbar.showMessage("Keine Ausgabe-Dateien zur Analyse verfügbar.")
def update_status_p2():
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
processing_step = processing_status["processing_step"]
status_message = processing_status["status_message"]
self.analysisStatusDialog_ui.progressBar.setValue(int(processing_step))
self.analysisStatusDialog_ui.label_analysis_status.setText(status_message)
def finished_p2():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.processing_status_updater.stop()
self.worker_end = datetime.datetime.now()
self.worker_duration = str(self.worker_end - self.worker_start)
logger.info("Prozessierungsdauer: {}".format(self.worker_duration))
self.analysisStatusDialog_ui.label_analysis_duration.setText(self.worker_duration)
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
if processing_status["error_status"] != "0":
self.analysisStatusDialog_ui.frame_analysis_error.setVisible(True)
self.statusbar.showMessage("Analyse abgeschlossen.")
self.enable_processing_controls()
self.analysisStatusDialog_ui.stackedWidget.setCurrentIndex(1)
def bootstrap_p2_after_p1(self):
self.transformationStatusDialog.close()
self.handle_transformation_p2()
def handle_cloud_transformation(self):
"""Aufruf der Methode modules.common.cloud.handle_cloud_processing -> submit_transformation_job
Analog zu handle_transformation_p1 und handle_transformation_p2 wird die Methode über einen Worker-Thread ausgeführt.
In der GUI wird der Fortschritt über die Statusleiste sowie die Logmeldungen in der Konsole kommuniziert.
Nach Beendigung des Worker-Threads wird die Methode finished_cloud_transformation() aufgerufen.
"""
logger.info("Cloud-Transformation wurde durch GUI aufgerufen.")
self.disable_processing_controls()
self.statusbar.showMessage("Datenlieferung für Cloud-Transformation vorbereiten...")
worker_prepare_cloud_dataset = Worker(lambda: handle_cloud_processing.submit_transformation_job(root_path=self.root_path, session_data=self.session_data))
worker_prepare_cloud_dataset.signals.destroyed.connect(lambda: finished_cloud_transformation())
self.worker_start = datetime.datetime.now()
self.threadpool.start(worker_prepare_cloud_dataset)
def finished_cloud_transformation():
"""Aufgerufen nach Beendigung des Worker-Threads 'worker_prepare_cloud_dataset'.
Die Prozesssteuerungsschaltflächen der GUI werden wieder aktiviert.
"""
result_message = "Abgeschlossen: Datenlieferung auf FTP-Server abgelegt."
logger.info(result_message)
self.statusbar.showMessage(result_message)
self.enable_processing_controls()
def handle_validation(self, input_files: list, rule_definition: str):
logger.info("Validierung wurde durch GUI aufgerufen.")
# Deaktivieren der Eingabemöglichkeiten während der Prozessierung:
self.disable_processing_controls()
self.statusbar.showMessage("Validierung gestartet.")
self.validationStatusDialog_ui.frame_validation_error.setVisible(False)
self.validationStatusDialog_ui.label_validation_status.setText("")
self.validationStatusDialog.show()
self.validationStatusDialog_ui.stackedWidget.setCurrentIndex(0)
# Abruf der Status-Info zur Anzeige in der GUI:
self.processing_status_updater.timeout.connect(lambda: update_status_validation())
self.processing_status_updater.start(1000)
# Zurücksetzen des Thread-Status
handle_thread_actions.save_to_xml("reset_actions", self.root_path)
# Initialisieren des Workers, um die Validierung in einem separaten Thread zu starten
worker_validation = Worker(lambda: handle_validify_validation.handle_validation(root_path=self.root_path, input_files=input_files, rule_definition=rule_definition))
worker_validation.signals.destroyed.connect(lambda: finished_validation())
self.worker_start = datetime.datetime.now()
self.threadpool.start(worker_validation)
def update_status_validation():
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
processing_step = processing_status["processing_step"]
status_message = processing_status["status_message"]
self.validationStatusDialog_ui.progressBar.setValue(int(processing_step))
self.validationStatusDialog_ui.label_validation_status.setText(status_message)
def finished_validation():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.processing_status_updater.stop()
self.worker_end = datetime.datetime.now()
self.worker_duration = str(self.worker_end - self.worker_start)
logger.info("Prozessierungsdauer: {}".format(self.worker_duration))
self.validationStatusDialog_ui.label_validation_duration.setText(self.worker_duration)
processing_status = handle_session_data.get_processing_status(self.root_path)
if processing_status is not None:
if processing_status["error_status"] != "0":
self.validationStatusDialog_ui.frame_validation_error.setVisible(True)
self.statusbar.showMessage("Validierung abgeschlossen.")
if len(self.comboBox_provider.currentText()) == 0:
self.enable_processing_controls(is_first_launch=True)
else:
self.enable_processing_controls()
self.validationStatusDialog_ui.stackedWidget.setCurrentIndex(1)
def processing_cleanup(self, processing_type):
# Nach nutzergesteuertem Abbruch der Prozessierung soll der Output-Ordner aufgeräumt sowie zentrale Variablen (cwd) zurückgesetzt werden.
# UI deaktivieren:
self.transformationStatusDialog_ui.pushButton_cancel_transformation_process.setDisabled(True)
self.analysisStatusDialog_ui.pushButton_cancel_analysis_process.setDisabled(True)
self.validationStatusDialog_ui.pushButton_cancel_validation_process.setDisabled(True)
# Variable stop_processing=True setzen
handle_thread_actions.save_to_xml("stop_thread", self.root_path)
# Auf Beenden des Threads warten
logger.info("Prozessierung durch Nutzer abgebrochen. Warte auf Beendigung des Worker-Threads ...")
self.threadpool.waitForDone()
logger.info("Worker-Thread erfolgreich beendet.")
# Variable stop_processing=False setzen
handle_thread_actions.save_to_xml("reset_actions", self.root_path)
def cancel_p1():
self.processing_status_updater.stop()
self.enable_processing_controls()
def cancel_p2():
self.processing_status_updater.stop()
self.enable_processing_controls()
def cancel_validation():
self.processing_status_updater.stop()
self.enable_processing_controls()
# Wechsel in das Root-Verzeichnis der Anwendung
os.chdir(self.root_path)
# Ermitteln des zu bereinigenden Ausgabe-Ordners
output_path = get_analysis_path.get_path(self.session_data)
if processing_type == "transformation_p1":
logger.info("Starte Bereinigung für abgebrochenen Transformations-Prozess ...")
cancel_p1()
self.transformationStatusDialog_ui.pushButton_cancel_transformation_process.setDisabled(True)
[os.remove(output_path + "/" + f) for f in os.listdir(output_path) if os.path.isfile(f)]
delete_folders = ["findbuch", "tektonik"]
[shutil.rmtree(output_path + "/" + delete_folder) for delete_folder in delete_folders if os.path.isdir(output_path + "/" + delete_folder)] # Transformations-Ordner entfernen
logger.info("Bereinigung für abgebrochenen Transformations-Prozess abgeschlossen.")
self.transformationStatusDialog.close()
elif processing_type == "transformation_p2":
logger.info("Starte Bereinigung für abgebrochenen Analyse-Prozess ...")
cancel_p2()
self.analysisStatusDialog_ui.pushButton_cancel_analysis_process.setDisabled(True)
[os.remove(output_path + "/" + f) for f in os.listdir(output_path) if f.endswith(".txt")] # Statistik-Txt-Dateien entfernen
[os.remove(output_path + "/tektonik/" + f) for f in os.listdir(output_path + "/" + "tektonik") if f.startswith("enriched_")] # angereicherte Tektonik-Datei entfernen
delete_folders = ["preview", "Statistik", "Technische_Validierung"]
[shutil.rmtree(output_path + "/" + delete_folder) for delete_folder in delete_folders if os.path.isdir(output_path + "/" + delete_folder)] # Analyse-Ordner entfernen
logger.info("Bereinigung für abgebrochenen Analyse-Prozess abgeschlossen.")
self.analysisStatusDialog.close()
elif processing_type == "validation":
logger.info("Starte Bereinigung für abgebrochenen Validierungs-Prozess ...")
cancel_validation()
logger.info("Bereinigung für abgebrochenen Validierungs-Prozess abgeschlossen.")
self.transformationStatusDialog_ui.pushButton_cancel_transformation_process.setDisabled(False)
self.analysisStatusDialog_ui.pushButton_cancel_analysis_process.setDisabled(False)
self.validationStatusDialog_ui.pushButton_cancel_validation_process.setDisabled(False)
self.statusbar.showMessage("test")
def handle_id_enrichment(self):
logger.info("ID-Enrichment wurde durch GUI aufgerufen.")
self.idEnrichmentDialog_ui.buttonBox_id_enrichment.setEnabled(False)
self.disable_processing_controls()
# Übergabe der im GUI gesetzten Einstellungen:
enrichment_settings = {}
enrichment_settings["replace_existing_ids"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_replace_existing.isChecked()
enrichment_settings["id_prefix"] = self.idEnrichmentDialog_ui.lineEdit_id_prefix.text()
enrichment_settings["process_findbuch"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_findbuch.isChecked()
enrichment_settings["process_tektonik"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_tektonik.isChecked()
enrichment_settings["process_class"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_class.isChecked()
enrichment_settings["process_series"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_series.isChecked()
enrichment_settings["process_file"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_file.isChecked()
enrichment_settings["process_item"] = self.idEnrichmentDialog_ui.checkBox_id_enrichment_process_item.isChecked()
# Ermitteln der ausgewählten Input-Dateien:
input_file_list = []
for i in range(self.idEnrichmentDialog_ui.listWidget_id_enrichment_files.count()):
input_file_list.append(self.idEnrichmentDialog_ui.listWidget_id_enrichment_files.item(i).text())
#input_file_list = self.idEnrichmentDialog_ui.listWidget_id_enrichment_files
self.statusbar.showMessage("Anreicherungsprozess gestartet.")
# Initialisieren des Workers, um den Anreicherungsprozess in einem separaten Thread zu starten
worker_id_enrichment = Worker(lambda: enrich_with_uuids.process_enrichment(input_file_list, enrichment_settings, is_gui_session=True))
worker_id_enrichment.signals.destroyed.connect(lambda: finished_id_enrichment())
self.threadpool.start(worker_id_enrichment)
def finished_id_enrichment():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.statusbar.showMessage("Anreicherungsprozess abgeschlossen.")
self.idEnrichmentDialog_ui.buttonBox_id_enrichment.setEnabled(True)
self.enable_processing_controls()
self.handle_util_result("ID-Anreicherung", "./utils/xml_enriched_with_uuids")
def handle_ddb_id_generation(self):
logger.info("DDB-ID-Generierung wurde durch GUI aufgerufen.")
self.ddbidGenerationDialog_ui.buttonBox_ddbid_generation.setEnabled(False)
self.disable_processing_controls()
# Übergabe der im GUI gesetzten Einstellungen:
ddb_id_generation_settings = {}
ddb_id_generation_settings["provider_id"] = self.ddbidGenerationDialog_ui.lineEdit_provider_id.text()
ddb_id_generation_settings["process_findbuch"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_findbuch.isChecked()
ddb_id_generation_settings["process_tektonik"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_tektonik.isChecked()
ddb_id_generation_settings["process_class"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_class.isChecked()
ddb_id_generation_settings["process_series"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_series.isChecked()
ddb_id_generation_settings["process_file"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_file.isChecked()
ddb_id_generation_settings["process_item"] = self.ddbidGenerationDialog_ui.checkBox_ddbid_generation_process_item.isChecked()
# Ermitteln der ausgewählten Input-Dateien:
input_file_list = []
for i in range(self.ddbidGenerationDialog_ui.listWidget_ddbid_generation_files.count()):
input_file_list.append(self.ddbidGenerationDialog_ui.listWidget_ddbid_generation_files.item(i).text())
self.statusbar.showMessage("DDB-ID-Generierung gestartet.")
# Initialisieren des Workers, um den Generierungssprozess in einem separaten Thread zu starten
worker_ddbid_generation = Worker(lambda: generate_ddbid_list.process_ddbids(input_file_list, ddb_id_generation_settings, is_gui_session=True))
worker_ddbid_generation.signals.destroyed.connect(lambda: finished_ddb_id_generation())
self.threadpool.start(worker_ddbid_generation)
def finished_ddb_id_generation():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.statusbar.showMessage("DDB-ID-Generierung abgeschlossen.")
self.ddbidGenerationDialog_ui.buttonBox_ddbid_generation.setEnabled(True)
self.enable_processing_controls()
self.handle_util_result("DDB-ID-Generierung", "./utils/ddb_id_lists")
def bootstrap_validation(self):
input_file_list = []
for i in range(self.validationDialog_ui.listWidget_validation_files.count()):
input_file_list.append(self.validationDialog_ui.listWidget_validation_files.item(i).text())
rule_definition_selection = self.validationDialog_ui.comboBox_schema_selection.currentText()
if rule_definition_selection == "EAD(DDB) Findbuch":
self.handle_validation(input_file_list, rule_definition="eadddb_findbuch")
elif rule_definition_selection == "EAD(DDB) Tektonik":
self.handle_validation(input_file_list, rule_definition="eadddb_tektonik")
def fetch_from_oai(self):
# Dateien per OAI-PMH anziehen und in data_input/{ISIL} ablegen. Parameter werden aus dem OAI-Input-Dialog übernommen
logger.info("OAI-Harvester wurde durch GUI aufgerufen.")
self.oaiInputDialog_ui.buttonBox.setEnabled(False)
oai_output_folder = "data_input/" + self.session_data["provider"].replace("-", "_") + "/"
oai_url = self.oaiInputDialog_ui.lineEdit_oai_url.text()
oai_metadata_prefix = self.oaiInputDialog_ui.lineEdit_metadata_prefix.text()
oai_identifier = self.oaiInputDialog_ui.lineEdit_oai_identifier.text()
if oai_metadata_prefix == "":
oai_metadata_prefix = None
oai_set_spec = self.oaiInputDialog_ui.lineEdit_oai_set.text()
if oai_set_spec == "":
oai_set_spec = None
oai_from_date = self.oaiInputDialog_ui.lineEdit_oai_from_date.text()
if oai_from_date == "":
oai_from_date = None
if oai_identifier == "":
oai_identifier = None
if self.oaiInputDialog_ui.radioButton_oai_multiple.isChecked():
oai_verb = "ListRecords"
oai_parameters = [oai_output_folder, oai_url, oai_metadata_prefix, oai_set_spec, oai_from_date, oai_verb]
else:
oai_verb = "GetRecord"
oai_parameters = [oai_output_folder, oai_url, oai_metadata_prefix, oai_verb, oai_identifier]
self.statusbar.showMessage("Daten werden über OAI-PMH geladen ...")
# Initialisieren des Workers, um den Anreicherungsprozess in einem separaten Thread zu starten
if self.oaiInputDialog_ui.radioButton_oai_multiple.isChecked():
worker_fetch_oai = Worker(lambda: fetch_oai_records.get_records(*oai_parameters))
else:
worker_fetch_oai = Worker(lambda: fetch_oai_records.get_single_record(*oai_parameters))
worker_fetch_oai.signals.destroyed.connect(lambda: finished_fetch_oai())
self.worker_start = datetime.datetime.now()
self.threadpool.start(worker_fetch_oai)
def finished_fetch_oai():
# Reaktivieren der Eingabemöglichkeiten nach Abschluss der Prozessierung:
self.worker_end = datetime.datetime.now()
self.worker_duration = str(self.worker_end - self.worker_start)
self.statusbar.showMessage("Laden der Daten über OAI-PMH abgeschlossen.")
logger.info("OAI-Harvesting abgeschlossen.")
logger.info("Prozessierungsdauer: {}".format(self.worker_duration))
self.oaiInputDialog_ui.buttonBox.setEnabled(True)
self.handle_util_result("OAI-PMH Harvesting", oai_output_folder)
def get_oai_sets(self):
# Verfügbare Sets des OAI-PMH-Repositories ermitteln und auflisten.
self.oaiSetsDialog.show()
self.oaiSetsDialog_ui.treeWidget.clear()
oai_url = self.oaiInputDialog_ui.lineEdit_oai_url.text()
oai_sets = fetch_oai_records.get_sets(oai_url)
if len(oai_sets) > 0:
for set_item in oai_sets:
list_item = QtWidgets.QTreeWidgetItem(self.oaiSetsDialog_ui.treeWidget)
list_item.setText(0, set_item["set_identifier"])
list_item.setText(1, set_item["set_name"])
def handle_analysis_htmlview_dialog(self, analysis_type):
# Aufruf des Analyse-HTMlView-Dialogs und Laden des initialen HTML-Templates:
html_view_path = os.path.abspath("./modules/analysis/statistics/helpers/templates/template_initial.html")
self.analysis_type = analysis_type
self.analysisHtmlViewDialog_ui.webEngineView.load(QtCore.QUrl.fromLocalFile(html_view_path))
self.analysisHtmlViewDialog.show()
# Befüllung der Combobox je nach Art der Analyse:
if self.analysis_type == "validify_validation":
analysis_base_folder = "{}/{}".format(self.root_path, "utils/validation_results")
single_analysis_folders = os.listdir(analysis_base_folder)
single_analysis_folders_max = []
for item in single_analysis_folders:
single_analysis_folders_max.append(item.replace("_", ":").replace("-", "_"))
analysis_folder = max(single_analysis_folders_max,
key=lambda d: datetime.datetime.strptime(d, "%Y%m%d_%X")).replace("_", "-").replace(
":", "_")
else:
transformation_dates = []
provider_path = "./data_output" + "/" + self.session_data["provider"].replace("-", "_")
for date in os.listdir(provider_path):
if date.startswith("2"): # Workaround, um nur relevante Ordner einzuschließen (schließt insbesondere unsichtbare Ordner auf Unix-Systemen aus, die mit einem "." beginnen)
transformation_dates.append(date)
transformation_date = max(transformation_dates, key= lambda d: datetime.datetime.strptime(d, "%Y%m%d"))
if self.analysis_type == "statistics":
analysis_folder = "Statistik/"
self.analysisHtmlViewDialog_ui.label_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.label.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.setVisible(False)
elif self.analysis_type == "technical_validation":
analysis_folder = "Technische_Validierung/"
self.analysisHtmlViewDialog_ui.label_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.label.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.setVisible(False)
elif self.analysis_type == "html_previews":
analysis_folder = "preview/"
self.analysisHtmlViewDialog_ui.label_filter_type.setVisible(True)
self.analysisHtmlViewDialog_ui.comboBox_filter_type.setVisible(True)
self.analysisHtmlViewDialog_ui.label.setVisible(True)
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.setVisible(True)
elif self.analysis_type == "validify_validation":
self.analysisHtmlViewDialog_ui.label_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_filter_type.setVisible(False)
self.analysisHtmlViewDialog_ui.label.setVisible(False)
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.setVisible(False)
else:
analysis_folder = "."
if self.analysis_type == "validify_validation":
self.analysis_path = "{}/{}".format(analysis_base_folder, analysis_folder)
else:
self.analysis_path = provider_path + "/" + transformation_date + "/" + analysis_folder
# HTML-Dateien für die Auswahl in der GUI ermitteln.
preview_file_ext = [".html", ".txt"]
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.clear()
if os.path.isdir(self.analysis_path):
if analysis_type == "html_previews":
self.get_filtered_preview_list()
else:
html_file_list = [f for f in os.listdir(self.analysis_path) if (os.path.isfile(os.path.join(self.analysis_path, f)) and f.endswith(tuple(preview_file_ext)))]
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.addItems(html_file_list)
def load_web_view_url(self):
if len(self.analysisHtmlViewDialog_ui.comboBox_statistics_file.currentText()) > 0:
if self.analysis_type == "html_previews":
html_view_path = os.path.abspath(self.analysis_path + "/" + self.analysisHtmlViewDialog_ui.comboBox_filter_type.currentText().replace("ä", "ae") + "/" + self.analysisHtmlViewDialog_ui.comboBox_statistics_file.currentText())
else:
html_view_path = os.path.abspath(self.analysis_path + "/" + self.analysisHtmlViewDialog_ui.comboBox_statistics_file.currentText())
qt_html_view_url = QtCore.QUrl.fromLocalFile(html_view_path)
self.analysisHtmlViewDialog_ui.webEngineView.load(qt_html_view_url)
self.currentWebViewUrl = qt_html_view_url.toString()
def get_filtered_preview_list(self):
if os.path.isdir(self.analysis_path):
analysis_path_filtered = self.analysis_path
analysis_path_filtered += self.analysisHtmlViewDialog_ui.comboBox_filter_type.currentText().replace("ä", "ae")
if os.path.isdir(analysis_path_filtered):
html_file_list = [f for f in os.listdir(analysis_path_filtered) if
(os.path.isfile(os.path.join(analysis_path_filtered, f)) and f.endswith(".html"))]
else:
html_file_list = [] # Abfangen von OSError, wenn für einen bestimmten Typ keine Vorschaudatensätze und dementsprechende Unterordner nicht vorhanden sind.
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.clear()
self.analysisHtmlViewDialog_ui.comboBox_statistics_file.addItems(html_file_list)
def session_load_from_xml(self):
logger.debug("Sitzungs-Daten wurden aus session.xml geladen.")
self.session_data = handle_session_data.load_from_xml()
def session_load_defaults(self):
logger.debug("Zurücksetzen der Session-Daten durch GUI angefordert.")
self.session_data = handle_session_data.load_defaults(self.session_data)
self.session_synchronize_with_gui()
def session_synchronize_with_gui(self):
# Synchronisierung der Sitzungsvariablen mit der UI:
self.checkBox_binaries.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["process_binaries"]))
self.checkBox_metsmods.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enable_mets_generation"]))
self.checkBox_tektonik_enrichment.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enable_tektonik_enrichment"]))
self.checkBox_analysis.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enable_metadata_analysis"]))
self.checkBox_metadata_previews.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enable_metadata_preview"]))
self.menuToggleRightsInfo.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enrich_rights_info"]))
self.menuToggleDdb2017Preprocessing.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enable_ddb2017_preprocessing"]))
self.menuToggleAggregatorInfo.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["enrich_aggregator_info"]))
self.menuToggleObsoleteObjects.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["handle_obsolete_objects"]))
self.menuToggleMappingDefinition.setChecked(
handle_session_data.synchronize_with_gui(self.session_data["apply_mapping_definition"]))
def get_provider_list(self):
logger.debug("Liste der Provider wurde aktualisiert.")
self.provider_list = [name.replace("_", "-") for name in os.listdir("./data_input") if
os.path.isdir(os.path.join("./data_input", name))]
self.comboBox_provider.clear()
self.comboBox_provider.addItems(self.provider_list)
# Wenn noch keine Datengeber vorhanden sind, Funktionen zur Prozessierung deaktivieren.
if len(self.comboBox_provider.currentText()) == 0:
self.disable_processing_controls(is_first_launch=True)
self.stackedWidget.setCurrentIndex(1)
else:
self.enable_processing_controls()
self.stackedWidget.setCurrentIndex(0)
def set_provider_from_list(self, current_index):
logger.debug("Provider-Listeneintrag wurde geändert --> Sitzungsvariable 'provider' angepasst: {}".format(self.provider_list[current_index]))
self.session_data["provider"] = self.provider_list[current_index]
def create_new_provider(self):
new_provider_name = process_filenames(self.newProviderDialog_ui.lineEdit_newprovider_isil.text())