[main] Git stuff

This commit is contained in:
2024-12-09 18:31:01 +01:00
parent 61e0c670c6
commit 9764bb4c63
11 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1 @@
shiv -c project-installer -o ../../../project-installer .

View File

View File

@@ -0,0 +1,61 @@
import os
import random
import pystache
import argparse
import re
def render_templates(template_dir, project_name):
import pystache # Import after ensuring it's installed
# Generate a random port number
port = random.randint(8900, 9400)
# Mustache data (dynamic placeholders)
data = {
"PROJECT_NAME": project_name,
"PORT": port
}
# Define a regex for detecting [[ ... ]] custom placeholders
pattern = re.compile(r"\[\[(.*?)\]\]")
# Process all .tmpl files in the directory
for root, _, files in os.walk(template_dir):
for file in files:
if file.endswith(".tmpl"):
tmpl_file = os.path.join(root, file)
output_file = os.path.join(root, file.replace(".tmpl", ""))
# Read the template file
with open(tmpl_file, 'r') as f:
template_content = f.read()
# Replace placeholders wrapped with [[ ... ]]
def replace_placeholder(match):
key = match.group(1)
return str(data.get(key, match.group(0))) # Replace only if key exists
rendered_content = pattern.sub(replace_placeholder, template_content)
# Write to output file
with open(output_file, 'w') as f:
f.write(rendered_content)
print(f"Generated: {output_file}")
def main():
# Parse arguments
parser = argparse.ArgumentParser(description="Render Mustache templates in a directory.")
parser.add_argument('--project-name', type=str, help='Project name (defaults to current directory name)')
parser.add_argument('--template-dir', type=str, default='.gitea/workflows', help='Template directory')
args = parser.parse_args()
# Get the project name (current directory name if not provided)
project_name = args.project_name or os.path.basename(os.getcwd())
# Render templates
render_templates(args.template_dir, project_name)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,5 @@
Metadata-Version: 2.1
Name: project-installer
Version: 0.1.0
Summary: Project Installer Tool
Requires-Dist: pystache

View File

@@ -0,0 +1,9 @@
README.md
project_installer.py
setup.py
project_installer.egg-info/PKG-INFO
project_installer.egg-info/SOURCES.txt
project_installer.egg-info/dependency_links.txt
project_installer.egg-info/entry_points.txt
project_installer.egg-info/requires.txt
project_installer.egg-info/top_level.txt

View File

@@ -0,0 +1,2 @@
[console_scripts]
project-installer = project_installer:main

View File

@@ -0,0 +1 @@
pystache

View File

@@ -0,0 +1 @@
project_installer

View File

@@ -0,0 +1,61 @@
import os
import random
import pystache
import argparse
import re
def render_templates(template_dir, project_name):
import pystache # Import after ensuring it's installed
# Generate a random port number
port = random.randint(8900, 9400)
# Mustache data (dynamic placeholders)
data = {
"PROJECT_NAME": project_name,
"PORT": port
}
# Define a regex for detecting [[ ... ]] custom placeholders
pattern = re.compile(r"\[\[(.*?)\]\]")
# Process all .tmpl files in the directory
for root, _, files in os.walk(template_dir):
for file in files:
if file.endswith(".tmpl"):
tmpl_file = os.path.join(root, file)
output_file = os.path.join(root, file.replace(".tmpl", ""))
# Read the template file
with open(tmpl_file, 'r') as f:
template_content = f.read()
# Replace placeholders wrapped with [[ ... ]]
def replace_placeholder(match):
key = match.group(1)
return str(data.get(key, match.group(0))) # Replace only if key exists
rendered_content = pattern.sub(replace_placeholder, template_content)
# Write to output file
with open(output_file, 'w') as f:
f.write(rendered_content)
print(f"Generated: {output_file}")
def main():
# Parse arguments
parser = argparse.ArgumentParser(description="Render Mustache templates in a directory.")
parser.add_argument('--project-name', type=str, help='Project name (defaults to current directory name)')
parser.add_argument('--template-dir', type=str, default='.gitea/workflows', help='Template directory')
args = parser.parse_args()
# Get the project name (current directory name if not provided)
project_name = args.project_name or os.path.basename(os.getcwd())
# Render templates
render_templates(args.template_dir, project_name)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,14 @@
from setuptools import setup
setup(
name="project-installer", # Name of your package
version="0.1.0", # Version of your package
description="Project Installer Tool", # Short description
py_modules=["project_installer"], # Module(s) to include (no .py extension)
install_requires=["pystache"], # List of dependencies
entry_points={
"console_scripts": [
"project-installer=project_installer:main", # Entry point
],
},
)