dev #1

Merged
kkenny merged 8 commits from dev into main 2024-10-07 14:51:01 -04:00
10 changed files with 198 additions and 77 deletions
Showing only changes of commit 416d889d1c - Show all commits

View File

@ -20,6 +20,7 @@ from _thread_my_stuff import Worker
from _media_file import MediaFile
from _file_stuff import path_exists,is_file,create_folder,cmp_hashes
from _verify_file_checksum import FileHash
from _dialog_compare_imported_checksums import DialogCompareImportedChecksums
basedir = os.path.dirname(__file__)
@ -60,6 +61,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.imp_dialog = DialogImport()
self.find_files_dialog = FindProgress()
self.checksum_progress_dialog = DialogChecksumProgress()
self.compare_imported_checksums_dialog = DialogCompareImportedChecksums()
self.widgets_config()
@ -104,7 +106,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
def toggle_scan_button(self,enable=True):
print(f'toggle_scan_button.enabled: {enable}')
self.pushButton_3_scan_dir.setEnabled(enable)
def toggle_import_button(self,enable=True):
@ -116,7 +117,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.src_dir)
if directory:
print("Selected Directory:", directory)
# path = Path(directory)
self.src_dir = directory
self.lineEdit_src_dir.setText(self.src_dir)
@ -127,7 +127,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.dst_dir)
if directory:
print("Selected Directory:", directory)
# path = Path(directory)
self.dst_dir = directory
self.lineEdit_dst_dir.setText(self.dst_dir)
@ -141,21 +140,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.config['verify_checksum'] = True
else:
self.config['verify_checksum'] = False
print(f"verify_checksums: {self.config['verify_checksums']}")
def cleanup_files_changed(self):
if self.checkBox_cleanup_files.isChecked():
self.config['cleanup_sd'] = True
else:
self.config['cleanup_sd'] = False
print(f"cleanup_sd: {self.config['cleanup_sd']}")
def store_originals_changed(self):
if self.checkBox_store_originals.isChecked():
self.config['store_originals'] = True
else:
self.config['store_originals'] = False
print(f"store_originals: {self.config['store_originals']}")
def set_thumbnail(self,thumb_file,scaled=True,ratio=None):
self.img_preview.setPixmap(QPixmap(thumb_file))
@ -261,7 +257,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.set_default_thumbnail()
else:
self.process_file(i.text())
print(f'index changed to: {i.text()}')
preview = self.get_preview(i.text())
self.update_preview(preview)
self.update_metadata(preview)
@ -311,12 +306,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
print(f'output: {s}')
def worker_thread_started(self):
print('scan thread started')
self.toggle_scan_button(False)
self.toggle_import_button(False)
def worker_thread_done(self):
print('scan thread complete.')
self.toggle_scan_button(True)
if 0 < len(self.file_list):
self.toggle_import_button(True)
@ -387,8 +380,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# From _media_import.py
def is_video(self,sph):
print(f"Should be sph: {sph}")
print(f"Should be filetype: {self.files[sph]['file_type']}")
if self.files[sph]['file_type'] == 'video':
r = True
else:
@ -412,7 +403,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
""" Copy Files. """
count = int(0)
for line in range(self.file_list.count()):
@ -420,7 +416,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
file = item.text()
self.process_file(file)
sph = self.get_source_path_hash(file)
print(sph)
self.src_dir = self.files[sph]['folders']['source_path']
self.dst_dir = self.files[sph]['folders']['destination']
self.path_file_source = path.join(self.src_dir,
@ -429,19 +424,21 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.files[sph]['name'])
self.imp_dialog.set_importing_file(self.path_file_source)
self.copy_a_file(
sph,
self.path_file_destination,
progress_callback,
current_file_progress_callback,
imported_file_count_callback,
found_file_callback,
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
print(f'check_store_original({sph}): {self.check_store_original(sph)}')
self.copy_a_file(sph,
self.path_file_destination,
progress_callback,
current_file_progress_callback,
imported_file_count_callback,
found_file_callback,
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
if self.check_store_original(sph) is True:
self.path_file_destination_original = path.join(self.dst_dir,
@ -457,7 +454,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
count += 1
@ -475,7 +477,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
size = path.getsize(self.path_file_source)
target_dir = os.path.dirname(target)
@ -489,7 +496,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
if dup_check is False:
if self.is_video(fph):
self.chunk_size = (1024 * 1024) * 5
@ -525,7 +537,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
sph = FileHash(_pf).path_hash
self.path_file_source = os.path.join(self.files[sph]['folders']['source_path'],
@ -539,10 +556,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def set_checksum(_pf):
print(f'set_checksum, _pf: {_pf}')
if path_exists(_pf) and is_file(_pf):
self.files[sph]['xx_checksum'][_pf] = FileHash(_pf).get_hash(_pf,
progress_callback,
current_file_progress_callback,
@ -551,7 +565,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
else:
print(f"set_checksum: {_pf} doesn't exist yet or isn't a real file.")
@ -570,8 +589,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.files[sph]['xx_checksum'].get(self.path_file_destination_original) is None:
set_checksum(self.path_file_destination_original)
# self.checksum_progress_dialog.close_dialog()
def check_duplicate(self,
sph,
target,
@ -583,7 +600,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
if path_exists(target):
print(f'Path Exists: path_file_source: {self.path_file_source}\ntarget: {target}')
self.get_checksum(self.path_file_source,
@ -594,7 +616,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
hash1 = self.files[sph]['xx_checksum'][self.path_file_source]
hash2 = self.files[sph]['xx_checksum'][target]
@ -663,17 +690,23 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# if self.config['verify_checksum'] is True:
# self.checksum_fph = fph
# Initialize Widgets
self.checksum_progress_dialog.set_progress(0)
self.compare_imported_checksums_dialog.setup_compare_dialog()
worker = Worker(self.t_compare_imported_checksums)
worker.signals.started.connect(
self.worker_thread_started)
worker.signals.started.connect(
self.checksum_progress_dialog.open_dialog)
worker.signals.found_file.connect(
self.checksum_progress_dialog.set_file)
worker.signals.progress.connect(
self.checksum_progress_dialog.set_progress)
self.compare_imported_checksums_dialog.open_dialog)
worker.signals.compare_checksums_source_file.connect(
self.compare_imported_checksums_dialog.set_label_path_file_source)
worker.signals.compare_checksums_dest_file.connect(
self.compare_imported_checksums_dialog.set_label_path_file_dest)
worker.signals.compare_checksums_source_hash.connect(
self.compare_imported_checksums_dialog.set_label_hash_source)
worker.signals.compare_checksums_dest_hash.connect(
self.compare_imported_checksums_dialog.set_label_hash_dest)
worker.signals.compare_checksums_add_row.connect(
self.compare_imported_checksums_dialog.add_table_row)
worker.signals.finished.connect(
self.thread_complete)
worker.signals.finished.connect(
@ -702,15 +735,25 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
for file in self.files:
_pf = os.path.join(self.files[file]['folders']['source_path'],
_pfs = os.path.join(self.files[file]['folders']['source_path'],
self.files[file]['name'])
print(f"source_path: {self.files[file]['folders']['source_path']}")
print(f"name: {self.files[file]['name']}")
print(f'_pf: {_pf}')
self.get_checksum(_pf,
_pfd = os.path.join(self.files[file]['folders']['destination'],
self.files[file]['name'])
compare_checksums_source_file_callback.emit(_pfs)
compare_checksums_dest_file_callback.emit(_pfd)
compare_checksums_source_hash_callback.emit('Calculating...')
compare_checksums_dest_hash_callback.emit('Calculating...')
self.get_checksum(_pfs,
progress_callback,
current_file_progress_callback,
imported_file_count_callback,
@ -718,7 +761,19 @@ class MainWindow(QMainWindow, Ui_MainWindow):
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback)
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback)
compare_checksums_source_hash_callback.emit(
self.files[file]['xx_checksum'][_pfs])
compare_checksums_dest_hash_callback.emit(
self.files[file]['xx_checksum'][_pfd])
i = 0
c = {}
for checksum in self.files[file]['xx_checksum']:
@ -733,6 +788,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
print(f'Checksum failed for: {self.files[file]["name"]}')
i += 1
table_row = {
'source_path_file': _pfs,
'dest_path_file': _pfd,
'source_path_hash': self.files[file]['xx_checksum'][_pfs],
'dest_path_hash': self.files[file]['xx_checksum'][_pfd],
'checksum_match': self.files[file]['checksum_match']
}
print(f"checksum_match:{self.files[file]['checksum_match']}")
print(f"--------Table Row-------\n{table_row}\n--------End-------\n")
compare_checksums_add_row_callback.emit(table_row)
# Main App
app = QApplication(sys.argv)
# Main Window

View File

@ -7,16 +7,13 @@ class DialogChecksumProgress(QDialog, Ui_ChecksumProgressDialog):
self.setupUi(self)
# self.import_dialog = UI_DialogImport()
# self.ui_import_dialog = Ui_DialogImport()
print('DialogImport')
def is_shown(self):
print(f'is_shown: {self.isVisible()}')
return self.isVisible()
def open_dialog(self,should_be_open):
if should_be_open is True:
if self.is_shown() is False:
print(f'open_checksum_dialog: {self.is_shown()}')
self.show()
else:
print('Checksum dialog already open.')
@ -24,10 +21,7 @@ class DialogChecksumProgress(QDialog, Ui_ChecksumProgressDialog):
self.close_dialog()
def close_dialog(self):
print('close_import_dialog')
if self.is_shown():
print('inside self.is_shown()')
print('hiding window')
self.hide()
def set_progress(self, n):

View File

@ -0,0 +1,56 @@
from PyQt6.QtWidgets import QDialog, QTableWidgetItem
from _Window_comparison_dialog import Ui_FileComparisonDialog
class DialogCompareImportedChecksums(QDialog, Ui_FileComparisonDialog):
def __init__(self,*args,**kwargs):
super(DialogCompareImportedChecksums,self).__init__(*args,**kwargs)
self.setupUi(self)
# self.import_dialog = UI_DialogImport()
# self.ui_import_dialog = Ui_DialogImport()
self.table_headers = ['Source File',
'Destination File',
'Source Hash',
'Destination Hash',
'Checksum Match']
def setup_compare_dialog(self):
self.set_table_headers()
self.tableWidget.setRowCount(0)
def is_shown(self):
return self.isVisible()
def open_dialog(self):
if self.is_shown() is False:
self.show()
else:
self.close_dialog()
def close_dialog(self):
if self.is_shown():
self.hide()
def set_label_path_file_source(self,value):
self.l_path_file_source.setText(value)
def set_label_path_file_dest(self,value):
self.l_path_file_dest.setText(value)
def set_label_hash_source(self,value):
self.l_hash_source.setText(value)
def set_label_hash_dest(self,value):
self.l_hash_dest.setText(value)
def set_table_headers(self):
self.tableWidget.setHorizontalHeaderLabels(self.table_headers)
def add_table_row(self,_dictionary):
row_count = self.tableWidget.rowCount()
self.tableWidget.insertRow(row_count)
self.tableWidget.setItem(row_count, 0, QTableWidgetItem(_dictionary['source_path_file']))
self.tableWidget.setItem(row_count, 1, QTableWidgetItem(_dictionary['dest_path_file']))
self.tableWidget.setItem(row_count, 2, QTableWidgetItem(_dictionary['source_path_hash']))
self.tableWidget.setItem(row_count, 3, QTableWidgetItem(_dictionary['dest_path_hash']))
self.tableWidget.setItem(row_count, 4, QTableWidgetItem(str(_dictionary['checksum_match'])))

View File

@ -8,21 +8,14 @@ class FindProgress(QDialog, Ui_FindProgress):
# self.set_progress_finding_files(0)
def is_shown(self):
print(f'is_shown: {self.isVisible()}')
return self.isVisible()
def open_find_files_dialog(self):
print(f'open_import_dialog: {self.is_shown()}')
if not self.is_shown():
print('Inside if not self.is_shown')
print('showing window')
self.show()
def close_find_files_dialog(self):
print('close_import_dialog')
if self.is_shown():
print('inside self.is_shown()')
print('hiding window')
self.hide()
def set_progress_finding_files(self,n):

View File

@ -7,18 +7,13 @@ class DialogImport(QDialog, Ui_DialogImport):
self.setupUi(self)
# self.import_dialog = UI_DialogImport()
# self.ui_import_dialog = Ui_DialogImport()
print('DialogImport')
def is_shown(self):
print(f'is_shown: {self.isVisible()}')
return self.isVisible()
def open_import_dialog(self):
if self.is_shown() is False:
print(f'open_import_dialog: {self.is_shown()}')
if not self.is_shown():
print('Inside if not self.is_shown')
print('showing window')
self.show()
else:
print('Import Dialog already open.')
@ -26,10 +21,7 @@ class DialogImport(QDialog, Ui_DialogImport):
self.close_import_dialog()
def close_import_dialog(self):
print('close_import_dialog')
if self.is_shown():
print('inside self.is_shown()')
print('hiding window')
self.hide()
def set_progress_importing(self, n):

View File

@ -32,7 +32,12 @@ class FindFiles:
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
file_count = int(0)
if len(self.search_types) > 0:
for folder, subfolders, filename in os.walk(self.src_dir):

View File

@ -17,7 +17,6 @@ class ImageTag:
return tag_data
def get_image_tags(self):
print(f'get_image_tags, self.path_file_name: {self.path_file_name}')
with open(self.path_file_name,'rb') as f:
tags = exifread.process_file(f)
return tags

View File

@ -156,5 +156,5 @@ class MediaFile:
self.media['image_meta'] = None
self.media['video_meta'] = None
print(f'MediaFile, self.media: {self.media}')
# print(f'MediaFile, self.media: {self.media}')
return self.media

View File

@ -34,6 +34,11 @@ class WorkerSignals(QObject):
checksum_progress = pyqtSignal(int)
checksum_file = pyqtSignal(str)
checksum_dialog_open = pyqtSignal(bool)
compare_checksums_source_file = pyqtSignal(str)
compare_checksums_dest_file = pyqtSignal(str)
compare_checksums_source_hash = pyqtSignal(str)
compare_checksums_dest_hash = pyqtSignal(str)
compare_checksums_add_row = pyqtSignal(dict)
class Worker(QRunnable):
"""
@ -66,6 +71,11 @@ class Worker(QRunnable):
self.kwargs['checksum_file_callback'] = self.signals.checksum_file
self.kwargs['checksum_progress_callback'] = self.signals.checksum_progress
self.kwargs['checksum_dialog_open_callback'] = self.signals.checksum_dialog_open
self.kwargs['compare_checksums_source_file_callback'] = self.signals.compare_checksums_source_file
self.kwargs['compare_checksums_dest_file_callback'] = self.signals.compare_checksums_dest_file
self.kwargs['compare_checksums_source_hash_callback'] = self.signals.compare_checksums_source_hash
self.kwargs['compare_checksums_dest_hash_callback'] = self.signals.compare_checksums_dest_hash
self.kwargs['compare_checksums_add_row_callback'] = self.signals.compare_checksums_add_row
@pyqtSlot()
def run(self):

View File

@ -11,7 +11,7 @@ class FileHash:
self.path_file = path_file
self._path = os.path.dirname(self.path_file)
self.chunk_size = chunk_size
self.path_hasher = xxhash.xxh64(self._path)
self.path_hasher = xxhash.xxh64(self.path_file)
# noinspection PyArgumentList
# self.file_hash = self.get_hash(self.path_file)
self.path_hash = self.hash_path()
@ -24,7 +24,12 @@ class FileHash:
total_file_count_callback,
checksum_file_callback,
checksum_progress_callback,
checksum_dialog_open_callback):
checksum_dialog_open_callback,
compare_checksums_source_file_callback,
compare_checksums_dest_file_callback,
compare_checksums_source_hash_callback,
compare_checksums_dest_hash_callback,
compare_checksums_add_row_callback):
checksum_dialog_open_callback.emit(True)