Initial commit
This commit is contained in:
95
skills/django-setup/scripts/create_gitignore.py
Executable file
95
skills/django-setup/scripts/create_gitignore.py
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to create .gitignore file from template.
|
||||
|
||||
Usage:
|
||||
python create_gitignore.py --output /path/to/project
|
||||
python create_gitignore.py --output .
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def create_gitignore(output_dir: str) -> None:
|
||||
"""
|
||||
Copy .gitignore template to the specified output directory.
|
||||
|
||||
Args:
|
||||
output_dir: Directory where .gitignore should be created
|
||||
"""
|
||||
# Get the directory where this script is located
|
||||
script_dir = Path(__file__).parent
|
||||
skill_dir = script_dir.parent
|
||||
|
||||
# Path to the template
|
||||
template_path = skill_dir / "examples" / ".gitignore-template"
|
||||
|
||||
# Validate template exists
|
||||
if not template_path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Template not found at: {template_path}\n"
|
||||
f"Expected location: .claude/skills/django-setup/examples/.gitignore-template"
|
||||
)
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
output_path = Path(output_dir).resolve()
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Destination path
|
||||
gitignore_path = output_path / ".gitignore"
|
||||
|
||||
# Check if .gitignore already exists
|
||||
if gitignore_path.exists():
|
||||
print(f"⚠️ .gitignore already exists at: {gitignore_path}")
|
||||
print("❌ Script should only be used when .gitignore does not exist.")
|
||||
print("💡 Use manual merging to add missing entries from the template.")
|
||||
exit(1)
|
||||
|
||||
# Copy the template
|
||||
shutil.copy2(template_path, gitignore_path)
|
||||
|
||||
print(f"✅ Created .gitignore at: {gitignore_path}")
|
||||
print(f"📋 Copied from template: {template_path}")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Create .gitignore file from template for Django projects",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Create .gitignore in current directory
|
||||
python create_gitignore.py --output .
|
||||
|
||||
# Create .gitignore in specific project directory
|
||||
python create_gitignore.py --output /path/to/project
|
||||
|
||||
# Create .gitignore in parent directory
|
||||
python create_gitignore.py --output ..
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--output',
|
||||
type=str,
|
||||
required=True,
|
||||
help='Directory where .gitignore should be created (e.g., . for current directory)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
create_gitignore(args.output)
|
||||
except FileNotFoundError as e:
|
||||
print(f"❌ Error: {e}")
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
print(f"❌ Unexpected error: {e}")
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user