Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomii committed Feb 10, 2025
1 parent ce19d54 commit 28088ad
Show file tree
Hide file tree
Showing 35 changed files with 1,315 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests

on:
push:
pull_request:

jobs:
Lint:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: sudo apt update && sudo apt install --yes tox
- name: Flake8
run: |
tox -e pep8
tests:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.10", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: sudo apt update && sudo apt install --yes tox
- name: Unit tests
run: |
tox -e ${{ matrix.python-version }}
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# editors
*~

# IDE
.idea/
.vscode

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
deps/
docker/common/bin
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
AUTHORS
ChangeLog
cover/
version.txt

# OS
.DS_Store

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
.testrepository/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Documentation
docs/build
docs/source/*.png

# Vagrant
.vagrant/
Empty file added gst_templates/__init__.py
Empty file.
Empty file added gst_templates/cmd/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions gst_templates/cmd/create_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2025 Genesis Corporation.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import sys

from oslo_config import cfg

from gst_templates.common import config


cli_opts = [
cfg.StrOpt(
"template-settings",
default="./templates/py_dummy.settings.json",
help="The path to the template settings file.",
),
cfg.StrOpt(
"target-directory",
help="The path to the target directory.",
),
]


CONF = cfg.CONF
CONF.register_cli_opts(cli_opts)


def main():
config.parse(sys.argv[1:])


if __name__ == "__main__":
main()
73 changes: 73 additions & 0 deletions gst_templates/cmd/init_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2025 Genesis Corporation.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import logging
import sys

from oslo_config import cfg

from gst_templates.common import config
from gst_templates.common import log as infra_log
from gst_templates import renders
from gst_templates import repositories
from gst_templates import settings


cli_opts = [
cfg.StrOpt(
"template_settings",
default="./templates/py_dummy.settings.json",
help="The path to the template settings file.",
),
cfg.StrOpt(
"target_directory",
help="The path to the target directory.",
),
]


CONF = cfg.CONF
CONF.register_cli_opts(cli_opts)


def main():
# Parse config
config.parse(sys.argv[1:])

# Configure logging
infra_log.configure()
log = logging.getLogger(__name__)

template_setting = settings.TemplateSetting(CONF.template_settings)

repository = repositories.GitRepository(CONF.target_directory)
repository.initialize_repository()
if repository.has_uncommitted_changes():
log.error("The target directory contains uncommitted changes.")
sys.exit(-1)

template_render = renders.JinjaTemplateRender(
template_setting,
repository,
)
template_render.initialize_project_settings()
template_render.render_template()

log.info("Bye!!!")


if __name__ == "__main__":
main()
Empty file.
48 changes: 48 additions & 0 deletions gst_templates/common/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2025 Genesis Corporation.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import logging

from oslo_config import cfg

from gst_templates.common import constants
from gst_templates import version


GLOBAL_SERVICE_NAME = constants.GLOBAL_SERVICE_NAME


_CONFIG_NOT_FOUND_MESSAGE = (
"Unable to find configuration file in the"
" default search paths (~/.%(service_name)s/, ~/,"
" /etc/%(service_name)s/, /etc/) and the '--config-file' option!"
% {"service_name": GLOBAL_SERVICE_NAME}
)


def parse(args):
cfg.CONF(
args=args,
project=GLOBAL_SERVICE_NAME,
version="%s %s"
% (
GLOBAL_SERVICE_NAME.capitalize(),
version.version_info,
),
)
if not cfg.CONF.config_file:
logging.warning(_CONFIG_NOT_FOUND_MESSAGE)
return cfg.CONF.config_file
18 changes: 18 additions & 0 deletions gst_templates/common/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 Genesis Corporation.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# project
GLOBAL_SERVICE_NAME = "templater"
Loading

0 comments on commit 28088ad

Please sign in to comment.