def load_module_from_path(i):
    """
    Input:  {
              path             - module path
              module_code_name - module name
              (cfg)            - configuration of the module if exists ...
              (skip_init)      - if 'yes', skip init
              (data_uoa)       - module UOA (useful when printing error)
            }

    Output: {
              return       - return code =  0, if successful
                                         >  0, if error
              (error)      - error text if return > 0

              code         - python code object
              path         - full path to the module
              cuid         - internal UID of the module
            }
    """

    p=i['path']
    n=i['module_code_name']

    xcfg=i.get('cfg',None)

    # Find module
    try:
       x=imp.find_module(n, [p])
    except ImportError as e: # pragma: no cover
       return {'return':1, 'error':'can\'t find module code (path='+p+', name='+n+', err='+format(e)+')'}

    ff=x[0]
    full_path=x[1]

    # Check if code has been already loaded
    if full_path in work['cached_module_by_path'] and work['cached_module_by_path_last_modification'][full_path]==os.path.getmtime(full_path):
       ff.close()
       # Code already loaded 
       return work['cached_module_by_path'][full_path]

    # Check if has dependency on specific CK kernel version
    if xcfg!=None:
       kd=xcfg.get('min_kernel_dep','')
       if kd!='':
          rx=check_version({'version':kd})
          if rx['return']>0: return rx

          ok=rx['ok']
          version_str=rx['current_version']

          if ok!='yes':
             return {'return':1, 'error':'module "'+i.get('data_uoa','')+'" requires minimal CK kernel version '+kd+' while your version is '+version_str} 

    # Generate uid for the run-time extension of the loaded module 
    # otherwise modules with the same extension (key.py for example) 
    # will be reloaded ...

    r=gen_uid({})
    if r['return']>0: return r
    ruid='rt-'+r['data_uid']

    try:
       c=imp.load_module(ruid, ff, full_path, x[2])
    except ImportError as e: # pragma: no cover
       return {'return':1, 'error':'can\'t load module code (path='+p+', name='+n+', err='+format(e)+')'}

    x[0].close()

    # Initialize module with this CK instance 
    c.ck=sys.modules[__name__]
    if xcfg!=None: c.cfg=xcfg

    # Initialize module
    if i.get('skip_init','')!='yes':
       # Check if init function exists
       if getattr(c, 'init')!=None:
          r=c.init(i)
          if r['return']>0: return r

    r={'return':0, 'code':c, 'path':full_path, 'cuid':ruid}

    # Cache code together with its time of change
    work['cached_module_by_path'][full_path]=r
    work['cached_module_by_path_last_modification'][full_path]=os.path.getmtime(full_path)

    return r
def load_module_from_path ( i ) : p = i [ 'path' ] n = i [ 'module_code_name' ] xcfg = i . get ( 'cfg' , None ) try : x = imp . find_module ( n , [ p ] ) except ImportError as e : return { 'return' : 1 , 'error' : 'can\'t find module code (path=' + p + ', name=' + n + ', err=' + format ( e ) + ')' } ff = x [ 0 ] full_path = x [ 1 ] if full_path in work [ 'cached_module_by_path' ] and work [ 'cached_module_by_path_last_modification' ] [ full_path ] == os . path . getmtime ( full_path ) : ff . close ( ) return work [ 'cached_module_by_path' ] [ full_path ] if xcfg != None : kd = xcfg . get ( 'min_kernel_dep' , '' ) if kd != '' : rx = check_version ( { 'version' : kd } ) if rx [ 'return' ] > 0 : return rx ok = rx [ 'ok' ] version_str = rx [ 'current_version' ] if ok != 'yes' : return { 'return' : 1 , 'error' : 'module "' + i . get ( 'data_uoa' , '' ) + '" requires minimal CK kernel version ' + kd + ' while your version is ' + version_str } r = gen_uid ( { } ) if r [ 'return' ] > 0 : return r ruid = 'rt-' + r [ 'data_uid' ] try : c = imp . load_module ( ruid , ff , full_path , x [ 2 ] ) except ImportError as e : return { 'return' : 1 , 'error' : 'can\'t load module code (path=' + p + ', name=' + n + ', err=' + format ( e ) + ')' } x [ 0 ] . close ( ) c . ck = sys . modules [ __name__ ] if xcfg != None : c . cfg = xcfg if i . get ( 'skip_init' , '' ) != 'yes' : if getattr ( c , 'init' ) != None : r = c . init ( i ) if r [ 'return' ] > 0 : return r r = { 'return' : 0 , 'code' : c , 'path' : full_path , 'cuid' : ruid } work [ 'cached_module_by_path' ] [ full_path ] = r work [ 'cached_module_by_path_last_modification' ] [ full_path ] = os . path . getmtime ( full_path ) return r
Input:  {
              path             - module path
              module_code_name - module name
              (cfg)            - configuration of the module if exists ...
              (skip_init)      - if 'yes', skip init
              (data_uoa)       - module UOA (useful when printing error)
            }

    Output: {
              return       - return code =  0, if successful
                                         >  0, if error
              (error)      - error text if return > 0

              code         - python code object
              path         - full path to the module
              cuid         - internal UID of the module
            }