Example #1
0
def init(dllpath=None, root="C:\\", bypass_check=False):
    """ Initialize the underlying tos-databridge DLL

  dllpath: string of the exact path of the DLL
  root: string of the directory to start walking/searching to find the DLL
  """
    global _dll
    rel = set()
    if not bypass_check and dllpath is None and root == "C:\\":
        if abort_init_after_warn():
            return False

    def _remove_older_versions():
        nonlocal rel
        getver = lambda x: _search(_REGEX_VER_SFFX, x).group().strip('-')
        vers = tuple(zip(map(getver, rel), rel))
        vers_max = max(vers)[0].split('.')[0]
        mtup = tuple(( x[0].split('.')[1],x[1]) \
                       for x in vers if x[0].split('.')[0] == vers_max )
        mtup_max = max(mtup)[0]
        rel = set(x[1] for x in mtup if x[0] == mtup_max)

    try:
        if dllpath is None:
            matcher = _partial(_match, _REGEX_DLL_NAME)  # regex match function
            for nfile in map(matcher, _listdir(_curdir)):
                if nfile:  # try the current dir first
                    rel.add(_curdir + _sep + nfile.string)
            if not rel:  # no luck, walk the dir tree
                for root, dirs, files in _walk(root):
                    for file in map(matcher, files):
                        if file:
                            rel.add(root + _sep + file.string)
                if not rel:  # if still nothing throw
                    raise TOSDB_InitError(" could not locate DLL")
            if len(rel) > 1:  # only use the most recent version(s)
                _remove_older_versions()
            # most recently updated
            d = dict(zip(map(lambda x: _stat(x).st_mtime, rel), rel))
            rec = max(d)
            dllpath = d[rec]
        _dll = _WinDLL(dllpath)
        print("+ Using Module ", dllpath)
        print("+ Last Update ", _asctime(_localtime(_stat(dllpath).st_mtime)))
        if connect():
            print("+ Succesfully Connected to Service \ Engine")
        else:
            print("- Failed to Connect to Service \ Engine")
        return True  # indicate the lib was loaded (but not if connect succeeded)
    except TOSDB_Error:
        raise
    except Exception as e:
        raise TOSDB_InitError("unable to initialize library", e)
Example #2
0
    def _check_channel_data(cls, channels):

        for ch in channels:
            if ch.model == 'pointwise':
                if not _exists(ch.filep):
                    raise FileNotFoundError(
                        f'The file {ch.filep} does not exist.')
                if _stat(ch.filep).st_size == 0:
                    raise OSError(f'The file {ch.filep} is empty.')

                pot_data = np.loadtxt(ch.filep, skiprows=1)

                msg_init = 'The pointwise potential file'
                if pot_data.shape[0] < 5:
                    _warning(
                        f'{msg_init} {ch.filep} has less than 5 parameters')
                if pot_data.shape[0] < 2:
                    _error(f'{msg_init} {ch.filep} has less than 2 parameters')
                if pot_data.shape[1] == 2:
                    _warning(f'{msg_init} {ch.filep} has 2 columns')
                if pot_data.shape[1] < 2:
                    _error(f'{msg_init} {ch.filep} has less than 2 columns')

            if ch.model == 'custom':
                if not hasattr(ch, '__call__'):
                    _error('Model is set to custum but ' +
                           'custom function is not provided')
