67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
import os
|
|
|
|
def update_yaml_with_script(yaml_path, script_path, key_line_start):
|
|
with open(script_path, 'r', encoding='utf-8') as f:
|
|
script_content = f.read()
|
|
|
|
# Indent script content by 4 spaces
|
|
indented_script = '\n'.join(' ' + line if line.strip() else line for line in script_content.splitlines())
|
|
|
|
with open(yaml_path, 'r', encoding='utf-8') as f:
|
|
yaml_lines = f.readlines()
|
|
|
|
# Find the key line (e.g., " app.py: |")
|
|
start_index = -1
|
|
for i, line in enumerate(yaml_lines):
|
|
if key_line_start in line:
|
|
start_index = i + 1
|
|
break
|
|
|
|
if start_index == -1:
|
|
print(f"Error: Could not find '{key_line_start}' in {yaml_path}")
|
|
return
|
|
|
|
# Find where the script block ends (next line that is NOT indented by at least 4 spaces, or EOF)
|
|
# Actually, the Data block might be the last thing.
|
|
# We assume the script goes until the end of the file or next unindented key.
|
|
# In these files, the script is usually the main data.
|
|
# Let's just truncate and append if it looks like the script is the last/main thing.
|
|
# But usually, it's safer to just replace the lines that look like script.
|
|
|
|
# Simple heuristic: The script block ends when indentation drops to 2 spaces or 0?
|
|
# In worker-script.yaml:
|
|
# 6: data:
|
|
# 7: worker.py: |
|
|
# 8: ...script...
|
|
# The script is indented by 4 spaces.
|
|
|
|
pre_script = yaml_lines[:start_index]
|
|
|
|
# We will just write the pre_script + indented_script
|
|
# WARNING: If there are other keys after worker.py, this deletes them.
|
|
# Let's check the files.
|
|
# worker-script.yaml: 378 lines. Script ends at 378. Nothing follows.
|
|
# fiesta-gateway.yaml: 407 lines. Script ends at 407. Nothing follows.
|
|
# So appending is SAFE.
|
|
|
|
with open(yaml_path, 'w', encoding='utf-8') as f:
|
|
f.writelines(pre_script)
|
|
f.write(indented_script)
|
|
f.write('\n') # Ensure newline at EOF
|
|
|
|
print(f"Successfully updated {yaml_path}")
|
|
|
|
# Update Fiesta Gateway
|
|
update_yaml_with_script(
|
|
r'e:\nats\kubernetes\manifests\nearle\fiesta-gateway.yaml',
|
|
r'e:\nats\kubernetes\conf\app.py',
|
|
' app.py: |'
|
|
)
|
|
|
|
# Update Worker Script
|
|
update_yaml_with_script(
|
|
r'e:\nats\kubernetes\manifests\core\worker-script.yaml',
|
|
r'e:\nats\kubernetes\conf\worker.py',
|
|
' worker.py: |'
|
|
)
|