@ -5,30 +5,33 @@ import sys
import json
import json
import importlib
import importlib
import importlib.util
import importlib.util
from git.repo.base import Repo
# from git.repo.base import Repo
import typer
import typer
from typing_extensions import Annotated
from typing_extensions import Annotated
from typing import Optional
from typing import Optional
from typing import Tuple
import meta
import meta
import uuid
import uuid
from termcolor import colored
from termcolor import colored
import base64
import base64
import io
import io
import cms
from cms import index
from cms import index
start = index.start
from cms.engine.config.structure import Layout, System
from cms.engine import project, config, themes, plugins
import pandas as pd
import requests
__doc__ = """
(c) 2022 Quick Content Management System - QCMS
Health Information Privacy Lab - Vanderbilt University Medical Center
MIT License
Is a Python/Flask template for creating websites using disk structure to build the site and loading custom code
start = index.start
The basic template for a flask application will be created in a specified location, within this location will be found a folder "content "
__doc__ = f"""
- within the folder specify the folder structure that constitute the menu
Built and designed by Steve L. Nyemba, steve@the-phi.com
Usage :
version {meta.__version__}
qcms --create <path> --version <value> --title <title> --subtitle <subtitle>
"""
{meta.__license__} """
PASSED = ' '.join(['[',colored(u'\u2713', 'green'),']'])
PASSED = ' '.join(['[',colored(u'\u2713', 'green'),']'])
FAILED= ' '.join(['[',colored(u'\u2717','red'),']'])
FAILED= ' '.join(['[',colored(u'\u2717','red'),']'])
@ -40,94 +43,6 @@ INVALID_FOLDER = """
# handling cli interface
# handling cli interface
cli = typer.Typer()
cli = typer.Typer()
def _get_config (path) :
if os.path.exists(path) :
f = open(path)
_conf = json.loads(f.read())
f.close()
else:
_conf = {}
return _conf
def _isvalid(_allowed,**_args):
if not list(set(_allowed) - set(_args.keys())) :
_pargs = {}
for key in _allowed :
_pargs [key] = _args[key]
return _pargs
return False
def write_config(_config, path):
f = open(path,'w')
f.write( json.dumps(_config)) ;
f.close()
def _system(**_args):
"""
Both version and context must be provided otherwise they are ignored
:version
:context context
"""
_info = _isvalid(['version','context'],**_args)
_info['theme'] = 'default.css'
_info = _info if _info else {'version':'0.0.0','context':'','theme':'default.css'}
if _info :
_info['logo'] = None if 'logo' not in _args else _args['logo']
#
# There is an aggregation entry here in app
_appInfo = {'debug':True,'port':8084,'threaded':True,'host':'0.0.0.0'}
if 'app' not in _args:
_info['app'] = _appInfo
else:
_info['app'] = dict(_appInfo,**_args['app'])
return _info
def _header(**_args):
return _isvalid(['logo','title','subtitle'],**_args)
def _layout(**_args):
_info = _isvalid(['root','index'],**_args)
_info['on'] = {"load":{},"error":{}}
_url = 'qcms.co'
_overwrite = {"folder1":{"type":"redirect","url":_url},"folder2":{"type":"dialog"},"folder3":{"type":"dialog","url":_url}}
_info['icons'] = {"comment":"use folder names as keys and fontawesome type as values to add icons to menu"}
_info["api"] = {"comment":"use keys as uri and function calls as values"}
_info['map'] = {},
_info['order'] = {'menu':[]}
_info['overwrite'] = _overwrite
return _info
def make (**_args):
"""
:context
:port port to be served
:title title of the application
:root folder of the content to be scanned
"""
if 'port' in _args :
_args['app'] = {'port':_args['port']}
del _args['port']
if 'context' not in _args :
_args['context'] = ''
_info ={'system': _system(**_args)}
_hargs = {'title':'QCMS'} if 'title' not in _args else {'title':_args['title']}
_hargs['subtitle'] = '' if 'subtitle' not in _args else _args['subtitle']
_hargs['logo'] = True
_info['layout'] = _layout(root=_args['root'],index='index.html')
_info['layout']['header'] = _header(**_hargs)
#
if 'footer' in _args :
_info['layout']['footer'] = [{'text':_args['footer']}] if type(_args['footer']) != list else [{'text':term} for term in _args['footeer']]
else:
_info['layout']['footer'] = [{'text':'Vanderbilt University Medical Center'}]
return _info
@cli.command(name="info")
@cli.command(name="info")
def _info():
def _info():
@ -135,23 +50,23 @@ def _info():
This function returns metadata information about this program, no parameters are needed
This function returns metadata information about this program, no parameters are needed
"""
"""
print ()
print ()
print (meta.__name__ ,meta.__version__)
print ('QCMS' ,meta.__version__)
print (meta.__author__,meta.__email__)
print (meta.__author__,meta.__email__)
print ()
print ()
@cli.command(name='set-ap p')
@cli.command(name='setu p')
# def set_app (host:str="0.0.0.0",context:str="",port:int=8084,debug=True):
# def set_app (host:str="0.0.0.0",context:str="",port:int=8084,debug=True):
def set_app (host:Annotated[str,typer.Argument(help="bind host IP address")]="0.0.0.0",
def set_app (host:Annotated[str,typer.Argument(help="bind host IP address")]="0.0.0.0",
context:Annotated[str,typer.Argument(help="if behind a proxy server (no forward slash needed)")]="",
context:Annotated[str,typer.Argument(help="if behind a proxy server (no forward slash needed)")]="",
port:Annotated[int,typer.Argument(help="port on which to run the application")]=8084,
port:Annotated[int,typer.Argument(help="port on which to run the application")]=8084,
debug:Annotated[bool,typer.Argument(help="set debug mode on|off")]=True):
debug:Annotated[bool,typer.Argument(help="set debug mode on|off")]=True):
"""
"""
This function consists in editing application access i.e port, debug, and/or context
Setup application access i.e port, debug, and/or context
These parameters are the same used in any flask application
:context alias or path for applications living behind proxy server
"""
"""
global INVALID_FOLDER
global INVALID_FOLDER
_config = _get_ config()
_config = config.get ()
if _config :
if _config :
_app = _config['system']['app']
_app = _config['system']['app']
_app['host'] = host
_app['host'] = host
@ -159,21 +74,18 @@ def set_app (host:Annotated[str,typer.Argument(help="bind host IP address")]="0.
_app['debug'] = debug
_app['debug'] = debug
_config['system']['context'] = context
_config['system']['context'] = context
_config['app'] = _app
_config['app'] = _app
write_ config(_config)
config.write (_config)
_msg = f"""{PASSED} Successful update, good job !
_msg = f"""{PASSED} Successful update, good job !
"""
"""
else:
else:
_msg = INVALID_FOLDER
_msg = INVALID_FOLDER
print (_msg)
print (_msg)
@cli.command(name='set- cloud')
@cli.command(name='cloud')
# def set_cloud(path:str): #url:str,uid:str,token:str):
# def set_cloud(path:str): #url:str,uid:str,token:str):
def set_cloud(path:Annotated[str,typer.Argument(help="path of the auth-file for the cloud")]): #url:str,uid:str,token:str):
def set_cloud(path:Annotated[str,typer.Argument(help="path of the auth-file for the cloud")]): #url:str,uid:str,token:str):
"""
"""
This function overwrites or sets token information for nextcloud. This function will load the content from the cloud instead of locally
Setup qcms to generate a site from files on nextcloud
The path must refrence auth-file (data-transport)
:url url of the nextcloud
:uid account identifier
:token token to be used to signin
"""
"""
if os.path.exists(path):
if os.path.exists(path):
f = open (path)
f = open (path)
@ -182,12 +94,11 @@ def set_cloud(path:Annotated[str,typer.Argument(help="path of the auth-file for
url = _auth['url']
url = _auth['url']
if os.path.exists('qcms-manifest.json') :
if os.path.exists('qcms-manifest.json') :
_config = _get_ config()
_config = config.get ()
_config['system']['source'] = path #{'id':'cloud','auth':{'url':url,'uid':uid,'token':token}}
_config['system']['source'] = path #{'id':'cloud','auth':{'url':url,'uid':uid,'token':token}}
write_ config(_config)
config.write (_config)
title = _config['layout']['header']['title']
title = _config['layout']['header']['title']
_msg = f"""
_msg = f"""{PASSED} Successfully update, good job!
Successfully update, good job!
{url}
{url}
"""
"""
else:
else:
@ -197,13 +108,15 @@ def set_cloud(path:Annotated[str,typer.Argument(help="path of the auth-file for
else:
else:
_msg = INVALID_FOLDER
_msg = INVALID_FOLDER
print (_msg)
print (_msg)
@cli.command(name='set-key ')
@cli.command(name='secure ')
# def set_key(path):
# def set_key(path):
def set_key (
def secure (
manifest:Annotated[str,typer.Argument(help="path of the manifest file")],
manifest:Annotated[str,typer.Argument(help="path of the manifest file")],
keyfile:Annotated[str,typer.Argument(help="path of the key file to generate")]):
keyfile:Annotated[str,typer.Argument(help="path of the key file to generate")]):
"""
"""
create a security key to control the application during developement. The location must have been created prior.
Create a security key and set it in the manifest (and store in on disk).
The secure key allows for administrative control of the application/portal
"""
"""
if not os.path.exists(keyfile):
if not os.path.exists(keyfile):
@ -211,11 +124,11 @@ def set_key(
f.write(str(uuid.uuid4()))
f.write(str(uuid.uuid4()))
f.close()
f.close()
#
#
_config = _get_ config(manifest)
_config = config.get (manifest)
if 'source' not in _config['system']:
if 'source' not in _config['system']:
_config['system']['source'] = {'id':'disk'}
_config['system']['source'] = {'id':'disk'}
_config['system']['source']['key'] = keyfile
_config['system']['source']['key'] = keyfile
write_ config(_config,manifest)
config.write (_config,manifest)
_msg = f"""{PASSED} A key was generated and written to {keyfile}
_msg = f"""{PASSED} A key was generated and written to {keyfile}
use this key in header to enable reload of the site ...`
use this key in header to enable reload of the site ...`
"""
"""
@ -252,103 +165,186 @@ def load(**_args):
return getattr(module,_name) if hasattr(module,_name) else None
return getattr(module,_name) if hasattr(module,_name) else None
@cli.command(name='plugins')
def plug_info (manifest:Annotated[str,typer.Argument(help="path to manifest file")],
show:bool=typer.Option(default=False,help="list plugins loaded"),
add: Annotated[Optional[bool],typer.Option("--register/--unregister",help="add/remove a plugin to manifest use with --pointer option")] = None,
pointer:str=typer.Option(default=None,help="pointer is structured as 'filename.function'")
) :
"""
Manage plugins list loaded plugins,
"""
_config = config.get(manifest)
_root = os.sep.join(manifest.split(os.sep)[:-1] + [_config['layout']['root'],'_plugins'])
if os.path.exists(_root) :
# files = os.listdir(_root)
_msg = f"""{FAILED} no operation was specified, please use --help option"""
# if 'plugins' in _config :
_plugins = _config['plugins'] if 'plugins' in _config else {}
if show :
if not _plugins :
_msg = f"""{FAILED} no plugins are loaded\n\t{manifest}"""
else:
_data = plugins.stats(_plugins)
print (_data)
_msg = f"""{PASSED} found a total of {_data.loaded.sum()} plugins loaded from {_data.shape[0]} file(s)\n\t{_root}"""
if add in [True,False] and pointer :
file,fnName = pointer.split('.')
_fnpointer = plugins.load(_root,file+'.py',fnName)
if _fnpointer and add:
if file not in _plugins :
_plugins[file] = []
if fnName not in _plugins[file] :
_plugins[file].append(fnName)
_msg = f"""{PASSED} registered {pointer}, use the --show option to list loaded plugins\n{manifest} """
else:
_msg = f"""{FAILED} could not register {pointer}, it already exists\n\t{manifest} """
elif add is False and file in _plugins:
_plugins[file] = [_name.strip() for _name in _plugins[file] if _name.strip() != fnName.strip() ]
_msg = f"""{PASSED} unregistered {pointer}, use the --show option to list loaded plugins\n{manifest} """
#
# We need to write this down !!
if add in [True,False] :
_config['plugins'] = _plugins
config.write(_config,manifest)
# else:
# _msg = f"""{FAILED} no plugins are loaded\n\t{manifest}"""
print()
print(_msg)
else:
_msg = f"""{FAILED} no plugin folder found """
pass
@cli.command (name='create')
@cli.command (name='create')
# def create(folder:str,root:str,index:str='index.html',title:str='qcms',subtitle:str='',footer:str='Quick Content Management System',version:str='0.1'):
def create(folder:Annotated[str,typer.Argument(help="path of the project folder")],
def create(folder:Annotated[str,typer.Argument(help="path of the project folder")],
root:Annotated[str,typer.Argument(help="folder of the content (inside the project folder)")],
# root:Annotated[str,typer.Argument(help="folder of the content (inside the project folder)")],
index:str=typer.Option(default="index.html",help="index file (markup or html)"), #Annotated[str,typer.Argument(help="index file to load (.html or markup)")]='index.html',
index:str=typer.Option(default="index.html",help="index file (markup or html)"), #Annotated[str,typer.Argument(help="index file to load (.html or markup)")]='index.html',
title:str=typer.Option(default="QCMS PROJECT", help="name of the project") , #Annotated[str,typer.Argument(help="title of the project")]='QCMS - TITLE',
title:str=typer.Option(default="QCMS PROJECT", help="name of the project") , #Annotated[str,typer.Argument(help="title of the project")]='QCMS - TITLE',
subtitle:str=typer.Option(default="designed & built by The Phi Technology",help="tag line about the project (sub-title)"), #Annotated[str,typer.Argument(help="subtitle of the project")]='qcms - subtitle',
subtitle:str=typer.Option(default="designed & built by The Phi Technology",help="tag line about the project (sub-title)"), #Annotated[str,typer.Argument(help="subtitle of the project")]='qcms - subtitle',
footer:str=typer.Option(default="Quick Content Management System",help="text to be placed as footer"), #Annotated[str,typer.Argument(help="text on the footer of the main page")]='Quick Content Management System',
footer:str=typer.Option(default="Powered By QCMS",help="text to be placed as footer"), #Annotated[str,typer.Argument(help="text on the footer of the main page")]='Quick Content Management System',
version:str=typer.Option(default="0.2",help="version number") #Annotated[str,typer.Argument(help="version of the site")]='0.1'
port:int=typer.Option(default=8084, help="port to be used for the app"),
context:str=typer.Option(default="", help="application context if using a proxy server"),
version:str=typer.Option(default=meta.__version__,help="version number") #Annotated[str,typer.Argument(help="version of the site")]='0.1'
):
):
"""
"""
This function will create a project folder by performing a git clone (pull the template project)
C reate a project folder by performing a git clone (pull the template project)
and adding a configuration file to that will bootup the project
and adding a configuration file to that will bootup the project
folder project folder
root name/location of root folder associated with the web application
@TODO:
- add port,
"""
"""
#global SYS_ARGS
#folder = SYS_ARGS['create']
url = "https://dev.the-phi.com/git/cloud/cms.git"
#if 'url' in SYS_ARGS :
# url = SYS_ARGS['url']
print ("\tcreating project into folder " +folder)
#
#
# if standalone, then we should create the git repository
# Build the configuration for the project
# if standalone :
if not os.path.exists(folder) :
# _repo = Repo.clone_from(url,folder)
root = 'www/html'
# #
_system = System()
# # removing remote folder associated with the project
_layout = Layout()
# _repo.delete_remote(remote='origin')
_layout = _layout.build(root=root, footer = [{"text":term} for term in footer.split(',')],header={'title':title,'subtitle':subtitle} )
# else:
# os.makedirs(folder)
_system = System()
_system = _system.build(version=version,port=port, context=context)
_config = dict(_system,**_layout)
print (f"{PASSED} Built Configuration Object")
#
#
# @TODO: root should be handled in
# Setup Project on disk
rootpath = os.sep.join([folder,root])
_img = None
if not os.path.exists(rootpath) :
print (f"{PASSED} Creating content folder "+rootpath)
os.makedirs(rootpath)
os.makedirs(os.sep.join([rootpath,'_images']))
_img = """data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAANpElEQVR4Xu2dB9AlRRHHwZxzjt+Zc0KhzIeKEXMqA/CZoBTFrBjQExVUTJhKVPQUscyomBU9M+acMB0mTKhlzvj/Vb0t11e7b2fmzU7uqq7b+96k7fnvhJ6e7l13aVS1BHat+u3by+/SAFA5CBoAGgAql0Dlr99GgAaAyiVQ+eu3EaABoHIJVP76tY0A11R/P1J8I/FFxD8Tv098pPhHNWKhJgA8VB38AvEZBjr6z/rbPuLjagNBTgDg6z1J/FeHTrqD8rxDvOp9/6nfry/+okP52WbJBQBnk4S/L/63eJt4++LZRPCnV6Ifii9lkHiH0uxpkK6YJLkA4ImS+DN7Uv+WnvnbOw164sZK83GDdF2Si+nhFIv0WSfNAQDnl4R/ID73gKQ/rb89XvzJFb3wAP32Kote2qq0H7NIn3XSHADwPEn4URNSPn4xInxjIB2Lu9dZ9NINlPYzFumzTpo6AC4t6X5HfBYDKbM+OEb8VPGP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Ef0QvFAgBaOPbkIervK4J2V514DN0YkB7X0wgDBwgIPMUcOxU7yEcn9BVBW1XgseKh6+iEqCGimjcdAI0P0QHLQkLRQpy+ULbwy6pgvjAUL50qmK+JABLcPcT7CCMF2rZ+4GgfHT1WRh8ApOG8gviFqIKZ608R87G8Xuzd06lPALCdY3+KMIcIte/+Yhwtjd2x+7Z+45yAl8ZjGKtxOopnV+oAwK0gOpfwMkPEopSAUawBxsDJ6MA5AecHjA5EKqF96yxklwHg+p5O+XwCoLsZxFDKRUq2eNzrA8X42eG4dWOklTv0d6J+fX7gd1yzcXhziNgmKFRX1LJJ2In6gXh/DKW0D69fjEoM/9xUHiLCxBGUgs5fJoC9KUZt7HLKWRwARmQ4+ucj9MvB4qlr1XQOo4vtUe26NoHcWj5APDX8csrIqaJt4MqqAXC0BGYaqRME4YWLL9hmyF0HAO9RXZwQmnomYwRgFCN6iSlVCwDmeeZkdO82xFk5fgVNyRUAtIv20U4bIhglFlGmVC0AGPZtI30iVOZcOoUDGxNyBQAgO8ikgoE0NhrEagGAihUHTC7Eke0+hhldAcDq3tX4And2ANyEqgQAcyrbKNO5dVmQY95EhgTuCgC2jfgIdCHsCbYbZqwSAGy/TPTyYzI8UD9gw2dCrgBgy4mNoAvhK5CtsAlVCYDTJBmUO65+dQ9VXvQCJuQKABaArhHC2Tbi1NKEqgQAgiEuwAkmEhpIg1kUc7QJuQJgXxV+jEkFA2kwfd80zFstABAuQrYl9tgYa5j6F3YFAOAEpLaE11NUxaZTXLUAwOBiDzFqVhtCM2cDHFcA0Ka9xSiDbMhmB0C5xQDARkgtbSIS8HkYlMgrtWbYSKABwEZaBaZtACiwU21eqQHARloFpm0AKLBTbV6pAcBGWgWmbQAosFNtXqkBwEZaBab9L2FjSp+s5clTAAAAAElFTkSuQmCC"""
_,_img = _img.split(',',1)
logo = os.sep.join([rootpath,'_images','logo.png'])
f = open(logo,'wb')
f.write(base64.b64decode(_img))
f.close()
_html = __doc__.replace("<","<").replace(">",">").replace("Usage","<br>Usage")
if not os.path.exists(os.sep.join([rootpath,'index.html'])) :
f = open(os.sep.join([rootpath,'index.html']),'w')
f.write(_html)
f.close()
print (f'{PASSED} configuration being written to project folder')
_args = {'title':title,'subtitle':subtitle,'version':version,'root':root,'index':index}
if footer :
_args['footer'] = footer
_config = make(**_args)
#
#
# updating logo reference (default for now)
project.make(folder=folder,config=_config)
_config['system']['logo'] = os.sep.join([_config['layout']['root'],'_images/logo.png'])
print (f"""{PASSED} created project at {folder} """)
else:
print ()
print (f"""{FAILED} Could not create project {folder}
The folder is not empty
""")
f = open(os.sep.join([folder,'qcms-manifest.json']),'w')
f.write(json.dumps(_config))
f.close()
return _config
@cli.command (name='reload')
@cli.command (name='reload')
def reload (path) :
def reload (
if os.path.exists (path):
path:Annotated[str,typer.Argument(help="")],
pass
port:int=typer.Option(default=None,help="port of the host to call")
) :
"""
Reload a site/portal given the manifest ...
"""
_config = config.get(path)
if 'key' in _config['system']['source'] :
f = open(_config['system']['source']['key'])
key = f.read()
f.close()
_port = port if port else _config['system']['app']['port']
url = f"http://localhost:{_port}/reload"
resp = requests.post(url, headers={"key":key})
if resp.status_code == 200 :
_msg = f"""{PASSED} successfully reloaded {url}"""
else:
_msg = f"""{FAILED} failed to reload, status code {resp.status_code}\n{url}
"""
else:
_msg = f"""{FAILED} no secure key found in manifest"""
print (_msg)
@cli.command(name="bootup")
@cli.command(name="bootup")
def bootup (
def bootup (
path:Annotated[str,typer.Argument(help="path of the manifest file")]='qcms-manifest.json',
manifest :Annotated[str,typer.Argument(help="path of the manifest file")]='qcms-manifest.json',
port:int=typer.Option(default=None, help="port number to serve on (will override configuration)")
port:int=typer.Option(default=None, help="port number to serve on (will override configuration)")
):
):
"""
"""
This function will launch a site/project given the location of the manifest file
This function will launch a site/project given the location of the manifest file
"""
"""
index.start(path,port)
index.start(manifest,port)
# if not port :
@cli.command(name='theme')
# index.start(path)
def handle_theme (
# else:
manifest:Annotated[str,typer.Argument(help="path of the manifest file")],
# index.start(path,port)
show:bool = typer.Option(default=False,help="print list of themes available"),
name:str = typer.Option(default='default',help='name of the theme to apply')
) :
"""
This function will show the list available themes and can also set a theme in a manifest
def reset():
"""
"""
_config = config.get(manifest)
_root = os.sep.join( manifest.split(os.sep)[:-1]+[_config['layout']['root']])
if show :
_df = pd.DataFrame({"available":themes.List()})
if _df.shape[0] > 0 :
values = themes.installed(_root)
values = values + np.repeat(f"""{FAILED}""", _df.shape[0] - len(values)).tolist()
_df['installed'] = values
else:
_df = f"""{FAILED} No themes were found in registry,\ncurl {themes.URL}/api/themes/List (QCMS_HOST_URL should be set)"""
print (_df)
if name :
# we need to install the theme, i.e download it and update the configuration
#
try:
_object = themes.Get(name)
path = os.sep.join([_root,'_assets','themes',name])
if not os.path.exists(path) :
os.makedirs(path)
_object = _object[name] #-- formatting (...)
for _filename in _object :
css = _object[_filename]
f = open(os.sep.join([path,_filename+'.css']),'w')
f.write(css)
f.close()
#
# Let us update the configuration file ...
#
_config['system']['theme'] = name
config.write(_config,manifest)
_msg = f"""{PASSED} successfully downloaded {name} \n{PASSED} updated manifest {manifest}
"""
"""
except Exception as e:
_msg = f"""{FAILED} operation failed "{str(e)}"
"""
pass
print (_msg)
global SYS_ARGS
global SYS_ARGS
if __name__ == '__main__':
if __name__ == '__main__':
cli()
cli()