import yaml import os import shutil # Paths SLOT_FIXES_PATH = "/Users/kempersc/apps/glam/data/fixes/slot_fixes.yaml" SLOTS_DIR = "/Users/kempersc/apps/glam/schemas/20251121/linkml/modules/slots/" ARCHIVE_DIR = os.path.join(SLOTS_DIR, "archive") # Ensure archive directory exists os.makedirs(ARCHIVE_DIR, exist_ok=True) def get_processed_slots(fixes_path): processed_slots = [] try: with open(fixes_path, 'r') as f: data = yaml.safe_load(f) if 'fixes' in data: for fix in data['fixes']: if fix.get('processed', {}).get('status') == True: # Extract slot name from URL # e.g., https://nde.nl/ontology/hc/slot/activities_societies -> activities_societies original_id = fix.get('original_slot_id', '') if '/slot/' in original_id: slot_name = original_id.split('/slot/')[-1] processed_slots.append(slot_name) except Exception as e: print(f"Error reading YAML: {e}") # Fallback to simple parsing if yaml load fails (e.g. huge file) # This is less robust but works for simple structure pass return processed_slots def main(): print(f"Reading fixes from {SLOT_FIXES_PATH}...") processed_slots = get_processed_slots(SLOT_FIXES_PATH) print(f"Found {len(processed_slots)} processed slots in fixes file.") # Get current slot files current_files = os.listdir(SLOTS_DIR) moved_count = 0 for slot_name in processed_slots: filename = f"{slot_name}.yaml" src_path = os.path.join(SLOTS_DIR, filename) dst_path = os.path.join(ARCHIVE_DIR, filename) if os.path.exists(src_path): print(f"Moving {filename} to archive...") try: shutil.move(src_path, dst_path) moved_count += 1 except Exception as e: print(f"Failed to move {filename}: {e}") print(f"Operation complete. Archived {moved_count} files.") if __name__ == "__main__": main()