def get_config(cls, conf=""): cls.service_conf = {} if conf == "": conf = os.path.join(define.APP_BIN, "port.ini") L.debug(conf) try: config = ConfigParser.ConfigParser() config.read(conf) for section in config.sections(): for option in config.options(section): cls.service_conf["%s" % option] = config.get(section, option) except Exception as e: L.warning("error: could not read config file: %s" % e)
def __exec(self, cmd, timeout=TIMEOUT): proc = Process(cmd, self.queue) proc.start() proc.join(timeout) if proc.is_alive(): proc.kill() time.sleep(3) L.debug("proc.terminate. %s" % proc.is_alive()) if self.queue.empty(): return None return self.queue.get()
def _service_parse(cls, conf=""): result = [] if conf == "": conf = os.path.join(define.APP_SCRIPT, "module.ini") try: config = ConfigParser.ConfigParser() config.read(conf) for section in config.sections(): for option in config.options(section): if config.get(section, option) == str(True): result.append(option) return result except Exception as e: L.warning('error: could not read config file: %s' % e) return result
def register(cls): base_dir = define.APP_LIB cwd = os.getcwd() for fdn in os.listdir(base_dir): try: if fdn.endswith(".pyc") or fdn.endswith(".py"): pass else: sys.path.append(os.path.join(base_dir, fdn)) f, n, d = imp.find_module("service") module = imp.load_module("service", f, n, d) cls.service[module.NAME] = module.FACTORY sys.path.remove(os.path.join(base_dir, fdn)) except Exception as e: L.warning('error: could not search "service.py" file in %s : %s' % (fdn, e))
def get_config(cls, conf=""): """ Get Config File. :arg string conf: config file path. """ cls.config = {} if conf == "": conf = os.path.join(define.APP_SCRIPT, "config.ini") try: config = ConfigParser.ConfigParser() config.read(conf) for section in config.sections(): for option in config.options(section): cls.config["%s.%s" % (section, option)] = config.get(section, option) except Exception as e: L.warning('error: could not read config file: %s' % e)
def parse_testcase(self, filename, folder=define.APP_EXCEL): """ Parse TestCases in the ".csv" File. :arg string filename: csv filename. :arg string folder: exists csv file. Default : bantorra/excel """ self.testcase = [] try: path, ext = os.path.splitext(filename) if ext != ".csv": pass else: with open(os.path.join(folder, filename), 'r') as f: reader = csv.reader(f) next(reader) for r in reader: self.testcase.append(r[0]) except Exception, e: L.warning('error: could not read config file: %s' % e) return
def load(self, testcase): """ TestCase Load Method. .. warning:: Default Settings, TestCase Folder is only bantorra/script. TestCase Class is only inheritant of testcase_base.py :arg string testcase: testcase name. only ".py" file. :return module: module object. """ sys.path.append(define.APP_SCRIPT) if testcase.find(".py") != -1: script = testcase else: script = testcase + ".py" path = os.path.join(define.APP_SCRIPT, script) name = script[:script.find(".")] L.debug("TestCase : %s" % path) if os.path.exists(path): f, n, d = imp.find_module(str(name)) return imp.load_module(name, f, n, d) else: return False
def start_all(cls): L.info(cls.service_conf) try: for x in cls.service.values(): L.info(int(cls.service_conf["kancolle"])) #x.start(int(cls.service_conf["kancolle"])) p = multiprocessing.Process(target=x.start, args=(int(cls.service_conf["kancolle"]), )) p.daemon = True except Exception as e: L.warning(str(e))
def run(self): L.info("Command Send : %s" % self.command) args = self.command.split(" ") subproc_args = { 'stdin' : subprocess.PIPE, 'stdout' : subprocess.PIPE, 'stderr' : subprocess.PIPE, } try: proc = subprocess.Popen(args, **subproc_args) except OSError: L.info("Failed to execute command: %s" % args[0]) sys.exit(1) (stdout, stderr) = proc.communicate() code = proc.wait() L.debug("Command Resturn Code: %d" % code) self.queue.put(stdout)
try: for x in cls.service.values(): L.info(int(cls.service_conf["kancolle"])) #x.start(int(cls.service_conf["kancolle"])) p = multiprocessing.Process(target=x.start, args=(int(cls.service_conf["kancolle"]), )) p.daemon = True except Exception as e: L.warning(str(e)) @classmethod def stop_all(cls): try: for x in cls.service.values(): x.shutdown() except Exception as e: L.warning(str(e)) @classmethod def restart_all(cls): cls.stop_all() time.sleep(3) cls.start_all() if __name__ == '__main__': proc = ServiceControl() L.info("Start Service") proc.start_all() time.sleep(20) L.info("Stop Service") proc.stop_all()
def kill(self): L.debug("Kill This Process.") self.terminate()
if id in filename and ext == ".py": return filename return False def parse_testcase(self, filename, folder=define.APP_EXCEL): """ Parse TestCases in the ".csv" File. :arg string filename: csv filename. :arg string folder: exists csv file. Default : bantorra/excel """ self.testcase = [] try: path, ext = os.path.splitext(filename) if ext != ".csv": pass else: with open(os.path.join(folder, filename), 'r') as f: reader = csv.reader(f) next(reader) for r in reader: self.testcase.append(r[0]) except Exception, e: L.warning('error: could not read config file: %s' % e) return if __name__ == "__main__": runner = TestRunner() if len(sys.argv[1:]) < 1: sys.exit("Usage: %s <filename>" % sys.argv[0]) testcase = sys.argv[1] L.info("testcase name : %s " % testcase) runner.execute(testcase)
def service_check(cls, conf=""): serv = cls._service_parse(conf) for s in serv: if not s in cls.service: L.warning("error : not installed service: %s" % s) sys.exit(1)
def stop_all(cls): try: for x in cls.service.values(): x.shutdown() except Exception as e: L.warning(str(e))
def setUpClass(cls): L.info("*** Start TestRunner. Version : %s" % cls.core.version()) L.info("*** Start TestCase : %s *** " % __file__)
def picture_crop(self, pic, box="", filename=""): try: return self.picture.crop_picture(pic, box, filename) except Exception as e: L.warning(e)
def ret_rgb(self, pic, box=""): try: return self.picture.get_rgb(pic, box) except Exception as e: L.warning(e)
def picture_is_pattern(self, reference, target): try: return self.picture.is_pattern(reference, target) except Exception as e: L.warning(e)
def tearDownClass(cls): L.info("*** End TestCase : %s *** " % __file__)