[main] Git stuff
This commit is contained in:
1
.gitea/installers/renders/README.md
Normal file
1
.gitea/installers/renders/README.md
Normal file
@@ -0,0 +1 @@
|
||||
shiv -c project-installer -o ../../../project-installer .
|
||||
0
.gitea/installers/renders/__init__.py
Normal file
0
.gitea/installers/renders/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: project-installer
|
||||
Version: 0.1.0
|
||||
Summary: Project Installer Tool
|
||||
Requires-Dist: pystache
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[console_scripts]
|
||||
project-installer = project_installer:main
|
||||
@@ -0,0 +1 @@
|
||||
pystache
|
||||
@@ -0,0 +1 @@
|
||||
project_installer
|
||||
61
.gitea/installers/renders/project_installer.py
Normal file
61
.gitea/installers/renders/project_installer.py
Normal 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()
|
||||
|
||||
14
.gitea/installers/renders/setup.py
Normal file
14
.gitea/installers/renders/setup.py
Normal 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
|
||||
],
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user