Example #3
0
def init(dllpath = None, root = "C:\\", bypass_check=False):
    """ Initialize the underlying tos-databridge DLL

    dllpath: string of the exact path of the DLL
    root: string of the directory to start walking/searching to find the DLL
    """  
    global _dll
    rel = set()
    if not bypass_check and dllpath is None and root == "C:\\":
        if abort_init_after_warn():
            return
    try:
        if dllpath is None:
            matcher = _partial( _match, _REGEX_DLL_NAME)  # regex match function
            for nfile in map( matcher, _listdir( _curdir )):
                if nfile: # try the current dir first             
                    rel.add( _curdir+ _sep + nfile.string )                    
            if not rel:                
                for root,dirs, files in _walk(root): # no luck, walk the dir tree 
                    for file in map( matcher, files):  
                        if file:                           
                            rel.add( root + _sep + file.string )                           
                if not rel: # if still nothing throw
                    raise TOSDB_Error(" could not locate DLL")    
            if len(rel) > 1:  # only use the most recent version(s)
                ver = _compile('-[\d]{1,2}.[\d]{1,2}-')
                vers = tuple( zip( map( 
                    lambda x: _search(ver,x).group().strip('-'), rel), rel) )
                vers_max = max(vers)[0].split('.')[0]
                mtup = tuple( (x[0].split('.')[1],x[1]) 
                              for x in vers if x[0].split('.')[0] == vers_max)         
                mtup_max = max(mtup)[0]
                rel = set( x[1] for x in mtup if x[0] == mtup_max )                      
            # find the most recently updated
            d = dict( zip(map( lambda x : _stat(x).st_mtime, rel), rel ) )
            rec = max(d)
            dllpath = d[ rec ]
        _dll = _WinDLL( dllpath )
        print( "+ Using Module ", dllpath )
        print( "+ Last Update ", _asctime(_localtime(_stat(dllpath).st_mtime)))
        if connect():
            print("+ Succesfully Connected to Service \ Engine")       
        else:
            print("- Failed to Connect to Service \ Engine")
        return True # indicate the lib was loaded
    except Exception as e:
        raise TOSDB_CLibError( "unable to initialize library", e )        
Example #4
0
def Check(FilePath):
    """Check(FilPath)
    Check the permission of file and return value
    """
    if (_isfile(FilePath) or _isdir(FilePath)):
        chmodValue = ((oct(_stat(FilePath).st_mode & 0O777))[-3:])
        return (int(chmodValue))
    else:
        chmodValue = "File Not Found"
        return (chmodValue)
Example #5
0
def stat(file_path):
    stat_result = _stat(encode_path(file_path))
    mtime = int(stat_result.st_mtime)
    size = stat_result.st_size
    return mtime, size
Example #6
0
def init(dllpath=None, root="C:\\", bypass_check=False):
    """ Initialize the underlying tos-databridge DLL

    dllpath: string of the exact path of the DLL
    root: string of the directory to start walking/searching to find the DLL
    """  
    global _dll, _dll_depend1
    rel = set()
    if not bypass_check and dllpath is None and root == "C:\\":
        if abort_init_after_warn():
            return False

    def _remove_older_versions():
        nonlocal rel  
        getver = lambda x: _search(_REGEX_VER_SFFX,x).group().strip('-')
        vers = tuple(zip(map(getver, rel), rel))
        vers_max = max(vers)[0].split('.')[0]
        mtup = tuple(( x[0].split('.')[1],x[1]) \
                       for x in vers if x[0].split('.')[0] == vers_max )         
        mtup_max = max(mtup)[0]
        rel = set(x[1] for x in mtup if x[0] == mtup_max)

    def _get_depends1_dll_path(dllpath):
        d = _path.dirname(dllpath)
        return d + "/" + DLL_DEPENDS1_NAME + "-" + SYS_ARCH_TYPE + ".dll"
    
    try:   
        if dllpath is None:
            matcher = _partial(_match, _REGEX_DLL_NAME)  
            for nfile in map(matcher, _listdir(_curdir)):
                if nfile: # try the current dir first             
                    rel.add(_curdir+ _sep + nfile.string)                    
            if not rel: # no luck, walk the dir tree              
                for root, dirs, files in _walk(root):  
                    for file in map(matcher, files):  
                        if file:                           
                            rel.add(root + _sep + file.string)                           
                if not rel: # if still nothing throw
                    raise TOSDB_InitError(" could not locate DLL")          
            if len(rel) > 1:  # only use the most recent version(s)
                _remove_older_versions()              
            # most recently updated
            d = dict(zip(map(lambda x: _stat(x).st_mtime, rel), rel)) 
            rec = max(d)
            dllpath = d[rec]

        dllpath_depends1 = _get_depends1_dll_path(dllpath)
        _dll_depend1 = _CDLL(dllpath_depends1)
        _dll = _CDLL(dllpath)
        
        print("+ Using Module(s) ", dllpath)
        print("                  ", dllpath_depends1)
        print("+ Last Update ", _asctime(_localtime(_stat(dllpath).st_mtime)))
        if connect():
            print("+ Succesfully Connected to Service \ Engine")       
        else:
            print("- Failed to Connect to Service \ Engine")
        return True # indicate the lib was loaded (but not if connect succeeded)
    except TOSDB_Error:
        raise
    except Exception as e:
        raise TOSDB_InitError("unable to initialize library", e)        
