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)
def _create__tosdb(consts, topics): topic_dict = dict(zip(topics, topics)) for key in topic_dict: if key in TOPIC_VAL_REPLACE: # don't just .update, check all are valid topic_dict[key] = TOPIC_VAL_REPLACE[key] with open(_OUTPUT_PATH, 'w') as pfile: pfile.write('# AUTO-GENERATED BY tosdb/setup.py\n') pfile.write('# DO NOT EDIT!\n\n') pfile.write('_BUILD_DATETIME = "' + _asctime() + '"\n') for c in consts: pfile.write(c.replace('TOSDB_', '', 1) + ' = ' + consts[c] + '\n') pfile.write('\n\n') pfile.write('from tosdb.meta_enum import MetaEnum\n') pfile.write('class TOPICS(metaclass=MetaEnum):\n') pfile.write(' fields = ' + str(topic_dict) + '\n')
def _create__tosdb(consts, topics): topic_dict = dict(zip(topics,topics)) for key in topic_dict: if key in TOPIC_VAL_REPLACE: # don't just .update, check all are valid topic_dict[key] = TOPIC_VAL_REPLACE[key] with open(_OUTPUT_PATH,'w') as pfile: pfile.write('# AUTO-GENERATED BY tosdb/setup.py\n') pfile.write('# DO NOT EDIT!\n\n') pfile.write('_BUILD_DATETIME = "' + _asctime() + '"\n') for c in consts: pfile.write(c.replace('TOSDB_','',1) + ' = ' + consts[c] + '\n') pfile.write('\n\n') pfile.write('from tosdb.meta_enum import MetaEnum\n') pfile.write('class TOPICS(metaclass=MetaEnum):\n') pfile.write(' fields = ' + str(topic_dict) + '\n')
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 )
def _create__tosdb(consts, topics): error_consts = _build_error_lookup(consts) topic_dict = dict(zip(topics, topics)) for key in topic_dict: if key in TOPIC_VAL_REPLACE: # don't just .update, check all are valid topic_dict[key] = TOPIC_VAL_REPLACE[key] with open(_OUTPUT_PATH, 'w') as pfile: pfile.write('# AUTO-GENERATED BY tosdb/setup.py\n') pfile.write('# DO NOT EDIT!\n\n') pfile.write('_BUILD_DATETIME = "' + _asctime() + '"\n') for k, v in consts: pfile.write(k.replace('TOSDB_', '', 1) + ' = ' + v + '\n') pfile.write('\n') pfile.write('from tosdb.meta_enum import MetaEnum\n') pfile.write('class TOPICS(metaclass=MetaEnum):\n') pfile.write(' fields = ' + str(topic_dict) + '\n') pfile.write('\n') pfile.write('ERROR_LOOKUP = { \n') for k, v in error_consts.items(): pfile.write(str(int(k)) + ": '" + v + "', \n") pfile.write('} \n')
def _create__tosdb(consts, topics): error_consts = _build_error_lookup(consts) topic_dict = dict(zip(topics,topics)) for key in topic_dict: if key in TOPIC_VAL_REPLACE: # don't just .update, check all are valid topic_dict[key] = TOPIC_VAL_REPLACE[key] with open(_OUTPUT_PATH,'w') as pfile: pfile.write('# AUTO-GENERATED BY tosdb/setup.py\n') pfile.write('# DO NOT EDIT!\n\n') pfile.write('_BUILD_DATETIME = "' + _asctime() + '"\n') for k,v in consts: pfile.write(k.replace('TOSDB_','',1) + ' = ' + v + '\n') pfile.write('\n') pfile.write('from tosdb.meta_enum import MetaEnum\n') pfile.write('class TOPICS(metaclass=MetaEnum):\n') pfile.write(' fields = ' + str(topic_dict) + '\n') pfile.write('\n') pfile.write('ERROR_LOOKUP = { \n') for k,v in error_consts.items(): pfile.write( str(int(k)) + ": '" + v + "', \n" ) pfile.write('} \n')
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)
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 asctime(self): return _asctime(self._tfunc(self._intervals_since_epoch * self._isec))
def formatted_local_time(): return _asctime(_localtime())