90 lines
3.5 KiB
Python
90 lines
3.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
import subprocess
|
||
|
|
|
||
|
|
# Determine base path: use FACTORY_PATH env var, or default to ../../.standards/factory relative to this script
|
||
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||
|
|
DEFAULT_FACTORY_PATH = os.path.abspath(os.path.join(SCRIPT_DIR, "../../.standards/factory"))
|
||
|
|
FACTORY_PATH = os.environ.get("FACTORY_PATH", DEFAULT_FACTORY_PATH)
|
||
|
|
|
||
|
|
REPO_URL = "git@bitbucket.org:reltio-ondemand/transparent-factory.git"
|
||
|
|
|
||
|
|
def ensure_directory(path):
|
||
|
|
"""Ensure the parent directory exists."""
|
||
|
|
parent = os.path.dirname(path)
|
||
|
|
if not os.path.exists(parent):
|
||
|
|
print(f"📂 Creating directory: {parent}")
|
||
|
|
os.makedirs(parent, exist_ok=True)
|
||
|
|
|
||
|
|
def update_or_clone():
|
||
|
|
"""Clone the Transparent Factory repo if missing, pull if present."""
|
||
|
|
ensure_directory(FACTORY_PATH)
|
||
|
|
|
||
|
|
# Check if it's already a git repo
|
||
|
|
if os.path.exists(os.path.join(FACTORY_PATH, ".git")):
|
||
|
|
print(f"🔄 Updating Transparent Factory Standards...")
|
||
|
|
try:
|
||
|
|
subprocess.run(["git", "pull"], cwd=FACTORY_PATH, check=True)
|
||
|
|
print(f"✅ Standards updated at {FACTORY_PATH}.")
|
||
|
|
except subprocess.CalledProcessError as e:
|
||
|
|
print(f"❌ Update failed: {e}")
|
||
|
|
|
||
|
|
# Check if directory exists but is empty (safe to clone into)
|
||
|
|
elif os.path.exists(FACTORY_PATH) and not os.listdir(FACTORY_PATH):
|
||
|
|
print(f"📥 Cloning Transparent Factory Standards into empty directory...")
|
||
|
|
try:
|
||
|
|
subprocess.run(["git", "clone", REPO_URL, "."], cwd=FACTORY_PATH, check=True)
|
||
|
|
print(f"✅ Standards cloned to {FACTORY_PATH}.")
|
||
|
|
except subprocess.CalledProcessError as e:
|
||
|
|
print(f"❌ Clone failed: {e}")
|
||
|
|
|
||
|
|
# Directory doesn't exist at all
|
||
|
|
elif not os.path.exists(FACTORY_PATH):
|
||
|
|
print(f"📥 Cloning Transparent Factory Standards...")
|
||
|
|
try:
|
||
|
|
subprocess.run(["git", "clone", REPO_URL, FACTORY_PATH], check=True)
|
||
|
|
print(f"✅ Standards cloned to {FACTORY_PATH}.")
|
||
|
|
except subprocess.CalledProcessError as e:
|
||
|
|
print(f"❌ Clone failed: {e}")
|
||
|
|
|
||
|
|
else:
|
||
|
|
print(f"⚠️ Target directory {FACTORY_PATH} exists and is not empty (and not a git repo). Skipping.")
|
||
|
|
|
||
|
|
def list_standards():
|
||
|
|
"""List available standards and PR/FAQ documents."""
|
||
|
|
if not os.path.exists(FACTORY_PATH):
|
||
|
|
return "Standards not found. Run 'factory_update' first."
|
||
|
|
|
||
|
|
print("--- Core Documents ---")
|
||
|
|
try:
|
||
|
|
# Look for the primary PR/FAQ or README
|
||
|
|
print(subprocess.getoutput(f"find {FACTORY_PATH} -maxdepth 1 -name '*.md' | sort"))
|
||
|
|
|
||
|
|
# Look inside the content folder
|
||
|
|
content_path = os.path.join(FACTORY_PATH, "content")
|
||
|
|
if os.path.exists(content_path):
|
||
|
|
print("\n--- Tenets & Content ---")
|
||
|
|
print(subprocess.getoutput(f"find {content_path} -name '*.md' | sort"))
|
||
|
|
|
||
|
|
# Look inside skills folder
|
||
|
|
skills_path = os.path.join(FACTORY_PATH, "skills")
|
||
|
|
if os.path.exists(skills_path):
|
||
|
|
print("\n--- Available Factory Skills ---")
|
||
|
|
print(subprocess.getoutput(f"find {skills_path} -name 'SKILL.md' | sort"))
|
||
|
|
except Exception as e:
|
||
|
|
return f"Error listing files: {e}"
|
||
|
|
|
||
|
|
return ""
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
action = sys.argv[1] if len(sys.argv) > 1 else "list"
|
||
|
|
|
||
|
|
if action == "update":
|
||
|
|
update_or_clone()
|
||
|
|
elif action == "list":
|
||
|
|
print(list_standards())
|
||
|
|
else:
|
||
|
|
print(f"Unknown action: {action}")
|
||
|
|
sys.exit(1)
|