def _get_binaries(self, path, binaries): if os.path.isdir(path): fileList = os.listdir(path) for f in fileList: if f and f[0] != '.' and f not in [ 'build' ] and not f.endswith('.cfg') and not f.endswith('.so'): self._get_binaries(os.path.join(path, f), binaries) elif os.path.isfile(path) and os.access(path, os.X_OK): binaries.append( fms.PathObj(path=path, mtime=os.path.getmtime(path)))
def ChangedFiles(self, request, context): result = fms.PathList() chnged_files = [] for item in request.items: mtime = 0 if os.path.exists(item.path): mtime = os.path.getmtime(item.path) if mtime != item.mtime: chnged_files.append(fms.PathObj(path=item.path, mtime=mtime)) result.items.extend(chnged_files) return result
def changed_files(self, files): ''' Request to test files for last modification time. :param files: dictionary with files and their last known modification time. See results of :meth:`fkie_node_manager_daemon.launch_stub.LaunchStub.get_mtimes`, :meth:`fkie_node_manager_daemon.launch_stub.LaunchStub.load_launch`. :type files: dict(str: float) ''' request = fmsg.PathList() pathlist = [] for path, mtime in files.items(): pathlist.append(fmsg.PathObj(path=path, mtime=mtime)) request.items.extend(pathlist) response = self.fm_stub.ChangedFiles(request, timeout=settings.GRPC_TIMEOUT) return response.items
def delete(self, path): ''' Delete path. :param str path: existing path :raise OSError: :raise IOError: :raise Exception: ''' response = self.fm_stub.Delete(fmsg.PathObj(path=path), timeout=settings.GRPC_TIMEOUT) if response.code == OK: pass elif response.code == OS_ERROR: raise OSError(response.error_code, response.error_msg, response.error_file) elif response.code in [IO_ERROR]: raise IOError(response.error_code, response.error_msg, response.error_file) elif response.code == ERROR: raise Exception("%s, path: %s" % (response.error_msg, response.error_file))
def new(self, path, path_type): ''' Create a new path. :param str path: existing path :param int path_type: path type, 0=file, 1=directory :raise OSError: :raise IOError: :raise Exception: ''' response = self.fm_stub.New(fmsg.PathObj(path=path, type=path_type), timeout=settings.GRPC_TIMEOUT) if response.code == OK: pass elif response.code == OS_ERROR: raise OSError(response.error_code, response.error_msg, response.error_file) elif response.code in [IO_ERROR]: raise IOError(response.error_code, response.error_msg, response.error_file) elif response.code == ERROR: raise Exception("%s, path: %s" % (response.error_msg, response.error_file))
def ListPath(self, request, context): result = fms.ListPathReply() result.path = request.path path_list = [] if not request.path: # list ROS root items for p in os.getenv('ROS_PACKAGE_PATH').split(':'): try: path = os.path.normpath(p) fileList = os.listdir(path) file_type = None if is_package(fileList): file_type = PATH_PACKAGE else: file_type = PATH_DIR self.DIR_CACHE[path] = file_type path_list.append( fms.PathObj(path=path, mtime=os.path.getmtime(path), size=os.path.getsize(path), type=file_type)) except Exception as _: pass else: try: # list the path dirlist = os.listdir(request.path) for cfile in dirlist: path = os.path.normpath('%s%s%s' % (request.path, os.path.sep, cfile)) if os.path.isfile(path): path_list.append( fms.PathObj(path=path, mtime=os.path.getmtime(path), size=os.path.getsize(path), type=PATH_FILE)) elif path in self.DIR_CACHE: path_list.append( fms.PathObj(path=path, mtime=os.path.getmtime(path), size=os.path.getsize(path), type=self.DIR_CACHE[path])) elif os.path.isdir(path): try: fileList = os.listdir(path) file_type = None if is_package(fileList): file_type = PATH_PACKAGE else: file_type = PATH_DIR self.DIR_CACHE[path] = file_type path_list.append( fms.PathObj(path=path, mtime=os.path.getmtime(path), size=os.path.getsize(path), type=file_type)) except Exception as _: pass except OSError as ose: # import traceback # print(traceback.format_exc()) result.status.code = OS_ERROR if ose.errno: result.status.error_code = ose.errno result.status.error_msg = utf8(ose.strerror) result.status.error_file = utf8(ose.filename) result.items.extend(path_list) return result