diff --git a/asfuncs.py b/asfuncs.py index 7516687..13cc633 100644 --- a/asfuncs.py +++ b/asfuncs.py @@ -1,6 +1,6 @@ import os import shutil -from datetime import datetime +from pathlib import Path, PurePath from random import randint RICH_TEXT_FORE_NL = '
' @@ -11,8 +11,8 @@ def filesnumrenamer(dstname, srcfiles, dstfiles, truepath, id_filelist): filesidrenamer(dstname, srcfiles, dstfiles, truepath) - for i, file in enumerate(os.listdir(truepath)): - name, extension = os.path.splitext(file) #error #1 + for file in Path(truepath).iterdir(): + name, extension = PurePath(file).stem, PurePath(file).suffix #error #1 name = name.split('---', 1)[0] id_filelist.append(name + '---' + extension) fileamount = id_filelist.count(name + '---' + extension) - 1 @@ -45,11 +45,14 @@ def filesidrenamer(dstname, srcfiles, dstfiles, truepath): def dstsort(dstname, truepath): files = [f for f in os.listdir(truepath) if os.path.isfile(os.path.join(truepath, f))] for file in files: - name, extension = os.path.splitext(file) - new_path = os.path.join(truepath, extension) - if not os.path.exists(new_path): - os.makedirs(new_path) - shutil.move(os.path.join(truepath, file), os.path.join(truepath, extension, name+extension)) + name, extension = PurePath(file).stem, PurePath(file).suffix + new_dir = PurePath(truepath, extension).joinpath() + if not Path(new_dir).exists(): + Path(new_dir).mkdir() + filename = name + extension + old_path = Path(truepath) / file + new_path = Path(truepath) / extension / filename + shutil.move(old_path, new_path) def createid(srcfiles, dstfiles): diff --git a/autosort.py b/autosort.py index 81af0aa..436df72 100644 --- a/autosort.py +++ b/autosort.py @@ -1,5 +1,6 @@ import os import shutil +from pathlib import Path, PurePath from datetime import datetime from asfuncs import (createid, dstsort, filesnumrenamer, RICH_TEXT_FORE_NL, RICH_TEXT_FORE, PLAIN_TEXT_FORE, TEXTBACK) @@ -16,11 +17,9 @@ def copyfromdirs(metadata, replace, fcmethod, sort, dstname): all_srcfiles_len = 0 - if fcmethod == 1: + if fcmethod == 'Single-folder creation': folder_name = f'autosort {datetime.now().strftime("%H-%M-%S-%f")}' - os.mkdir(os.path.join(dstname, folder_name)) - else: - pass + Path(PurePath(dstname, folder_name).joinpath()).mkdir() for srcdir in srcdirs: for root, dirs, files in os.walk(srcdir): @@ -36,14 +35,12 @@ def copyfromdirs(metadata, replace, fcmethod, sort, dstname): dstfiles.append(file) for srcdir in srcdirs: - if fcmethod == 2: + if fcmethod == 'Multi-folder creation': folder_name = f'autosort {datetime.now().strftime("%H-%M-%S-%f")}' - os.mkdir(os.path.join(dstname, folder_name)) - else: - pass + Path(PurePath(dstname, folder_name).joinpath()).mkdir() if 'folder_name' in locals(): - truepath = os.path.join(dstname, folder_name) + truepath = PurePath(dstname, folder_name).joinpath() else: truepath = dstname @@ -67,12 +64,12 @@ def copyfromdirs(metadata, replace, fcmethod, sort, dstname): temp_all_srcfiles_len -= 1 if metadata: - shutil.copy2(os.path.join(root, file), os.path.join(truepath, file_ider)) + shutil.copy2(PurePath(root, file).joinpath(), PurePath(truepath, file_ider).joinpath()) else: - shutil.copy(os.path.join(root, file), os.path.join(truepath, file_ider)) + shutil.copy(PurePath(root, file).joinpath(), PurePath(truepath, file_ider).joinpath()) dstfiles.append(file_ider) - if fcmethod == 2: + if fcmethod == 'Multi-folder creation': if not replace: yield f'{RICH_TEXT_FORE_NL}Enumerating...{TEXTBACK}' filesnumrenamer(dstname, srcfiles, dstfiles, truepath, id_filelist) @@ -81,7 +78,7 @@ def copyfromdirs(metadata, replace, fcmethod, sort, dstname): yield f'{RICH_TEXT_FORE}Finished{TEXTBACK}' id_filelist.clear() - if fcmethod == 1: + if fcmethod == 'Single-folder creation': if not replace: yield f'{RICH_TEXT_FORE_NL}Enumerating...{TEXTBACK}' filesnumrenamer(dstname, srcfiles, dstfiles, truepath, id_filelist) @@ -89,7 +86,7 @@ def copyfromdirs(metadata, replace, fcmethod, sort, dstname): dstsort(dstname, truepath) yield f'{RICH_TEXT_FORE}Finished{TEXTBACK}' - elif fcmethod == 0: + elif fcmethod == 'No folder creation': if not replace: yield f'{RICH_TEXT_FORE_NL}Enumerating...{TEXTBACK}' filesnumrenamer(dstname, srcfiles, dstfiles, truepath, id_filelist) diff --git a/autosortgui.py b/autosortgui.py index 5882f68..c2fc1e3 100644 --- a/autosortgui.py +++ b/autosortgui.py @@ -3,18 +3,16 @@ from PyQt5.QtWidgets import QFileDialog, QMessageBox, QLabel from autosort import copyfromdirs, srcdirs from asfuncs import RICH_TEXT_FORE, TEXTBACK +from pathlib import Path import qtfiles.qtresources.resources -import os -import threading -import time - class WorkerSignals(QtCore.QObject): result = QtCore.pyqtSignal(object) class Worker(QtCore.QRunnable): - def __init__(self, metadata, replace, fcmethod, sort, destdir): + def __init__(self, run_button, metadata, replace, fcmethod, sort, destdir): super().__init__() self.signals = WorkerSignals() + self.run_button = run_button self.metadata = metadata self.replace = replace self.fcmethod = fcmethod @@ -23,9 +21,11 @@ def __init__(self, metadata, replace, fcmethod, sort, destdir): @QtCore.pyqtSlot() def run(self): + self.run_button.setEnabled(False) function = copyfromdirs(self.metadata, self.replace, self.fcmethod, self.sort, self.destdir) for statement in function: self.signals.result.emit(statement) + self.run_button.setEnabled(True) class CustomQTextEdit(QtWidgets.QTextEdit): clicked = pyqtSignal() @@ -516,16 +516,16 @@ def setupUi(self, MainWindow): def source_button_click(self): sourcedir = QFileDialog.getExistingDirectory() - if os.path.isdir(sourcedir): + if Path(sourcedir).is_dir() and sourcedir != '': srcdirs.append(sourcedir) srcdirsstring = f'{RICH_TEXT_FORE}, {TEXTBACK}'.join(srcdirs) self.sourcedisplay.setText(srcdirsstring) - + def destination_button_click(self): + # bug: if user has selected destdir before then presses cancel on destdir file dialog. self.destdir = QFileDialog.getExistingDirectory() - if os.path.isdir(self.destdir): - self.destinationdisplay.setText(self.destdir) + self.destinationdisplay.setText(self.destdir) def run_button_click(self): @@ -533,11 +533,11 @@ def run_button_click(self): organization = self.organization_box.currentText() if organization == 'Single-folder creation': - fcmethod = 1 + fcmethod = 'Single-folder creation' elif organization == 'Multi-folder creation': - fcmethod = 2 + fcmethod = 'Multi-folder creation' else: - fcmethod = 0 + fcmethod = 'No folder creation' replace = self.replace_button.isChecked() metadata = not self.metadata_button.isChecked() @@ -550,17 +550,17 @@ def run_button_click(self): nosourceerror.setIcon(QMessageBox.Critical) nosourceerror.exec_() try: - if os.path.isdir(self.destdir) and srcdirs: - worker = Worker(metadata, replace, fcmethod, sort, self.destdir) + if Path(self.destdir).is_dir() and srcdirs: + worker = Worker(self.run_button, metadata, replace, fcmethod, sort, self.destdir) worker.signals.result.connect(self.statement_returner) self.threadpool.start(worker) - elif not os.path.isdir(self.destdir): + elif not Path(self.destdir).is_dir() or self.destdir == '': nodestinationerror = QMessageBox() nodestinationerror.setWindowTitle('Error') nodestinationerror.setText('Destination directory field cannot be empty.') nodestinationerror.setIcon(QMessageBox.Critical) nodestinationerror.exec_() - except AttributeError: # if self.desdir hasn't been defined yet (user hasn't clicked the destination button) + except (AttributeError, TypeError): # if self.desdir hasn't been defined yet (user hasn't clicked the destination button) nodestinationerror = QMessageBox() nodestinationerror.setWindowTitle('Error') nodestinationerror.setText('Destination directory field cannot be empty.') @@ -571,13 +571,16 @@ def run_button_click(self): def statement_returner(self, statement): self.console.append(statement) + def sourcedisplay_clear(self): self.sourcedisplay.clear() srcdirs.clear() + def destinationdisplay_clear(self): self.destinationdisplay.clear() - self.destdir = '' + self.destdir = False + def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate @@ -610,7 +613,7 @@ def retranslateUi(self, MainWindow): if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) - app.setWindowIcon(QtGui.QIcon(":/icons/newlogor.ico")) + app.setWindowIcon(QtGui.QIcon(":/icons/logo.ico")) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) diff --git a/autosortgui.spec b/autosortgui.spec index 97ec202..c64e646 100644 --- a/autosortgui.spec +++ b/autosortgui.spec @@ -6,7 +6,7 @@ block_cipher = None a = Analysis(['autosortgui.py'], pathex=['C:\\Users\\Duttas\\Desktop\\autosort'], binaries=[], - datas=[('newlogor.ico', '.')], + datas=[('logo.ico', '.')], hiddenimports=[], hookspath=[], runtime_hooks=[], @@ -30,4 +30,4 @@ exe = EXE(pyz, upx=True, upx_exclude=[], runtime_tmpdir=None, - console=False , icon='newlogor.ico') + console=False , icon='logo.ico') diff --git a/logo files/logov2.psd b/logo files/logov2.psd index 0467b7d..d7ffda3 100644 Binary files a/logo files/logov2.psd and b/logo files/logov2.psd differ diff --git a/logo files/logov2banner.PSD b/logo files/logov2banner.PSD new file mode 100644 index 0000000..05e3451 Binary files /dev/null and b/logo files/logov2banner.PSD differ diff --git a/newlogor.ico b/logo.ico similarity index 100% rename from newlogor.ico rename to logo.ico diff --git a/qtfiles/qtresources/resources.py b/qtfiles/qtresources/resources.py index bd0e199..71ec708 100644 --- a/qtfiles/qtresources/resources.py +++ b/qtfiles/qtresources/resources.py @@ -274,10 +274,10 @@ \x00\x6f\xa6\x53\ \x00\x69\ \x00\x63\x00\x6f\x00\x6e\x00\x73\ -\x00\x0c\ -\x04\xfc\x89\x3f\ -\x00\x6e\ -\x00\x65\x00\x77\x00\x6c\x00\x6f\x00\x67\x00\x6f\x00\x72\x00\x2e\x00\x69\x00\x63\x00\x6f\ +\x00\x08\ +\x05\xe2\x41\xff\ +\x00\x6c\ +\x00\x6f\x00\x67\x00\x6f\x00\x2e\x00\x69\x00\x63\x00\x6f\ " qt_resource_struct_v1 = b"\ diff --git a/qtfiles/qtresources/resources.qrc b/qtfiles/qtresources/resources.qrc index fee08b2..fa579db 100644 --- a/qtfiles/qtresources/resources.qrc +++ b/qtfiles/qtresources/resources.qrc @@ -1,6 +1,6 @@ - newlogor.ico + logo.ico \ No newline at end of file