-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_offset.py
37 lines (27 loc) · 1.06 KB
/
config_offset.py
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
import sys
def apply_offset(file_path, offset):
try:
with open(file_path, 'r') as file:
content = file.read()
if not content.startswith("ForceKeyFrames : "):
print("The file does not contain the expected format.")
return
prefix = "ForceKeyFrames : "
frame_numbers = content[len(prefix):].strip().split(',')
offset = int(offset)
updated_frame_numbers = [
f"{int(num[:-1]) + offset}f" for num in frame_numbers if int(num[:-1]) >= abs(offset) or offset > 0
]
updated_content = prefix + ','.join(updated_frame_numbers)
with open(file_path, 'w') as file:
file.write(updated_content)
print("The file has been updated successfully.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py path/to/file.config offset")
else:
file_path = sys.argv[1]
offset = sys.argv[2]
apply_offset(file_path, offset)