Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 16, 2026
1 parent e6b1167 commit 32457e7
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions local-app/python-tools/sso-tools/sso-create-sc-group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/env python

import argparse
import shutil
from pathlib import Path
from jinja2 import Environment, FileSystemLoader

__version__ = "1.0.0"

def create_sc_group():
parser = argparse.ArgumentParser(description="Automate file creation from templates.")
parser.add_argument("-b", "--business-label", required=True, help="Required business label")
parser.add_argument("-a", "--application-label", help="Optional application label")
parser.add_argument("-g", "--group", help="Group name (defaults to current directory name)")
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")

args = parser.parse_args()

# 1. Logic for group name and folder naming
group_name = args.group if args.group else Path.cwd().name

# Construct created_group name based on presence of application_label
if args.application_label:
created_group = f"{args.business_label}-{args.application_label}-{group_name}"
else:
created_group = f"{args.business_label}-{group_name}"

# 2. Setup paths
template_dir = Path("TEMPLATE")
target_dir = Path(created_group)

if not template_dir.exists():
print(f"Error: {template_dir} directory not found.")
return

target_dir.mkdir(parents=True, exist_ok=True)

# 3. Initialize Jinja2 Environment
env = Environment(loader=FileSystemLoader(str(template_dir)))

# 4. Expose all arguments as variables for rendering
# This dictionary maps exactly to what you can use in your {{ }} tags
render_vars = {
"business_label": args.business_label,
"application_label": args.application_label,
"group": group_name,
"created_group": created_group
}

print(f"Processing templates for: {created_group}...")

# 5. File Processing Loop
for item in template_dir.iterdir():
if item.is_dir():
continue # Skips subdirectories

if item.suffix == ".j2":
# Target logic: Replace 'GROUP' with created_group and strip '.j2'
new_filename = item.name.replace("GROUP", created_group).replace(".j2", "")
target_path = target_dir / new_filename

# Load and render
template = env.get_template(item.name)
output_content = template.render(render_vars)

target_path.write_text(output_content)
print(f" [Rendered] {item.name} -> {new_filename}")

else:
# Standard copy for non-template files
shutil.copy2(item, target_dir / item.name)
print(f" [Copied] {item.name}")

print(f"\nSuccessfully created group directory: {created_group}")

if __name__ == "__main__":
create_sc_group()

0 comments on commit 32457e7

Please sign in to comment.