Skip to content

Commit 6fa083c

Browse files
Code that should work but shutil is trash
1 parent ea6fd68 commit 6fa083c

File tree

5 files changed

+267
-152
lines changed

5 files changed

+267
-152
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11.11_daz_case_fix

DAZFix/RecursiveChecker.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from DAZFix.LibraryFix import log_to_ui
2+
import os
3+
import shutil
4+
5+
6+
7+
8+
def fix_recursive(library_path):
9+
dupe_folders = []
10+
for (root, dirs, files) in os.walk(library_path, topdown=True):
11+
for dir in dirs:
12+
full_directory = os.path.join(root,dir)
13+
# if current_depth > previous_depth and os.path.basename(os.path.normpath(full_directory)) == previous_root_end_folder:
14+
if os.path.basename(os.path.normpath(root)) == os.path.basename(os.path.normpath(full_directory)):
15+
log_to_ui("WARNING: Folder appears to have been placed inside itself:")
16+
log_to_ui(f"Current full path: {full_directory}")
17+
18+
# FIX #
19+
# Note the top-level folder
20+
# top_folder = root
21+
dupe_folder_name = os.path.basename(os.path.normpath(root))
22+
23+
# Walk from this folder to find out how many matryoshka folders we have
24+
for (root2, dirs2, files2) in os.walk(root, topdown=True):
25+
# Iterate over the directories for this level/root
26+
for d in dirs2:
27+
full_dir_path = os.path.join(root2,d)
28+
# Mark dupe folders with the same name as the current ("parent") folder
29+
if os.path.basename(os.path.normpath(d)) == dupe_folder_name and not any(x == full_dir_path for x in dupe_folders):
30+
dupe_folders.append(full_dir_path)
31+
32+
# Move CONTENTS of the dupes to the top folder, since we don't want to keep the folder itself.
33+
# If dupes were found, break the loop at this level of the directory tree, and start over.abs
34+
if len(dupe_folders) > 0:
35+
# Check for case match
36+
# Merge
37+
for f in dupe_folders:
38+
print(f)
39+
if os.path.exists(f):
40+
log_to_ui(f"Moving {f} => {root}")
41+
print(f"Moving {f} => {root}")
42+
shutil.copytree(f, root, dirs_exist_ok=True)
43+
44+
# Only remove the directory if it's...a directory & empty
45+
if os.path.isdir(f):
46+
if not any(os.scandir(f)):
47+
log_to_ui(f"Deleting empty folder: {f}")
48+
shutil.rmtree(f)
49+
else:
50+
print(any(os.scandir(f)))
51+
print(f"Folder not empty, not deleting: {f}")
52+
else:
53+
log_to_ui(f"Can't move to {root}")
54+
log_to_ui(f"Folder doesn't exist (already moved/deleted): {f}")
55+
return False
56+
return True
57+
58+
59+
def check(library_path):
60+
complete = False
61+
counter = 1
62+
while not complete:
63+
log_to_ui(f"Checking {library_path} for recursive folders, iteration {counter}")
64+
complete = fix_recursive(library_path)
65+
counter += 1
66+
67+
log_to_ui("Done fixing recursive folders!")
68+

daz_linux_casefix.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# import DAZFix
2+
13
from PyQt6.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
24
from PyQt6 import uic
35
import qdarktheme
@@ -7,7 +9,10 @@
79
import os
810
import pickle
911

12+
13+
1014
from DAZFix.LibraryFix import fix_libraries, log_to_ui
15+
from DAZFix.RecursiveChecker import check
1116

1217
import globals
1318

@@ -31,6 +36,8 @@ def __init__(self):
3136

3237
self.ui.btnSavePaths.clicked.connect(self.save_paths)
3338

39+
self.ui.btnRecursive.clicked.connect(lambda: check(self.ui.txtUserPath.text()))
40+
3441

3542

3643
def save_paths(self):

0 commit comments

Comments
 (0)