|
6 | 6 | OUTPUT_FUNCTIONS = "../../functions" |
7 | 7 | OUTPUT_EVENTS = "../../events" |
8 | 8 |
|
| 9 | +# Set this to True to copy to a temporary directory first |
| 10 | +# Then you can manually review the copied files before moving them to the final destination |
| 11 | +COPY_TO_TEMP_DIR = True |
| 12 | +TEMP_DIR = "./temp_copy" |
| 13 | + |
9 | 14 | def copy_files(page_type, source_dir, target_dir): |
| 15 | + |
| 16 | + copied_function_names = set() |
| 17 | + # First copy YAML files |
10 | 18 | for root, dirs, files in os.walk(source_dir): |
11 | 19 | for file in files: |
12 | 20 | if file.endswith(".yaml"): |
13 | 21 | src_path = os.path.join(root, file) |
14 | 22 | rel_path = os.path.relpath(src_path, source_dir) |
15 | 23 | dest_path = os.path.join(target_dir, rel_path) |
| 24 | + copy_to_dest_path = os.path.join(TEMP_DIR, page_type, rel_path) if COPY_TO_TEMP_DIR else dest_path |
16 | 25 |
|
17 | | - if not os.path.exists(dest_path): |
18 | | - # Don't copy because it doesn't exist in the output |
19 | | - print(f"(YAML) Skipping {dest_path} because it doesn't exist in the output") |
20 | | - continue |
21 | | - else: |
| 26 | + if os.path.exists(dest_path): |
22 | 27 | with open(dest_path, 'r', encoding='utf-8') as dest_file: |
23 | 28 | content = dest_file.read() |
24 | 29 | if 'incomplete: true' not in content: |
25 | | - print(f"(YAML) Skipping {dest_path} because it's not marked as incomplete") |
| 30 | + print(f"(YAML) Skipping {dest_path} because it is not incomplete") |
26 | 31 | continue |
27 | 32 |
|
28 | | - os.makedirs(os.path.dirname(dest_path), exist_ok=True) |
29 | | - print(f"(YAML) Copying {src_path} to {dest_path}") |
| 33 | + os.makedirs(os.path.dirname(copy_to_dest_path), exist_ok=True) |
| 34 | + print(f"(YAML) Copying {src_path} to {copy_to_dest_path}") |
30 | 35 | with open(src_path, 'r', encoding='utf-8') as src_file: |
31 | | - with open(dest_path, 'w', encoding='utf-8') as dest_file: |
| 36 | + with open(copy_to_dest_path, 'w', encoding='utf-8') as dest_file: |
32 | 37 | src_file_content = src_file.read() |
33 | 38 | # Hack: replace name: y with name: "y" |
34 | 39 | # because that's a YAML reserved keyword xD |
35 | 40 | src_file_content = src_file_content.replace("name: y", 'name: "y"') |
36 | 41 | dest_file.write(src_file_content) |
| 42 | + copied_function_names.add(file[:-5]) # Remove .yaml extension |
37 | 43 |
|
38 | | - elif file.endswith(".lua"): |
39 | | - # Copy all .lua files too |
| 44 | + # Copy corresponding .lua files too |
| 45 | + for root, dirs, files in os.walk(source_dir): |
| 46 | + for file in files: |
| 47 | + if file.endswith(".lua"): |
| 48 | + # Ignore if we haven't copied the corresponding YAML file |
| 49 | + function_name = file[:-4] # Remove .lua extension |
| 50 | + if function_name not in copied_function_names: |
| 51 | + print(f"(Lua) Skipping {file} because corresponding YAML was not copied") |
| 52 | + continue |
40 | 53 | src_path = os.path.join(root, file) |
41 | 54 | rel_path = os.path.relpath(src_path, source_dir) |
42 | 55 | dest_path = os.path.join(target_dir, rel_path) |
| 56 | + copy_to_dest_path = os.path.join(TEMP_DIR, page_type, rel_path) if COPY_TO_TEMP_DIR else dest_path |
43 | 57 | os.makedirs(os.path.dirname(dest_path), exist_ok=True) |
44 | | - print(f"(Lua) Copying {src_path} to {dest_path}") |
| 58 | + print(f"(Lua) Copying {src_path} to {copy_to_dest_path}") |
45 | 59 | with open(src_path, 'r', encoding='utf-8') as src_file: |
46 | | - with open(dest_path, 'w', encoding='utf-8') as dest_file: |
| 60 | + with open(copy_to_dest_path, 'w', encoding='utf-8') as dest_file: |
47 | 61 | dest_file.write(src_file.read()) |
48 | 62 |
|
49 | 63 | if __name__ == "__main__": |
|
0 commit comments