cleanup
This commit is contained in:
parent
9d6053403a
commit
e5487b0d29
85
bitmover.py
85
bitmover.py
|
@ -1,85 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Functions to copy bits around ...
|
||||
"""
|
||||
|
||||
from os import system,path,rename
|
||||
from tqdm import tqdm
|
||||
|
||||
from file_stuff import create_folder, cmp_files, path_exists
|
||||
from lumberjack import timber
|
||||
from hashing import xx_hash
|
||||
# from configure import Configure, CONFIG_FILE
|
||||
|
||||
# c = Configure(CONFIG_FILE)
|
||||
# config = c.load_config()
|
||||
log = timber(__name__)
|
||||
|
||||
def copy_with_progress(s,d,f):
|
||||
""" Copy a file with the progress bar """
|
||||
log.debug(f'copy_with_progress({s},{d},{f})')
|
||||
|
||||
size = path.getsize(s)
|
||||
with open(s, 'rb') as fs:
|
||||
with open(d, 'wb') as fd:
|
||||
with tqdm(total=size, unit='B', unit_scale=True, desc=f'Copying {f}') as pbar:
|
||||
while True:
|
||||
chunk = fs.read(4096)
|
||||
if not chunk:
|
||||
break
|
||||
fd.write(chunk)
|
||||
pbar.update(len(chunk))
|
||||
|
||||
def copy_from_source(source_path,dest_path,file_name):
|
||||
""" Copy file from source to destination """
|
||||
log.debug(f'copy_from_source({source_path},{dest_path},{file_name}')
|
||||
|
||||
file_exists = path_exists(path.join(dest_path,file_name))
|
||||
|
||||
if file_exists is True:
|
||||
log.debug(f'\nFound {file_name} at destination, checking if they match.')
|
||||
check_match = cmp_files(
|
||||
path.join(source_path,file_name),
|
||||
path.join(dest_path, file_name))
|
||||
if check_match is False:
|
||||
log.warn(f'\nFound duplicate for {source_path}/{file_name}, \
|
||||
renaming destination with hash appended.')
|
||||
base, extension = path.splitext(file_name)
|
||||
#md5 = md5_hash(os.path.join(dest_path, file_name))
|
||||
f_xxhash = xx_hash(path.join(dest_path, file_name))
|
||||
#file_name_hash = base + '_' + md5 + extension
|
||||
file_name_hash = base + '_' + f_xxhash + extension
|
||||
rename(path.join(dest_path, file_name),
|
||||
path.join(dest_path, file_name_hash))
|
||||
else:
|
||||
log.info(f'\n{file_name} hashes match')
|
||||
# remove(path.join(source_path,file_name))
|
||||
# f.pop(file_name)
|
||||
return
|
||||
|
||||
# create_folder(dest_path)
|
||||
# shutil.copy(os.path.join(source_path,file_name), dest_path)
|
||||
copy_with_progress(path.join(source_path, file_name),
|
||||
path.join(dest_path, file_name),
|
||||
file_name)
|
||||
system('clear')
|
||||
|
||||
def copy_files(f,config):
|
||||
""" Copy Files. """
|
||||
log.debug(f'copy_files({f})')
|
||||
system('clear')
|
||||
for file in tqdm(f, desc="Copying Files:"):
|
||||
create_folder(f[file]['folders']['destination'])
|
||||
|
||||
copy_from_source(f[file]['folders']['source_path'],
|
||||
f[file]['folders']['destination'],
|
||||
f[file]['name'])
|
||||
|
||||
if config['store_originals'] is True:
|
||||
if f[file]['type'] == 'image':
|
||||
create_folder(f[file]['folders']['destination_original'])
|
||||
|
||||
copy_from_source(f[file]['folders']['destination'],
|
||||
f[file]['folders']['destination_original'],
|
||||
f[file]['name'])
|
|
@ -1,99 +0,0 @@
|
|||
from PyQt6.QtCore import QSize, Qt
|
||||
from PyQt6.QtGui import QPixmap
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QLabel, QLineEdit, QWidget, \
|
||||
QHBoxLayout, QListWidget
|
||||
from ui_dialogues import select_directory, update_textbox_from_path
|
||||
|
||||
|
||||
def create_layout1():
|
||||
layout1 = QVBoxLayout()
|
||||
layout1_1 = QHBoxLayout()
|
||||
layout1_2 = QHBoxLayout()
|
||||
layout1_3 = QHBoxLayout()
|
||||
|
||||
### Spacing and Alignment
|
||||
layout1.setContentsMargins(10, 10, 10, 10)
|
||||
layout1.setSpacing(10)
|
||||
layout1.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
layout1_1.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
layout1_2.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
layout1_3.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
return layout1,layout1_1,layout1_2,layout1_3
|
||||
|
||||
def layout1_widgets(config):
|
||||
l1,l1_1,l1_2,l1_3 = create_layout1()
|
||||
|
||||
### Create Top Row
|
||||
lbl_src_directory = QLabel('Source Directory')
|
||||
txt_box_src_directory = QLineEdit()
|
||||
txt_box_src_directory.setPlaceholderText(config['folders']['source']['base'])
|
||||
|
||||
btn_src_browse = QPushButton('Browse')
|
||||
btn_src_browse.setFixedSize(100, 40)
|
||||
btn_src_browse.clicked.connect(update_textbox_from_path(
|
||||
txt_box_src_directory,
|
||||
config['folders']['source']['base']))
|
||||
|
||||
### Create Second Row
|
||||
lbl_dst_directory = QLabel('Destination Directory')
|
||||
txt_box_dst_directory = QLineEdit()
|
||||
txt_box_dst_directory.setPlaceholderText(config['folders']['destination']['base'])
|
||||
|
||||
btn_dst_browse = QPushButton('Browse')
|
||||
btn_dst_browse.setFixedSize(100, 40)
|
||||
btn_dst_browse.clicked.connect(update_textbox_from_path(
|
||||
txt_box_dst_directory,
|
||||
config['folders']['destination']['base']))
|
||||
|
||||
### Create Third Row
|
||||
btn_scan_dir = QPushButton("Scan Directory")
|
||||
btn_scan_dir.setFixedSize(100, 40)
|
||||
btn_scan_dir.setCheckable(False)
|
||||
|
||||
### Add Widgets to Layouts
|
||||
l1_1.addWidget(lbl_src_directory)
|
||||
l1_1.addWidget(txt_box_src_directory)
|
||||
l1_1.addWidget(btn_src_browse)
|
||||
l1_2.addWidget(lbl_dst_directory)
|
||||
l1_2.addWidget(txt_box_dst_directory)
|
||||
l1_2.addWidget(btn_dst_browse)
|
||||
l1_3.addWidget(btn_scan_dir)
|
||||
|
||||
### Add Layouts to primary Layout 1
|
||||
l1.addLayout(l1_1)
|
||||
l1.addLayout(l1_2)
|
||||
l1.addLayout(l1_3)
|
||||
|
||||
return l1
|
||||
|
||||
def create_layout2():
|
||||
layout2 = QHBoxLayout()
|
||||
layout2_1 = QHBoxLayout()
|
||||
layout2_2 = QVBoxLayout()
|
||||
layout2_2_1 = QHBoxLayout()
|
||||
layout2_2_2 = QVBoxLayout()
|
||||
|
||||
return layout2,layout2_1,layout2_2,layout2_2_1,layout2_2_2
|
||||
|
||||
def layout2_widgets():
|
||||
l2,l2_1,l2_2,l2_2_1,l2_2_2 = create_layout2()
|
||||
preview_width = int(220)
|
||||
preview_height = int(preview_width * 0.75)
|
||||
|
||||
src_file_list = QListWidget()
|
||||
|
||||
src_file_list.setFixedWidth(550)
|
||||
|
||||
preview_placeholder = QLabel("Placeholder")
|
||||
preview_placeholder.setPixmap(QPixmap('assets/preview_placeholder.jpg'))
|
||||
preview_placeholder.setScaledContents(True)
|
||||
preview_placeholder.setFixedWidth(preview_width)
|
||||
preview_placeholder.setFixedHeight(preview_height)
|
||||
|
||||
l2_1.addWidget(src_file_list)
|
||||
l2_2.addWidget(preview_placeholder)
|
||||
l2_1.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
l2_2.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop)
|
||||
l2.addLayout(l2_1)
|
||||
l2.addLayout(l2_2)
|
Loading…
Reference in New Issue