forked from ss14Starlight/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAP_FIX.py
More file actions
53 lines (45 loc) · 1.39 KB
/
MAP_FIX.py
File metadata and controls
53 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import re
import sys
import os
# Replace target regex matches
def transform_text(file):
pattern = r'- - (.*?)\n {10}- (.*)'
return re.sub(pattern, r'- \1: \2', file)
#Processes every file
def process_file(filepath):
# Read file
with open(filepath, 'r', encoding='utf-8') as file:
filedata = file.read()
#run the replace
newdata = transform_text(filedata)
# Write file
with open(filepath, 'w', encoding='utf-8') as file:
file.write(newdata)
print(f"Processed: {filepath}")
#Processes file or processes all files
def process_path(path):
#single file
if os.path.isfile(path):
#return if not .yml
if not path.endswith('.yml'):
return
process_file(path)
#folder
elif os.path.isdir(path):
for root, _, files in os.walk(path):
for name in files:
if name.endswith('.yml'):
process_file(os.path.join(root, name))
else:
print(f"Path not found: {path}")
if __name__ == "__main__":
#check for necessary filepath
if len(sys.argv) < 2:
print("Usage: MAP_FIX.py <path-to-.yml-file-or-directory>")
sys.exit(1)
input_path = sys.argv[1]
#Convert to absolute path
script_dir = os.path.dirname(os.path.abspath(__file__))
full_path = os.path.join(script_dir, input_path)
process_path(full_path)