def new_conn_thread_func(conn, addr): print addr try: handler = ConnHandler(conn) handler.do_work() except Exception, error: Log.logerr('svr handler thread exception: %d(%s)' % (error.errno, error.strerror))
def do_cmds(self, msg): if (msg.startswith("recv")): return self.recv_file(msg) elif (msg.startswith("send")): local_file = msg.split('#')[1] return self.send_file(local_file, local_file, True) elif (msg.startswith("cmd")): cmd,shell = self.parse_cmd_args(msg) ctl = Command() if (shell == 'shell'): ret_info = ctl.run_sys_cmd(cmd) return self.send_msg(self.sock, Message.MSG_CTRL, ret_info) elif (shell == 'update'): args = sys.argv[:] args.insert(0, sys.executable) os.chdir(os._startup_cwd) msg = 'success' self.send_msg(self.sock, Message.MSG_CTRL, msg) self.sock.close() Log.logmsg("Update self:%s,%s" % (args, os._startup_cwd)) os.execv(sys.executable, args) #no return else: Log.logerr("Invalid cmd!%s" % msg) return False
def connect_server(self, host): try: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((host, self.PORT)) except socket.error, error : Log.logerr('socket failed: %d(%s)' % (error.errno, error.strerror)) return False
def read_config(self, file_name): if not os.path.exists(file_name): Log.logerr("CONF:%s not exists,using default." % file_name) return False tree = xml.etree.ElementTree.ElementTree(file=file_name) root = tree.getroot() self.svr_conf_dict['listen'] = int(root.findall ('server/listen')[0].text) self.svr_conf_dict['backlog'] = int(root.findall ('server/backlog')[0].text) return True
def init_sock(self): try: port = self.conf.svr_conf_dict['listen'] back_log = self.conf.svr_conf_dict['backlog'] self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.set_close_exec(self.sock.fileno()) self.sock.bind(('', port)) self.sock.listen(back_log) except socket.error, error : Log.logerr('server init socket failed: %s(%s)' % (socket.error, error)) return False
def test_cancel_task_reason_too_long_fail(self): """HK reason为超长,取消任务失败""" Log.debug('test_cancel_task_reason_too_long_fail start') para_id = 21 data_id = 21007 res = self.cancel_task.base_cancel_task(para_id=para_id, data_id=data_id, cookies=self.admin_cookies, flag=False, task_modify=0, reason_modify=1) self.assertTrue(res, msg='result check fail') Log.debug('test_cancel_task_reason_too_long_fail end') pass
def base_get_gen_cal_result(self, para_id, data_id, cookies, flag): """历史记录-查询基因编辑距离对比计算结果公共方法""" # 获取请求url url_get_gen_cal_result = self.domain + Base.dh.get_path(para_id) Log.info('get_gen_cal_result request url : {}'.format( url_get_gen_cal_result)) # 获取请求数据 data_source = self.dh.get_data(data_id) req_para = Base.get_req_para(para_id=para_id, data_id=data_id) # 查询数据库taskId,随机选择查询 req_para['taskId'] = self.get_gen_done_task_id() data_source[0][5] = req_para['taskId'] # 数据库查询taskId为空处理 if req_para['taskId'] is None: actual = not flag Log.error('数据库查询taskId为空,该用例未执行,失败') else: Log.info('get_gen_cal_result request data is {}'.format(req_para)) # 请求 res = requests.post(url=url_get_gen_cal_result, headers=Base.headers, cookies=cookies, data=Base.sign(req_para)).json() Log.info('get_gen_cal_result response data is {}'.format(res)) # 结果检查 actual = self.get_gen_cal_result_check(req_para['taskId'], res, flag) # 结果写入 DataHandle.set_data(data_source[0], actual) self.dh.write_data(data_source) # 结果检查 return self.dh.check_result(data_source)
def get_responses(self,Url,method,Request_Data,Request_Data_Type): try: res = None if method == 'POST' or method == 'POST': res = requests.post(Url,data=json.dumps(Request_Data),headers=Request_Data_Type) if method == 'GET' or method == 'get': res = requests.get(Url,data=json.dumps(Request_Data),headers=Request_Data_Type) responese = res.json() return responese # code = responese.get("code") # msg = responese.get("msg") # content = {"code":code,"msg":msg} # return content except HTTPError as e: Log.debug('响应失败',e)
def setUpClass(cls): global logger global driver logger = Log() # 实例化浏览器引擎 logger.info( '############################### START ###############################' ) driver = Browser_engine().get_browser() cls.index = Ganzhou_pages.Ganzhou_pages_login(driver) cls.index.max_window() cls.index.open_Ganzhou(param[2]["url"]) cls.index.type_username(param[2]["username"]) cls.index.type_password(param[2]["password"]) cls.index.click_login()
def __init__(self, args=None): """ Initialize. :param args: optional arguments if not to use sys.argv :type args: [str] """ self.args = None """ Arguments of program. """ parser = self.get_parser() if args is not None: self.args = parser.parse_args(args) else: self.args = parser.parse_args() self.test_codes = None """ (numpy.ndarray) Codes for testing. """ self.perturbation_codes = None """ (numpy.ndarray) Perturbation codes for testing. """ self.model = None """ (encoder.Encoder) Model to train. """ self.perturbations = None """ (numpy.ndarray) Perturbations per test image. """ self.original_accuracy = None """ (numpy.ndarray) Success of classifier. """ self.transfer_accuracy = None """ (numpy.ndarray) Success of classifier. """ self.original_success = None """ (numpy.ndarray) Success per test image. """ self.transfer_success = None """ (numpy.ndarray) Success per test image. """ if self.args.log_file: utils.makedir(os.path.dirname(self.args.log_file)) Log.get_instance().attach(open(self.args.log_file, 'w')) log('-- ' + self.__class__.__name__) for key in vars(self.args): log('[Testing] %s=%s' % (key, str(getattr(self.args, key))))
class Login_in(): log = Log() def __init__(self): self.yaml_data = ReadFile().read_yaml("yaml_path") self.header = self.yaml_data["header"] self.url = self.yaml_data["url"] self.link_url = self.yaml_data["c_login"]["url"] self.login_method = self.yaml_data["c_login"]["method"] self.login_param = self.yaml_data["c_login"]["param"] def c_longin_in(self, mobile): """ 登录 :param mobile: :return: """ try: self.login_param["mobile"] = mobile result = Runmethod.run_main(self.login_method, url, self.login_param, self.header) return result except Exception as e: print("登录报错{}".format(e)) self.log.error("登录报错{}".format(e))
class Test_news(): log = Log() @allure.feature("功能点:添加新闻") @allure.story("用例:用户新添加新闻") @pytest.mark.parametrize("title,author,abstract", testdata["test_add_news_data"], ids=["正常添加"]) # @pytest.mark.skip('跳过该成功用例') def test_add_new(self, login_fixtrue, title, author, abstract): driver = login_fixtrue new = NewsPage(driver) with allure.step("点击进入新闻管理模块"): new.come_news() time.sleep(2) with allure.step("点击进入新增新闻页面"): new.add_news() with allure.step("输入新闻标题"): new.input_title(title) with allure.step("点击自定义作者"): new.click_CustomAuthor() with allure.step("输入自定义作者名"): new.input_author(author) time.sleep(2) with allure.step("选择TMT(一级)频道"): new.input_channel() with allure.step("选择原创类型"): new.input_type() new.select_tpye() time.sleep(7) with allure.step("选择同步首页"): new.select_homePage() with allure.step("填写摘要"): new.input_abstract(abstract) time.sleep(5)
def find_brand_by_identify(self, word): """stock_brandsのidentifyにつぶやきwordを当てて検索""" brands = list( self.dao.table('stock_brands').find({"identify": { "$in": [word] }}, {'_id': 0})) if not brands: Log.error('wordがstock_brandsに無い。mecab辞書とidentifyが不一致') return False if len(brands) > 1: Log.warn( "confrict word!! stock_brandsのidentifyフィールドに同じwordをもつ銘柄がある。 word={}", word) return False return AttrDict(brands[0])
class LoginTest(unittest.TestCase): log = Log() def setUp(self): self.log.info("登录测试开始") def test_login_suc(self): """登入测试用例!!!!""" lg_suc = Login('login_by_account') result = lg_suc.login_service() self.log.info("test_login_suc 登录的status code为:" + str(lg_suc.status_code())) "断言二:登录的国家是否是jp" + str( self.assertEqual(result['info']['countryid'], 'JP')) def test_login_invaild_password(self): """密码错误登录""" lg_invaild_password = Login("login_invaild_password") result = lg_invaild_password.login_service(True) self.log.info("test_login_invaild_password 登录的status code 为:" + str(lg_invaild_password.status_code())) "断言 是否是密码错误的提示:" + str(self.assertIn("password", result)) def test_logout(self): """登出测试用例""" lgout = LogOut("logout") result = lgout.logout_service() self.log.info("test_logout 的status code 为: " + str(lgout.status_code())) "断言: 是否登出:" + str(self.assertEqual(result['CODE'], "1")) def tearDown(self): self.log.info('登录测试结束')
def get_main(self, url, data=None, headers=None): try: if headers != None: res = requests.get(url=url, data=data, headers=headers, verify=False) else: res = requests.get(url=url, data=data, verify=False) res_code = res.status_code Log().info("成功发送GET请求,请求结果code为:%s,请求结果字段为:%s" % (res_code, res.json())) return res.json() except Exception as e: Log().error("GET请求出错,出错原因:%s" % e) return {'code': 1, 'result': 'post请求出错,出错原因:%s' % e}
def setUpClass(cls): global logger global driver logger = Log() # 实例化浏览器引擎 logger.info( '############################### START ###############################' ) driver = Browser_engine().get_browser() # driver = Browser_engine().get_browser() cls.index = Hunan_pages.Hunan_pages_login(driver) cls.index.max_window() cls.index.open_Hunan(param[1]["url"]) cls.index.username_input(param[1]["username"]) cls.index.password_input(param[1]["password"]) cls.index.click_login()
class Test_login(): log = Log() @allure.feature("功能点:用户登录页面") @allure.story("用例:用户登录") @pytest.mark.parametrize("username,password,msg", testdata["test_login_success_data"], ids=["正确用户名密码登录"]) # @pytest.mark.skip('跳过该成功用例') def test_success_login(self, username, password, msg): driver = webdriver.Chrome() web = LoginPage(driver) web.login(user=username, password=password) result = web.is_login_success(expect_text=msg) self.log.info("登录结果:%s" % result) # time.sleep(10) assert result # web.is_quit() @allure.feature("功能点:用户登录页面") @allure.story("用例:用户登录") @pytest.mark.parametrize("username,password,msg", testdata["test_login_fail_data"], ids=["正确用户名错误密码登录", "错误用户名正确密码登录"]) # @pytest.mark.skip('跳过') def test_fail_login(self, username, password, msg): driver = webdriver.Chrome() web = LoginPage(driver) web.login(user=username, password=password) result = web.is_login_fail(expect_text=msg) self.log.info("登录结果:%s" % result) assert result
def setUpClass(cls): cls.driver = set_options() cls.driver.set_window_size(1920, 1080) cls.login_driver = LoginPage(cls.driver) cls.login_driver.open(login_url) cls.log = Log() cls.find_driver = FindPage(cls.driver)
def setUpClass(cls): cls.s = requests.session() copy_excel(globalparam.data_path_name,globalparam.result_path) cls.run_method = Run_Method() cls.logger = Log() cls.logger.info( '############################### START ###############################')
class Test_login(): log = Log() @allure.story("用例:用户登录") @pytest.mark.parametrize("username,password,msg",testdata["login_success_data"], ids = ["正确用户名密码登录"]) #@pytest.mark.skip('跳过该成功用例') @pytest.mark.run(order=-1)#调整登录成功用例最后运行 def test_success_login(self,open_browser,username,password,msg): driver = open_browser #driver = Base().driver web = LoginPage(driver) web.login(user=username,password=password) with allure.step("获取结果: 获取页面实际结果,判断是否登录成功"): result = web.is_login_success(expect_text=msg) self.log.info("登录结果:%s"%result) with allure.step("断言:判断是否登录成功"): assert result #driver.quit() @allure.story("用例:用户登录") @pytest.mark.parametrize("username,password,msg", testdata["login_fail_data"], ids=["错误用户名正确密码登录"]) # @pytest.mark.skip('跳过') def test_fail_login(self,open_browser,username,password,msg): #driver调用前置无头模式启动 driver = open_browser web = LoginPage(driver) web.login(user=username,password=password) with allure.step("获取结果: 获取页面实际结果,判断是否登录成功"): result = web.is_login_fail(expect_text=msg) self.log.info("登录结果:%s"%result) with allure.step("断言:判断是否登录成功"): assert result
def setUpClass(cls): cls.driver = set_options() cls.driver.set_window_size(1920, 1080) cls.login_driver = LoginPage(cls.driver) cls.login_driver.open(login_url) cls.login_driver.user_login(cls.login_driver, '*****@*****.**', 'ab1234567') cls.find_pwd_driver = PostAnOfferPage(cls.driver) cls.log = Log()
class ConfigHttp: def __init__(self): self.host = localReadConfig.get_http("baseurl") self.port = localReadConfig.get_http("port") self.timeout = localReadConfig.get_http("timeout") self.logger = Log().get_logger() self.headers = {} self.params = {} self.data = {} self.url = "" self.files = {} def set_url(self, url, host=""): if host == "": self.url= self.host + url else: self.url = host + url def set_headers(self, header): self.headers = header def set_params(self, param): self.params = param def set_data(self, data): self.data = data def set_files(self, file): self.files = file # define http method def get(self): try: response = requests.get(self.url, params=self.params, headers=self.headers, timeout=float(self.timeout)) return response except TimeoutError: self.logger.error("Time out!") return None def post(self): try: response = requests.post(self.url, data=self.data, headers=self.headers, timeout=float(self.timeout)) return response except TimeoutError: self.logger.error("Time out!") return None
def initilize_logs(patterns,scalefactors,seeds): logfiles = [] global logFileDirectory for scalefactor in scalefactors: for seed in seeds: for pattern in patterns: logfiles.append(Log.find_logfile(pattern,scalefactor,seed,logFileDirectory)) return logfiles
def get_server_check(self, res): code = '00000' if res["code"] != code: Log.error('请求返回有误 {}'.format(res)) return 0 # 查询数据库服务器列表 sql_get_server = 'select id serverId,serverName name from t_server order by id' data_database = self.con_n.select_dic(sql_get_server) Log.info('数据库服务器列表:{}'.format(data_database)) # 按id升序排列 data_res = sorted(res['data'], key=lambda k: k['serverId']) Log.info('接口查询服务器列表:{}'.format(data_res)) if len(data_database) == len(data_res): Log.info('check success,result is 1') return 1 Log.error('接口返回数据与数据库查询不一致!') return 0
def __init__(self, args=None): """ Initialize. :param args: arguments :type args: list """ self.args = None """ Arguments of program. """ self.test_images = None """ (numpy.ndarray) Images to test on. """ self.test_codes = None """ (numpy.ndarray) Codes for testing. """ self.model = None """ (encoder.Encoder) Model to train. """ self.loss = None """ (float) Will hold evalauted loss. """ self.error = None """ (float) Will hold evaluated error. """ self.accuracy = None """ (numpy.ndarray) Will hold success. """ self.results = dict() """ (dict) Will hold evaluation results. """ parser = self.get_parser() if args is not None: self.args = parser.parse_args(args) else: self.args = parser.parse_args() # sys.args utils.makedir(os.path.dirname(self.args.log_file)) if self.args.log_file: Log.get_instance().attach(open(self.args.log_file, 'w')) log('-- ' + self.__class__.__name__) for key in vars(self.args): log('[Testing] %s=%s' % (key, str(getattr(self.args, key))))
def test_002(self): """百度搜索_Appium""" """百度搜索_Python""" try: self.driver.maximize_window() Log().info(" 浏览器窗口最大化") self.driver.implicitly_wait(time_to_wait=5) Log().info(" 设置隐性等待时间为5秒") self.driver.get(url="https://www.baidu.com") Log().info(" 访问百度") self.driver.find_element_by_xpath("//input[@id='kw']").send_keys( "Appium") Log().info(" 搜索输入框输入Python") time.sleep(1) self.driver.find_element_by_xpath("//input[@id='su']").click() Log().info(" 点击百度一下搜索框") time.sleep(1) title = self.driver.title Log().info(" 获得当前页面标题:%s" % title) time.sleep(2) assert "Appium_百度搜索", title except Exception as e: timeStrmap = time.strftime('%Y%m%d_%H_%M_%S') img_name = os.path.join(img_path, "%s.png" % str(timeStrmap)) Log().info(message=" 异常截图保存路径: %s 异常截图名称:%s" % (img_path, os.path.split(img_name)[1])) self.driver.get_screenshot_as_file(img_name) raise
def updata(self, sql): conn = pymysql.connect( host=self.conf.get('host'), port=int(self.conf.get('port')), user=self.conf.get('user'), password=self.conf.get('password'), database=self.conf.get('database'), ) cur = conn.cursor() try: cur.execute(sql) conn.commit() except: # 发生错误回滚 conn.rollback() Log.error("updata fail ! {}".format(sql)) cur.close() conn.close()
def select_dic(self, sql): """返回字典""" conn = pymysql.connect(host=self.conf.get('host'), port=int(self.conf.get('port')), user=self.conf.get('user'), password=self.conf.get('password'), database=self.conf.get('database'), cursorclass=pymysql.cursors.DictCursor) cur = conn.cursor() try: cur.execute(sql) result = cur.fetchall() return result except: Log.error('select_dic error !') finally: cur.close() conn.close()
def gwas_check(self, res): code = '00000' if res['code'] == code: Log.info('result check success ') return 1 # taskId = res['data'] # Log.debug('taskId is {}'.format(taskId)) # [data_n, data_o] = self.get_data(taskId) # Log.info('本端数据为: {}'.format(data_n)) # Log.info('对端数据为: {}'.format(data_o)) # if self.compare(data_n, data_o): # Log.info('compare result is True ,success !') # return 1 # else: # Log.error('compare result is False ,fail !') # return 0 Log.error('请求返回有误!{}'.format(res)) return 0
def write_excel(self, sheet_name, row, col, value): try: wb = load_workbook(self.file_name) sheet = wb[sheet_name] sheet.cell(row, col).value = '{}'.format(value) wb.save(self.file_name) wb.close() except Exception as e: Log().error('---写回测试结果失败{}'.format(e))
def setUpClass(cls): cls.driver = set_options() cls.driver.set_window_size(1920, 1080) cls.login_driver = LoginPage(cls.driver) cls.login_driver.open(login_url) cls.login_driver.user_login(cls.login_driver, "*****@*****.**", "ab1234567") cls.my_offers_driver = MyOffersPage(cls.driver) cls.log = Log()
class MyTest(unittest.TestCase): """ 适用于所有的testcase """ def setUp(self): self.logger = Log() self.logger.info( '##################### START ######################') warnings.simplefilter('ignore', ResourceWarning) driver = init_driver() self.driver = driver self.loginPage = LoginPage(self.driver) self.registerPage = RegisterPage(self.driver) self.settingPage = SettingPage(self.driver) def tearDown(self): self.driver.quit() self.logger.info("####################### END #####################")
def __init__(self, host=None, port=0, user=None, passwd=None, db=None, charset=None, max_retries_count=None, conn_retries_count=None, conn_timeout=None): con_status = True #定位路径 file = os.path.abspath( os.path.join(os.getcwd(), '..', 'database', 'config')) config = ConfigParser() config.read(file) host = config.get("mysql", 'host') port = config.getint("mysql", 'port') user = config.get("mysql", 'user') passwd = config.get("mysql", 'passwd') db = config.get("mysql", 'db') charset = config.get("mysql", 'charset') max_retries_count = config.getint("mysql", 'max_retries_count') conn_retries_count = config.getint("mysql", 'conn_retries_count') connect_timeout = config.getint("mysql", 'connect_timeout') while con_status and max_retries_count > conn_retries_count: try: #建立连接 self.conn = pymysql.Connect(host=host, port=port, user=user, passwd=passwd, db=db, charset=charset) Log().info('连接成功') # 创建游标 self.cursor = self.conn.cursor() con_status = False except: conn_retries_count += 1 print(conn_retries_count) Log().debug('连接失败') continue
def get_report_search_results(self, start_day: datetime, end_day: datetime, start_page=1, page_count=None): """ EDINETの書類検索(全文検索)の結果一覧を取得する。 対象は「有価証券報告書」「文字列に『大株主の状況』を含む」「指定期間」 検索一覧行オブジェクトリストを返す。 start_page(1始まり)、page_countの指定がない場合は全ページ対象。 """ rows, idx, page = [], 0, 1 while True: url = EdinetUrl.search_url.value.format(start_day.year, start_day.month, start_day.day, end_day.year, end_day.month, end_day.day, str(idx)) html = requests.get(url, timeout=20, headers=self.user_agent, verify=False) bs = BeautifulSoup(html.text, "lxml") if start_page <= page: table = bs.find_all('table', {'class': 'resultTable'}) row_datas = self.get_row_datas(table) rows.extend(row_datas) Log.debug('{}ページ読込。計{}件'.format(page, len(rows))) if page_count and page_count == page + 1 - start_page: break if not self.has_next_page(bs): break idx = idx + 100 page = page + 1 return rows
def compare(self, data_n, data_o): list1 = [] list2 = [] list1.append(data_n['calType']) list2.append(data_o['calType']) list1.append(data_n['startName']) list2.append(data_o['startName']) list1.append(data_n['acceptName']) list2.append(data_o['acceptName']) list1.append(data_n['remark']) list2.append(data_o['remark']) list1.append(data_n['status']) list2.append(data_o['status']) list1.append(data_n['name']) list2.append(data_o['name']) Log.info('compare data is {}'.format(list1)) Log.info('compare data is {}'.format(list2)) if list1 == list2: return True return False
def do_work(self): while (True): header = self.readn(self.sock, 8) if not header: return True version, machine, type, length = Message.parse_msg_header(header) if (version != Message.version or machine != Message.TYPE_HYDRA): Log.logerr("Server check message header failed!") return False msg = self.readn(self.sock, length) if (type == Message.MSG_CTRL): Log.logmsg("Server try execute cmd :%s" % msg) if self.do_cmds(msg): Log.logmsg("Server execute cmd :%s, success" % msg) return True else: Log.logmsg("Server execute cmd :%s, success" % msg) else: Log.logerr("unknown cmd:%d %s" % (type, msg)) return False
def http_request(self, url, method, param, cookie): global resp if method.upper() == 'GET': try: resp = requests.get(url, params=param, cookies=cookie) # print(resp) # print(resp.text) # print(resp.json()) except Exception as e: Log.error('GET请求出错啦{}'.format(e)) elif method.upper() == 'POST': try: resp = requests.post(url, data=param, cookies=cookie) # result = resp.text() except Exception as e: Log().error('POST请求出错啦{}'.format(e)) else: print('不支持该方法') return resp
avgQueryTimeProduct = 1.0 avgQueryTimeSum = 0 for j, avgQueryTime in avgQueryTimes.iteritems(): avgQueryTimeProduct*=(avgQueryTime) avgQueryTimeSum+=(avgQueryTime) avgQueryTimes["avg"] = avgQueryTimeSum/22 avgQueryTimes["geo"] = nroot(avgQueryTimeProduct,22) result[key].append(avgQueryTimes) return result parse_arguments() # create data structure for logfilepath in logfilepaths: log = Log(logfilepath) queryTimes[log.get_pattern()+log.get_scale()].append(log.get_query_times()) for key, patternScaleSet in queryTimes.iteritems(): print key csvbody = [] csvbody.append(["Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10","Q11","Q12","Q13","Q14","Q15","Q16","Q17","Q18","Q19","Q20","Q21","Q22","Avg","Geo. mean"]) patternScaleSet.append(calculate_average(queryTimes)[key].pop()) #add avg results for queryTimeSet in patternScaleSet: tempList = [] for i, queryTimeList in queryTimeSet.iteritems(): tempList.append(queryTimeList) if len(tempList) != 24:
rc = False try: if (method == "get"): local_file = sys.argv[4] remote_file = sys.argv[3] rc = client.cli_get_file(local_file, remote_file) elif (method == "put"): local_file = sys.argv[3] remote_file = sys.argv[4] rc = client.cli_put_file(local_file, remote_file) elif (method == "cmd"): shell = sys.argv[3] if shell == "shell": cmd = ' '.join(sys.argv[4:]) rc = client.cli_cmd(cmd, shell) elif shell == "update": cmd = '' rc = client.cli_cmd(cmd, shell) else: print "invalid args", ' '.join(sys.argv[:]) else: print "invalid args:%s" % (' '.join(sys.argv[:])) except Exception, error: err_msg = 'exception: %d(%s)' % (error.errno, error.strerror) Log.logerr(err_msg) if not rc: sys.exit(1) else: sys.exit(0)
os.dup2(null.fileno(), sys.stdin.fileno()) os.dup2(null.fileno(), sys.stdout.fileno()) os.dup2(null.fileno(), sys.stderr.fileno()) return True def run_svr(): svr = Server() svr.run() if __name__ == "__main__": PIDFILE = "/var/run/agent.pid" WORKPATH = "/" os._startup_cwd = os.getcwd() if not g_conf.read_config(Config.CONF_FILE): Log.logerr("read config failed!") sys.exit(1) import getopt,sys try: opts,args = getopt.getopt(sys.argv[1:], "d", ["daemon",]) except getopt.GetoptError,e: print e sys.exit(1) for o,a in opts: if o in ("-d","--daemon"): if not createDaemon(PIDFILE, WORKPATH): Log.logerr("Daemon failed!") sys.exit(1) run_svr()