from genericpath import isdir
import os
import pandas as pd
import transport
import copy
from jinja2 import Environment, BaseLoader, FileSystemLoader
import importlib
import importlib.util



# 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
 