diff --git a/paramecio/console.py b/paramecio/console.py index 3c7cc4d..54a4033 100644 --- a/paramecio/console.py +++ b/paramecio/console.py @@ -52,7 +52,7 @@ def start(): print('Error: cannot create the directory. Check if exists and if you have permissions') exit() - # Create folder settings and copy index.py, admin.py + # Create folder settings and copy app.py, admin.py path_settings=args.path+'/settings' @@ -74,11 +74,11 @@ def start(): try: - shutil.copy(workdir+'/frontend/index.py', args.path+'/index.py') + shutil.copy(workdir+'/frontend/app.py', args.path+'/app.py') except: - print('Error: cannot copy the file index.py. Check if exists and if you have permissions for this task') + print('Error: cannot copy the file app.py. Check if exists and if you have permissions for this task') try: diff --git a/paramecio/create_module.py b/paramecio/create_module.py index f9c2d59..9e12892 100644 --- a/paramecio/create_module.py +++ b/paramecio/create_module.py @@ -8,6 +8,7 @@ import getpass from pathlib import Path from settings import config from importlib import import_module +import re def start(): """Module for create new modules for paramecio @@ -39,6 +40,8 @@ def start(): #f=open('modules/'+args.path+'/index.py', 'w') + name_module=os.path.basename(args.path) + try: shutil.copy(workdir+'/examples/app.py', 'modules/'+args.path) @@ -46,8 +49,6 @@ def start(): app_file=f.read() - name_module=os.path.basename(args.path) - app_file=app_file.replace('/example', '/'+name_module) with open('modules/'+args.path+'/app.py', 'w') as f: @@ -61,6 +62,42 @@ def start(): print('Error: cannot copy controller example. Check if you have permissions') exit(1) + # Edit config.py + + module_final='modules.'+name_module + + try: + + with open('./settings/config.py') as f: + + #modules_final='\''+'\', \''.join(final_modules)+'\'' + + p=re.compile(r"^modules=\[(.*)\]$") + + #config_file=p.sub(r"modules=[\1, "+modules_final+"]", "modules=['paramecio.modules.welcome', 'paramecio.modules.admin', 'paramecio.modules.lang', 'modules.pastafari', 'modules.monit', 'modules.example']") + + final_config='' + + for line in f: + if p.match(line): + line=p.sub(r"modules=[\1, '"+module_final+"']", line) + final_config+=line + + with open('./settings/config.py', 'w') as f: + + f.write(final_config) + + print('Updated configuration for add new modules...') + + + except: + + print('Cannot update configuration, you need add the new module by hand') + + # Reload config + + config.modules.append(module_final) + # Regenerate modules regenerate_modules_config() diff --git a/paramecio/frontend/index.py b/paramecio/frontend/app.py similarity index 100% rename from paramecio/frontend/index.py rename to paramecio/frontend/app.py