Miscs
This commit is contained in:
+32
-31
@@ -12,19 +12,30 @@ def main():
|
||||
work_dir = os.path.abspath(sys.argv[1])
|
||||
bnot_dir = sys.argv[2]
|
||||
target_subdir = os.path.join(work_dir, "A Rendre")
|
||||
|
||||
os.makedirs(target_subdir, exist_ok=True)
|
||||
|
||||
# --- 1. Load the expected names list ---
|
||||
expected_names = set()
|
||||
names_path = os.path.join(work_dir, "names")
|
||||
if not os.path.exists(names_path):
|
||||
names_path = "names" # Fallback to current dir
|
||||
|
||||
if os.path.exists(names_path):
|
||||
with open(names_path, 'r', encoding='utf-8') as f:
|
||||
expected_names = {line.strip() for line in f if line.strip()}
|
||||
else:
|
||||
print(f"Warning: 'names' file not found in {work_dir} or current directory.")
|
||||
|
||||
# --- 2. Existing Collection Logic ---
|
||||
pattern = re.compile(r"^Copie(\d+)\.json$")
|
||||
copies_map = defaultdict(list)
|
||||
assigned_names = set() # To track which names were successfully linked
|
||||
|
||||
# 1. Collect all data
|
||||
for filename in os.listdir(work_dir):
|
||||
match = pattern.match(filename)
|
||||
if match:
|
||||
copie_id = match.group(1)
|
||||
json_path = os.path.join(work_dir, filename)
|
||||
|
||||
try:
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
@@ -33,7 +44,7 @@ def main():
|
||||
except Exception as e:
|
||||
print(f"Error processing {filename}: {e}")
|
||||
|
||||
# 2. Check constraints and symlink files
|
||||
# --- 3. Process and Link ---
|
||||
for name, ids in copies_map.items():
|
||||
if name == "Unknown":
|
||||
print(f"ALERT: 'Unknown' name found for IDs: {', '.join(ids)}")
|
||||
@@ -46,50 +57,40 @@ def main():
|
||||
path_b = os.path.join(work_dir, f"{bnot_dir}/Copie{copie_id}")
|
||||
path_a = os.path.join(work_dir, f"Anot/Copie{copie_id}")
|
||||
|
||||
# Determine source: must contain both files
|
||||
source_folder = None
|
||||
|
||||
# Check Bnot first
|
||||
if (os.path.exists(os.path.join(path_b, "Concat.jpg")) and
|
||||
os.path.exists(os.path.join(path_b, "score.json"))):
|
||||
if os.path.exists(os.path.join(path_b, "Concat.jpg")) and os.path.exists(os.path.join(path_b, "score.json")):
|
||||
source_folder = path_b
|
||||
# Fallback to Anot
|
||||
elif (os.path.exists(os.path.join(path_a, "Concat.jpg")) and
|
||||
os.path.exists(os.path.join(path_a, "score.json"))):
|
||||
print(f"Debug : couldn't find {path_b} falling back to Anot path")
|
||||
elif os.path.exists(os.path.join(path_a, "Concat.jpg")) and os.path.exists(os.path.join(path_a, "score.json")):
|
||||
source_folder = path_a
|
||||
|
||||
if not source_folder:
|
||||
print(f"Skipping ID {copie_id}: Files missing in both Anot and {bnot_dir}.")
|
||||
continue
|
||||
|
||||
# Create destination directory
|
||||
dest_folder_name = safe_name if len(ids) == 1 else f"{safe_name} ({copie_id})"
|
||||
# If we reached here, the link is possible
|
||||
assigned_names.add(name)
|
||||
|
||||
dest_folder_name = f"{safe_name} ({copie_id})"
|
||||
dest_path = os.path.join(target_subdir, dest_folder_name)
|
||||
os.makedirs(dest_path, exist_ok=True)
|
||||
|
||||
common = os.path.commonpath([source_folder, dest_path])
|
||||
s = os.path.relpath(source_folder, common)
|
||||
d = os.path.relpath(dest_path, common)
|
||||
|
||||
print(f"Linking '{s}' -> '{d}'")
|
||||
|
||||
# Link configuration: (source_filename, dest_filename)
|
||||
links = [
|
||||
("Concat.jpg", f"{safe_name}.jpg"),
|
||||
("score.json", "score.json")
|
||||
]
|
||||
|
||||
links = [("Concat.jpg", f"{safe_name}.jpg"), ("score.json", "score.json")]
|
||||
for src_name, dst_name in links:
|
||||
src_file = os.path.join(source_folder, src_name)
|
||||
dst_link = os.path.join(dest_path, dst_name)
|
||||
|
||||
try:
|
||||
if os.path.lexists(dst_link):
|
||||
os.remove(dst_link)
|
||||
if os.path.lexists(dst_link): os.remove(dst_link)
|
||||
os.symlink(src_file, dst_link)
|
||||
except Exception as e:
|
||||
print(f"Error linking {src_name} for {dest_folder_name}: {e}")
|
||||
|
||||
# --- 4. Print Unassigned Names ---
|
||||
unassigned = expected_names - assigned_names
|
||||
if unassigned:
|
||||
print("\n" + "!" * 40)
|
||||
print("NAMES FROM LIST NOT ASSIGNED:")
|
||||
for n in sorted(unassigned):
|
||||
print(f" - {n}")
|
||||
print("!" * 40)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user