Example #7
0
def init(dllpath=None, root="C:\\", bypass_check=False):
    """ Initialize the underlying tos-databridge DLL and try to connect.

    Returns True if library was successfully loaded, not necessarily that
    it was also able to connect. Details are sent to stdout.
    
    init(dllpath=None, root="C:\\", bypass_check=False)
    
    dllpath      :: str  :: exact path of the DLL -or-
    root         :: str  :: directory to start walking/searching to find the DLL
    bypass_check :: bool :: used by virtual layer implemenation (DO NOT SET)

    returns -> bool 

    throws TOSDB_InitError TOSDB_Error
    """
    global _dll, _dll_depend1
    rel = set()
    if not bypass_check and dllpath is None and root == "C:\\":
        if abort_init_after_warn():
            return False

    def _remove_older_versions():
        nonlocal rel
        getver = lambda x: _search(_REGEX_VER_SFFX, x).group().strip('-')
        vers = tuple(zip(map(getver, rel), rel))
        vers_max = max(vers)[0].split('.')[0]
        mtup = tuple(( x[0].split('.')[1],x[1]) \
                       for x in vers if x[0].split('.')[0] == vers_max )
        mtup_max = max(mtup)[0]
        rel = set(x[1] for x in mtup if x[0] == mtup_max)

    def _get_depends1_dll_path(dllpath):
        d = _path.dirname(dllpath)
        dbg = _match(_REGEX_DBG_DLL_PATH, dllpath)
        base = d + "/" + DLL_DEPENDS1_NAME + "-" + SYS_ARCH_TYPE
        path = base + ("_d.dll" if dbg else ".dll")
        return path

    try:
        if dllpath is None:
            matcher = _partial(_match, _REGEX_DLL_NAME)
            for nfile in map(matcher, _listdir(_curdir)):
                if nfile:  # try the current dir first
                    rel.add(_curdir + _sep + nfile.string)
            if not rel:  # no luck, walk the dir tree
                for root, dirs, files in _walk(root):
                    for file in map(matcher, files):
                        if file:
                            rel.add(root + _sep + file.string)
                if not rel:  # if still nothing throw
                    raise TOSDB_InitError(" could not locate DLL")
            if len(rel) > 1:  # only use the most recent version(s)
                _remove_older_versions()
            # most recently updated
            d = dict(zip(map(lambda x: _stat(x).st_mtime, rel), rel))
            rec = max(d)
            dllpath = d[rec]

        dllpath_depends1 = _get_depends1_dll_path(dllpath)
        _dll_depend1 = _CDLL(dllpath_depends1)
        _dll = _CDLL(dllpath)
        print("+ Using Module(s) ", dllpath)
        print("                  ", dllpath_depends1)
        print("+ Last Update:", _asctime(_localtime(_stat(dllpath).st_mtime)))
        print("+ Process ID:", str(_getpid()))
        if connect():
            print("+ Succesfully Connected to Service\Engine")
            if connected():
                print("+ Succesfully Connected to TOS")
            else:
                print("- Failed to Connect to TOS")
        else:
            print("- Failed to Connect to Service\Engine")
            print("- Failed to Connect to TOS")
        return True  # indicate the lib was loaded (but not if connect succeeded)
    except Exception as e:
        raise TOSDB_InitError("unable to initialize library:", e)
 def os_stat(path):
   return os._stat(longpathify(uni(path)))
Example #9
0
 def os_stat(path):
     return os._stat(longpathify(uni(path)))