diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c2d9f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,322 @@ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# 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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# 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/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/main.py b/main.py new file mode 100755 index 0000000..d60d8f9 --- /dev/null +++ b/main.py @@ -0,0 +1,109 @@ +import os +import subprocess +import sys +import yaml +import argparse + +from waymore.waymore import continueRespFile +def main(): + parser = argparse.ArgumentParser() + + if "REPO" in os.environ: + repo = os.environ['REPO'] + '/' + print(f"Your current repository path is {repo}. To change it, change the REPO environment variable.") + else: + repo = '' + print("The tool will use the config file from the directory it is running in. If you want to change this," + "set the REPO environment variable.") + + config = repo + 'ptconfig.yml' + with open(config, 'r') as ptcfg: + read_config = yaml.safe_load(ptcfg) + + compose_config = repo + "podman-compose.yml" + + services = read_config['services'] + + parser.add_argument("command", help="command to run") + parser.add_argument("service", help="name of service if applicable, or leave empty for all services", nargs='?', default='') + parser.add_argument("-y", action="store_true", help="automatically confirm any queries") + args = parser.parse_args() + + def create(): + subprocess.run(["rm", "-rf", compose_config]) + invalid_options = ['addons', 'bindings', 'commands'] + with open(config) as oldfile, open(compose_config, 'w') as newfile: + for line in oldfile: + if not any(invalid_option in line for invalid_option in invalid_options): + newfile.write(line) + subprocess.run(["podman-compose", "-f", compose_config, "up", "--no-start"]) + for service in list(read_config['services']): + for index in list(read_config['services'][service]['addons']['bindings']['commands']): + subprocess.run([index]) + + def start(): + start_service = args.service + if start_service == '': + start_service = list(services) + for i in range(len(start_service)): + subprocess.run(["podman-compose", "start", start_service[i]]) + exit(0) + else: + subprocess.run(["podman-compose", "start", start_service]) + exit(0) + + def stop(): + stop_service = args.service + if stop_service == '': + if args.y: + confirm = "y" + else: + confirm = input("Stop all services? (y/N): ") + if confirm.lower() == "y" or confirm.lower() == "yes": + stop_service = list(services) + for i in range(len(stop_service)): + subprocess.run(["podman-compose", "stop", stop_service[i]]) + exit(0) + else: + print("aborting...") + exit(0) + else: + subprocess.run(["podman_compose", "stop", stop_service]) + exit(0) + + def shell(): + subprocess.run(["podman-compose", "exec", args.service, "sh"]) + + def karaf(): + subprocess.run(["podman-compose", "exec", args.service, "/openhab/runtime/bin/client"]) + + def down(): + if args.y: + confirm = "y" + else: + confirm = input("Stop all services and delete all pods? (y/N): ") + if confirm.lower() == "y" or confirm.lower() == "yes": + subprocess.run(["podman-compose", "-f", compose_config, "down"]) + exit(0) + else: + print("aborting...") + exit(0) + + + if args.command == "create": + create() + elif args.command == "start": + start() + elif args.command == "stop": + stop() + elif args.command == "shell": + shell() + elif args.command == "karaf": + karaf() + elif args.command == "down": + down() + + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/ptconfig.yml b/ptconfig.yml new file mode 100755 index 0000000..30a2935 --- /dev/null +++ b/ptconfig.yml @@ -0,0 +1,34 @@ +services: +# alpine1: +# image: redis:alpine +# addons: +# bindings: +# commands: [ls] +# alpine2: +# image: redis:alpine +# addons: +# bindings: +# commands: [ls] + debian: + image: debian:latest + addons: + bindings: + commands: [] +# openhab: +# image: openhab/openhab:latest +# restart: always +# network_mode: host +# volumes: +# - "/etc/localtime:/etc/localtime:ro" +# - "/etc/timezone:/etc/timezone:ro" +# - "./openhab_addons:/openhab/addons" +# - "./openhab_conf:/openhab/conf" +# - "./openhab_userdata:/openhab/userdata" +# environment: +# CRYPTO_POLICY: "unlimited" +# EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin" +# OPENHAB_HTTP_PORT: "8080" +# OPENHAB_HTTPS_PORT: "8443" +# addons: +# bindings: +# commands: [ls] diff --git a/ptconfig_template.yml b/ptconfig_template.yml new file mode 100755 index 0000000..5b10c91 --- /dev/null +++ b/ptconfig_template.yml @@ -0,0 +1,6 @@ +services: + alpine1: + image: #insert image and other config above addons: + addons: + bindings: + commands: [] #insert commands in square brackets \ No newline at end of file