Initial commit
This commit is contained in:
83
install_data.py
Normal file
83
install_data.py
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Installation script for GitRepoSetup package data.
|
||||
Copies licenses, .gitignore, and workflows to the appdirs data directory.
|
||||
"""
|
||||
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_git_user_name():
|
||||
"""Get git user.name from config."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "config", "user.name"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
return "Default"
|
||||
|
||||
|
||||
def install_package_data():
|
||||
"""Copy package data files to appdirs location."""
|
||||
# Get source and destination directories
|
||||
repo_root = Path(__file__).parent
|
||||
|
||||
# Get git user name for the appdata path
|
||||
git_user = get_git_user_name()
|
||||
|
||||
# Construct appdata path: {appdata}/{git_user.name}/GitRepoSetup
|
||||
if platform.system() == "Windows":
|
||||
appdata = Path(os.environ.get("APPDATA", Path.home() / "AppData" / "Roaming"))
|
||||
else:
|
||||
appdata = Path.home() / ".local" / "share"
|
||||
|
||||
data_dir = appdata / git_user / "GitRepoSetup"
|
||||
|
||||
print(f"Installing package data to: {data_dir}")
|
||||
|
||||
# Create data directory
|
||||
data_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Copy licenses
|
||||
licenses_src = repo_root / "licenses"
|
||||
licenses_dst = data_dir / "licenses"
|
||||
|
||||
if licenses_src.exists():
|
||||
if licenses_dst.exists():
|
||||
shutil.rmtree(licenses_dst)
|
||||
shutil.copytree(licenses_src, licenses_dst)
|
||||
print(f"✓ Copied {len(list(licenses_dst.glob('*.txt')))} license files")
|
||||
|
||||
# Copy .gitignore
|
||||
gitignore_src = repo_root / ".gitignore"
|
||||
gitignore_dst = data_dir / ".gitignore"
|
||||
|
||||
if gitignore_src.exists():
|
||||
shutil.copy2(gitignore_src, gitignore_dst)
|
||||
print("✓ Copied .gitignore")
|
||||
|
||||
# Copy .gitea directory
|
||||
gitea_src = repo_root / ".gitea"
|
||||
gitea_dst = data_dir / ".gitea"
|
||||
|
||||
if gitea_src.exists():
|
||||
if gitea_dst.exists():
|
||||
shutil.rmtree(gitea_dst)
|
||||
shutil.copytree(gitea_src, gitea_dst)
|
||||
workflows_count = len(list((gitea_dst / "workflows").glob("*.yml")))
|
||||
print(f"✓ Copied .gitea directory with {workflows_count} workflow files")
|
||||
|
||||
print("\n✅ Package data installed successfully!")
|
||||
print(f" Location: {data_dir}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
install_package_data()
|
||||
Reference in New Issue
Block a user