diff --git a/cms/__init__.py b/cms/__init__.py index 32b6458..ba9b00c 100644 --- a/cms/__init__.py +++ b/cms/__init__.py @@ -79,8 +79,7 @@ class components : """ if 'source' in _system and _system['source']['id'] == 'cloud': - - _html = cloud.html(uri,_args) + _html = cloud.html(uri,dict(_args,**{'system':_system})) else: _html = disk.html(uri) @@ -105,7 +104,7 @@ class components : _store = _args['store'] reader = transport.factory.instance(**_store) _queries= copy.deepcopy(_store['query']) - _data = reader.read(**_query) + _data = reader.read(**_queries) return _data @staticmethod def csv(uri) : @@ -130,6 +129,7 @@ class components : return None #-- We have a file ... _name = _args['name'] + spec = importlib.util.spec_from_file_location(_name, _path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) @@ -142,29 +142,32 @@ class components : """ PATH= os.sep.join([_config['layout']['root'],'_plugins']) _map = {} - if not os.path.exists(PATH) : - return _map + # if not os.path.exists(PATH) : + # return _map if 'plugins' not in _config : _config['plugins'] = {} - _conf = _config['plugins'] + _conf = _config['plugins'] for _key in _conf : _path = os.sep.join([PATH,_key+".py"]) - + if not os.sep.path.exists(_path): + continue for _name in _conf[_key] : _pointer = components.load_plugin(path=_path,name=_name) if _pointer : _uri = "/".join(["api",_key,_name]) _map[_uri] = _pointer # - # Let us load the default plugins - + # We are adding some source specific plugins to the user-defined plugins + # This is intended to have out-of the box plugins... + # if 'source' in _config['system'] and _config['system']['source']['id'] == 'cloud' : _plugins = cloud.plugins() else: _plugins = disk.plugins() # # If there are any plugins found, we should load them and use them + if _plugins : _map = dict(_map,**_plugins) return _map @@ -182,3 +185,12 @@ class components : env = Environment(loader=BaseLoader()) # env.globals['routes'] = _config['plugins'] return env + @staticmethod + def get_system(_config,skip_keys=[]): + _system = copy.deepcopy(_config['system']) + if skip_keys : + for key in skip_keys : + if key in _system : + del _system + return _system + diff --git a/cms/cloud.py b/cms/cloud.py index a2e0ecf..d13113a 100644 --- a/cms/cloud.py +++ b/cms/cloud.py @@ -6,8 +6,15 @@ import nextcloud_client as nc import copy from mistune import markdown +import time _CLOUDHANDLER = None +def login(**_args): + nx = nc.Client(_args['url']) + nx.login(_args['uid'],_args['token']) + time.sleep(1) + return nx + def _format_root_folder (_root): if _root[0] == '/' : _root = _root[1:] @@ -21,22 +28,23 @@ def content(_args): :token :folder """ - global _CLOUDHANDLER - _handler = nc.Client(_args['url']) - _handler.login(_args['uid'],_args['token']) - _CLOUDHANDLER = _handler - _files = _handler.list(_args['folder'],10) + # global _CLOUDHANDLER + # if not _CLOUDHANDLER : + # _handler = nc.Client(_args['url']) + # _handler.login(_args['uid'],_args['token']) + # _CLOUDHANDLER = _handler + _handler = login(**_args) _root = _args['folder'] if _root.startswith('/') : _root = _root[1:] if _root.endswith('/') : _root = _root[:-1] + _files = _handler.list(_root,30) _menu = {} #[_args['folder']] + [_item for _item in _files if _item.file_type == 'dir' and _item.name[0] not in ['.','_']] _menu = {} #dict.fromkeys(_menu,[]) for _item in _files : _folder = _item.path.split(_item.name)[0].strip() _folder = _folder.replace(_root,'').replace('/','') - if _item.name[0] in ['.','_'] or _folder == '': continue ; @@ -60,6 +68,7 @@ def content(_args): # clean up the content ... _keys = [_name for _name in _menu.keys() if _name.startswith('_')] [_menu.pop(_name) for _name in _keys] + _handler.logout() return _menu @@ -72,10 +81,12 @@ def build(_config): _args = copy.deepcopy(_config['system']['source']['auth']) _args['folder'] = _config['layout']['root'] # update(_config) - return content(_args) + _menu = content(_args) + return _menu def html (uri,_config) : - global _CLOUDHANDLER - _handler = _CLOUDHANDLER + # global _CLOUDHANDLER + # _handler = _CLOUDHANDLER + _handler = login(**_config['system']['source']['auth']) _root = _format_root_folder(_config['layout']['root']) uri = _format_root_folder (uri) @@ -85,7 +96,10 @@ def html (uri,_config) : # _link = '/'.join(['api/cloud/download?doc='+_prefix,'_images']) _html = _handler.get_file_contents(uri).decode('utf-8').replace('.attachments.',_link) # print ([uri,uri[-2:] ,uri[-2:] in ['md','MD','markdown']]) - return markdown(_html) if uri[-2:] in ['md','MD','Md','mD'] else _html.replace(_root,('{{context}}api/cloud/download?doc='+_root)) + _handler.logout() + # if uri.endswith('.md'): + # _html = _html.replace(_root,('{{context}}api/cloud/download?doc='+_root)) + return markdown(_html) if uri[-2:] in ['md','MD','Md','mD'] else _html # def update (_config): # """ # This function updates the configuration provided by loading default plugins @@ -95,13 +109,14 @@ def html (uri,_config) : # _config['plugins'] = plugins () # return _config def download(**_args): - _handler = _CLOUDHANDLER + _auth = _args['config']['system']['source']['auth'] + _handler = login(**_auth) if _args['doc'][-2:] in ['md','ht']: _stream = html(_args['doc'],_args['config']) else: _stream = _handler.get_file_contents(_args['doc']) - + _handler.logout() return _stream pass diff --git a/index.py b/index.py index 96d3083..2c08ea8 100644 --- a/index.py +++ b/index.py @@ -31,7 +31,7 @@ def _index (): _args = {} if 'plugins' in _config : _args['routes']=['plugins'] - _system = copy.deepcopy(_config['system']) + _system = cms.components.get_system(_config) #copy.deepcopy(_config['system']) try: _args['layout'] = _config['layout'] @@ -157,14 +157,13 @@ def cms_page(): _args = {'layout':_config['layout']} if 'plugins' in _config: _args['routes'] = _config['plugins'] - _system = copy.deepcopy(_config['system']) + _system = cms.components.get_system(_config) _html = cms.components.html(_uri,_id,_args,_system) e = Environment(loader=BaseLoader()).from_string(_html) # _data = {} #cms.components.data(_config) - if 'source' in _system : - del _system['source'] + _system = cms.components.get_system(_config) _args['system'] = _system _html = e.render(**_args) @@ -175,13 +174,16 @@ def _cms_page (): _uri = request.args['uri'] _uri = os.sep.join([_config['layout']['root'],_uri]) _title = request.args['title'] if 'title' in request.args else '' - _args = {'system':_config['system']} + _args = {'system':cms.components.get_system(_config) } if 'plugins' in _config: _args['routes'] = _config['plugins'] _html = cms.components.html(_uri,_title,_args) e = Environment(loader=BaseLoader()).from_string(_html) return e.render(**_args),200 +@_app.route('/reload',methods=['POST']) +def reload(): + pass # # Let us bootup the application SYS_ARGS = {} @@ -217,12 +219,14 @@ if __name__ == '__main__' : # _root = _config['layout']['root'] - _menu = cms.components.menu(_config) + _menu = cms.components.menu(_config) if 'order' in _config['layout'] and 'menu' in _config['layout']['order']: _sortedmenu = {} for _name in _config['layout']['order']['menu'] : - _sortedmenu[_name] = _menu[_name] - _menu = _sortedmenu + if _name in _menu : + _sortedmenu[_name] = _menu[_name] + + _menu = _sortedmenu if _sortedmenu else _menu _config['layout']['menu'] = _menu #cms.components.menu(_config) # if 'data' in _config : # _config['data'] = cms.components.data(_config['data']) diff --git a/templates/pane.html b/templates/pane.html index 37357a1..dd85b40 100644 --- a/templates/pane.html +++ b/templates/pane.html @@ -3,4 +3,4 @@ Hard code whatever you want here @TODO: Perhaps have code to add things here onload --> - +