image-builder/utils/common.py

21 lines
676 B
Python
Raw Normal View History

2024-11-13 12:52:55 +00:00
#!/usr/bin/env python
2024-11-14 19:35:34 +03:00
import os
import subprocess
2024-11-13 12:52:55 +00:00
def load_config(config_path):
config = {}
with open(config_path, "r") as f:
for line in f:
if "=" in line and not line.strip().startswith("#"):
key, value = line.strip().split("=", 1)
config[key] = value.strip('"')
return config
2024-11-14 19:35:34 +03:00
def clone_repo(repo_url, branch, dest_dir, name):
if os.path.exists(dest_dir):
print(f"Warning: {name} directory '{dest_dir}' already exists. Skipping clone.")
else:
os.makedirs(dest_dir, exist_ok=True)
subprocess.run(["git", "clone", "--depth", "1", repo_url, "-b", branch, dest_dir], check=True)