From 5e98ed5289f7941f45f9a428767d8d7a825832bc Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 3 Oct 2025 00:29:08 +0200 Subject: [PATCH] Added install_module.py script for download modules for paramecio using git --- paramecio2/scripts/install_module.py | 80 ++++++++++++++++++++++++++++ pyproject.toml | 3 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 paramecio2/scripts/install_module.py diff --git a/paramecio2/scripts/install_module.py b/paramecio2/scripts/install_module.py new file mode 100644 index 0000000..d50ae5e --- /dev/null +++ b/paramecio2/scripts/install_module.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +import traceback +import argparse +import os,sys +import shutil +import getpass +from pathlib import Path +from importlib import import_module +from paramecio2.libraries.slugify import slugify +import json +import subprocess + +sys.path.insert(0, os.path.realpath('.')) + +try: + + from settings import config + +except: + + pass + + +def start(): + """Module for create new modules for paramecio + """ + + parser=argparse.ArgumentParser(description='A tool for add modules for paramecio from git url') + + parser.add_argument('--git_url', help='The git url for clone the module.', required=True) + + args=parser.parse_args() + + workdir='.' + + os.chdir('./modules/') + + if subprocess.call("git clone {}".format(args.git_url), shell=True) > 0: + print('Error, cannot install the git module. Do you have installed git?. Is a correct url?') + exit(1) + + real_path='' + + with os.scandir('.') as d: + for e in d: + #print(e.name) + if not e.name in config.apps: + #print(e.name) + if args.git_url.find(e.name)!=-1: + real_path=e.name + + # Add to json configuration. + + os.chdir('../') + + if real_path!='': + + if os.path.isfile('settings/modules.json'): + + modules_json={} + + with open('settings/modules.json') as f: + + #apps={'monit2': ['modules.monit2', 'monit2_app', '/'], 'welcome': ['paramecio2.modules.welcome', 'welcome_app', '/'], 'pastafari2': ['modules.pastafari2', 'pastafari_app', '/'], 'apache': ['modules.apache', 'apache_app', '/'], 'mariadb': ['modules.mariadb', 'mariadb_app', '/'], 'apiv1': ['modules.apiv1', 'apiv1_app', '/'], 'admin': ['paramecio2.modules.admin', 'admin_app', '/']} + + json_text=f.read() + + if json_text!='': + modules_json=json.loads(json_text) + + with open('settings/modules.json', 'w+') as f: + modules_json[real_path]=['modules.'+real_path, real_path+'_app', '/'] + + f.write(json.dumps(modules_json, indent=4)) + + print('Please, reload your wsgi application for access to your new module') + +if __name__=="__main__": + start() diff --git a/pyproject.toml b/pyproject.toml index 63f08a2..1a53626 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "flit_core.buildapi" name = "paramecio2" authors = [{name = "Antonio de la Rosa", email = "antonio.delarosa@salirdelhoyo.com"}] readme = "README.md" -version = "2.0.36.2" +version = "2.0.37" description = "A simple framework using flask and mako" # dynamic = ["version", "description"] @@ -47,6 +47,7 @@ Documentation = "https://docs.cuchulu.com/paramecio2/" paramecio2 = "paramecio2.console:start" paramecio2db = "paramecio2.libraries.db.dbadmin:start" paramecio2cm = "paramecio2.scripts.create_module:start" +paramecio2dm = "paramecio2.scripts.install_module:start" [tool.pytest.ini_options] testpaths = ["tests"]