def __init__(self, cfg) : threading.Thread.__init__(self) self.log = Log(type(self).__name__, 3) self.read_commands(cfg) self.readyToRun = None self.stop_event = threading.Event() signal.signal(signal.SIGINT, self.handel_signal)
class Dump (threading.Thread) : @staticmethod def start_thread(**kwargs) : command = kwargs.get('command', None) if command is None : print("Can't get command obj") return stop = kwargs.get('stop', None) if stop is None : print("Can't get stop event obj") return print(command) step = command.timeStep cnt = 0 while not stop.is_set() : for cmd in command.cmd : ShellCommand.fork(cmd) if step > 0 : time.sleep(step) print("{}\t count {}".format(command.name, cnt)) cnt += 1 if step < 0 : break def __init__(self, cfg) : threading.Thread.__init__(self) self.log = Log(type(self).__name__, 3) self.read_commands(cfg) self.readyToRun = None self.stop_event = threading.Event() signal.signal(signal.SIGINT, self.handel_signal) def __str__(self) : string = "" for key, value in self.commands.items() : string += "{}\t: {}\n".format(key, value) return string def handel_signal(self, signal, frame) : self.stop_event.set() def read_commands(self, cfg) : config = configparser.ConfigParser() config.read(cfg) self.commands = {} for name in config.sections() : cmd = config.get(name, 'cmd').replace('"', '').replace(",", '') ret = [] for c in cmd.split('|') : c = "adb wait-for-device shell {}".format(c) ret.append(c) timeStep = config.getint(name, 'time_step') self.commands[name] = Command(name, ret, timeStep) def set_command(self, key) : ret = self.commands.get(key, None) if ret is None : self.log.e("{} not found".format(key)) else : self.readyToRun = ret def start(self) : if self.readyToRun is None : self.log.e("Not ready to run, please set_command first") return kwargs = {'command':self.readyToRun, 'stop':self.stop_event} self.th = threading.Thread(target=Dump.start_thread, kwargs=kwargs) self.th.start() self.th.join()