コード例 #1
0
    def DHTSearchReturn(self, data):
        # Write the contact information of our user to a local file for use
        utils = Utils()
        messagingPartnerInfo = utils.writeRecipitent(data)
        messagingPartnerInfo = json.loads(messagingPartnerInfo)

        # Open file and write to it
        with open("DHT.json", "r") as f:
            contents = f.read()
        self.recipitent = json.loads(contents)


        logging.info("ONION ROUTING START")

        # Instantiate our onion router
        onionRouter = OR()

        # Set the end node (reciever)
        OR.recieverIP = messagingPartnerInfo['ip']
        OR.recieverPort = int(messagingPartnerInfo['port'])
        OR.recieverPublicKey = messagingPartnerInfo['publickey']

        # Create our circuit
        onionRouter.constructRoute(self.recipitent)
        onionRouter.createOnionKeys()
        OR.loadInRecipitent()
        onionRouter.exchangeKeys()

        logging.info("ONION ROUTING END")
コード例 #2
0
    def configurate_logger(cls):
        '''
        Configuration python in-build logger with config object parameters
        '''

        configs = Configuration()

        cls.add_to_journal(__file__, LoggingLevel.INFO,
                           'Start execution function of configuration logger')

        Utils.create_folder_if_not_exists(
            os.path.join(Utils.get_project_root_path(), 'Log'))
        logging_settings_file_path = Configuration().settings[
            Values.LOGGER_SECTION_NAME][Values.LOGGING_CONF_FILE_PATH]

        logging.config.fileConfig(logging_settings_file_path)

        logger = logging.getLogger()

        for handler_indx in range(0, len(logger.handlers)):
            if isinstance(logger.handlers[handler_indx],
                          logging.handlers.RotatingFileHandler):
                path = logger.handlers[handler_indx].baseFilename
                path_parts = os.path.splitext(path)
                logger.handlers[handler_indx].baseFilename = path_parts[0] + " " \
                                                             + Utils.get_current_date_with_format() + \
                                                             path_parts[1]

                if os.path.exists(path) and os.path.getsize(path) > 0:
                    logger.handlers[handler_indx].doRollover()

        cls.add_to_journal(
            __file__, LoggingLevel.INFO,
            'Execution function of configuration logger finished')
コード例 #3
0
def crawl_item_details(queue, i):
    shopall = ShopAllItemDb1()
    agentIp = Utils.GetAgentIp()
    # agentIp = "127.0.0.1:8888"
    driver = PhantomDriver(1, agentIp, 60).return_driver()
    while (True):
        try:
            nid = None
            nid = queue.get(block=False)
        except:
            pass
        try:
            if nid:
                item = CrawlItem.crawl(driver, nid)
                if item:
                    shopall.insert_or_update_details(item)
                else:
                    #如果抓取失败就更换代理ip并重新放到队列中
                    agentIp = Utils.GetAgentIp()
                    try:
                        queue.put(nid, block=False)
                    except:
                        pass
                    print("进程%s抓取%s宝贝详情失败,重试 Ip:%s" % (i, nid, agentIp))
        except Exception, e:
            agentIp = Utils.GetAgentIp()
            driver.quit()
            driver = PhantomDriver(1, agentIp, 60).return_driver()
            try:
                queue.put(nid, block=False)
            except:
                pass
            print("进程%s抓取%s宝贝详情失败:%s,退出浏览器重试" % (i, nid, e.message))
            driver.quit()
コード例 #4
0
    def set_seed(cls, x=1, y=2, a=18000, b=30903, carry=0xffff):
        '''
        Set MWC1616 algorithm seed
        Set parameter if that is number
        '''

        is_number, value = Utils.is_number(x)
        if is_number:
            cls.__mwc1616_x = value

        is_number, value = Utils.is_number(y)
        if is_number:
            cls.__mwc1616_y = value

        is_number, value = Utils.is_number(a)
        if is_number:
            cls.__mwc1616_a = value

        is_number, value = Utils.is_number(b)
        if is_number:
            cls.__mwc1616_b = value

        is_number, value = Utils.is_number(carry)
        if is_number:
            cls.__mwc1616_carry = value
コード例 #5
0
class TestUtils(TestCase):
    def setUp(self):
        self.utils = Utils()

    def test_generateID(self):
        result = self.utils.generateID("Alice")
        self.assertTrue(
            result ==
            '3bc51062973c458d5a6f2d8d64a023246354ad7e064b1e4e009ec8a0699a3043')

    def test_writeRecipitent(self):
        recipitent = {
            "ip": "localhost",
            "port": "8000",
            "user": "******",
            "nodeid":
            "cd9fb1e148ccd8442e5aa74904cc73bf6fb54d1d54d333bd596aa9bb4bb4e961",
            "publickey": "-----BEGIN PUBLIC KEY-----\n"
        }
        self.utils.writeRecipitent(recipitent)
        my_file = Path("messagingPartner.json")
        if (my_file.is_file()):
            self.assertTrue(True)
        else:
            self.assertTrue(False)
コード例 #6
0
 def report(self):
     Logger.info(__file__, 'Start reporting')
     print('Start getting reporting data at {}'.format(
         datetime.datetime.now()))
     Utils.get_db_report_date()
     ConsoleReporter.report(StatisticsDataStorage.statistics)
     print('Reporter finished data at {}'.format(datetime.datetime.now()))
     Logger.info(__file__, 'Reporting finished')
コード例 #7
0
 def response_match_expected(response, expected):
     if expected == "NONE":
         return True
     elif (expected == "OPEN" and Utils.is_positive_result(response)) or \
          (expected == "CLOSE" and Utils.is_negative_result(response)):
         return True
     else:
         return False
コード例 #8
0
    def read_data_from_file(self, file_path):
        '''
        Read configurations from ini file with 'file_path' path and
        save it to configuration dictionary

        :param file_path: path to ini file with programm configurations
        '''

        Logger.add_to_journal(
            __file__, Level.INFO,
            'Start execution reading config file by path {}'.format(
                self.file_path))

        cfg_parser = configparser.ConfigParser(comment_prefixes=('#', ';'))
        try:
            cfg_parser.read(file_path)

            Logger.add_to_journal(
                __file__, Level.INFO,
                'Data from file {} loaded to configparser'.format(
                    self.file_path))

            Logger.add_to_journal(
                __file__, Level.INFO,
                'Start writing data to configuration object')

            for section in cfg_parser.sections():
                Logger.add_to_journal(
                    __file__, Level.DEBUG,
                    'Writing {} section to configuration object'.format(
                        section))

                for key in cfg_parser[section]:
                    is_n, n_value = Utils.is_bool(cfg_parser.get(section, key))
                    is_b, b_value = Utils.is_number(
                        cfg_parser.get(section, key))

                    if is_n:
                        self.configuration.settings[section][key] = n_value
                    elif is_b:
                        self.configuration.settings[section][key] = b_value
                    else:
                        self.configuration.settings[section][
                            key] = cfg_parser.get(section, key)

                    Logger.add_to_journal(
                        __file__, Level.DEBUG,
                        'Parameter {} set to value {}'.format(
                            key, cfg_parser.get(section, key)))

            Logger.add_to_journal(
                __file__, Level.INFO,
                'Writing data to configuration object  successfully finished')
        except:
            Logger.add_to_journal(
                __file__, Level.WARNING,
                'Writing data to configuration object  finished with exception. Some or full setting from file can be not setted to configuration object'
            )
コード例 #9
0
    def login(self):
        username = Utils.get_conf("serverconf", "username")
        password = Utils.get_conf("serverconf", "password")
        self.driver.close_notification()
        self.driver.input("UserName", username, locator=self.__username)
        self.driver.input("Password", password, locator=self.__password)
        self.driver.click("LoginButton", locator=self.__login_button)

        self.driver.wait_logo()
コード例 #10
0
 def __init__(self):
     # Define the config filepath
     self.config_filepath = '{}/.TradingMate/config/config.json'.format(
         Utils.get_home_path())
     os.makedirs(os.path.dirname(self.config_filepath), exist_ok=True)
     self.config = Utils.load_json_file(self.config_filepath)
     if self.config is None:
         logging.error("Please configure TradingMate: {}".format(
             self.config_filepath))
         raise RuntimeError("Empty configuration file")
     self.load_credentials()
     logging.info('ConfigurationManager initialised')
コード例 #11
0
ファイル: BasePage.py プロジェクト: dieson/PythonSelenium
    def login_neocu(self):
        username = Utils.get_conf("serverconf", "username")
        password = Utils.get_conf("serverconf", "password")
        self.close_notification()
        self.driver.input("UserName", username, locator="NAME:username")
        self.driver.input("Password", password, locator="NAME:password")
        self.driver.click(
            "LoginButton",
            locator="CSS:.ult-btn.ult-btn-primary.ult-btn-medium")

        self.wait_logo()
        self.driver.switch_window()
コード例 #12
0
 def save_settings(self, config):
     """
     Save the edited configuration settings
     """
     # Overwrite settings
     self.config = config
     self.load_credentials()
     # Remove credentials part
     del config['credentials']
     # Write into file
     Utils.write_json_file(self.config_filepath, config)
     logging.info('ConfigurationManater - settings have been saved')
コード例 #13
0
    def add_to_journal(cls, logger_file_path, level, message):
        if level.value not in logging._levelToName:
            level = LoggingLevel.NOTSET

        cls.__journal.append({
            cls.__LOGGER_NAME:
            Utils.get_file_name(Utils.get_file_name(logger_file_path)),
            cls.__LOGGING_LEVEL:
            level,
            cls.__LOGGING_MESSAGE:
            message,
        })
コード例 #14
0
ファイル: Driver.py プロジェクト: dieson/PythonSelenium
 def __init__(self):
     self.logger = LoggerUtils()
     self.wait_time = Utils.get_conf("script", "wait_time")
     self.url = Utils.get_conf("serverconf", "server_url")
     if "Win" in platform.system():
         self.chromedriver = os.path.join(Utils.get_project_path(),
                                          "Resources", "chromedriver.exe")
     else:
         self.chromedriver = os.path.join(Utils.get_project_path(),
                                          "Resources", "chromedriver")
     self.driver = webdriver.Chrome(self.chromedriver)
     self.driver.maximize_window()
     self.driver.get(self.url)
コード例 #15
0
ファイル: TestCasesRead.py プロジェクト: YiQingZi/MeiGeTest
 def __readTestCases(self):
     v = Python_version()
     if v > 3.0:
         with open('{0}/testcase.txt'.format(Utils.get_sys_path()),
                   mode='r',
                   encoding='utf-8') as f:
             testcase = f.read()
         return testcase
     else:
         with open('{0}/testcase.txt'.format(Utils.get_sys_path()),
                   mode='r') as f:
             testcase = f.read()
         return testcase
コード例 #16
0
 def save_doctors_from_sublist(doctors_list):
     for doctor in doctors_list[::2]:
         doc = doctor.split()
         index = doctors_list.index(doctor)
         academic_title = AcademicTitle.get(
             AcademicTitle.academic_title == Utils.handle_academic_title(doc[0].upper()))
         language = Language.get(Language.language == 'RUSSIAN')
         status = Status.get(Status.status == 'Chief')
         department = Department.get(Department.department_title == 'Oncology')
         Doctor.create(academic_title=academic_title, first_name=doc[1].upper(),
                       second_name=doc[2].upper(), birthday='', vacation='', image='', language=language,
                       info=Utils.remove_blank_lines(doctors_list[index + 1]), department=department, sub_department=None,
                       visible_tg='', status=status, first_tg='', link='')
コード例 #17
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_video_A_CallBack(self):
     global is_select_VIDEO_A
     if is_select_VIDEO_A % 2 == 0:
         is_select_VIDEO_A += 1
         Utils.config_write('VIDEO_A', True)
         log('info', 'VIDEO_A test is_select')
         self.text.insert("insert", '视频 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_VIDEO_A += 1
         Utils.config_write('VIDEO_A', False)
         log('info', 'VIDEO_A test not_is_select')
         self.text.insert("insert", '视频 测试未选择\n')
         self.text.see("insert")
コード例 #18
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_camera_CallBack(self):
     global is_select_camera
     if is_select_camera % 2 == 0:
         is_select_camera += 1
         Utils.config_write('CAMERA_A', True)
         log('info', 'camera  A test is_select')
         self.text.insert("insert", '相机 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_camera += 1
         Utils.config_write('CAMERA_A', False)
         log('info', 'camera  A test not_is_select')
         self.text.insert("insert", '相机 测试未选择\n')
         self.text.see("insert")
コード例 #19
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_gallery_CallBack(self):
     global is_select_gallery
     if is_select_gallery % 2 == 0:
         is_select_gallery += 1
         Utils.config_write('GALLERY_A', True)
         log('info', 'GALLERY A test is_select')
         self.text.insert("insert", '图库 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_gallery += 1
         Utils.config_write('GALLERY_A', False)
         log('info', 'GALLERY A test not_is_select')
         self.text.insert("insert", '图库 测试未选择\n')
         self.text.see("insert")
コード例 #20
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def select_a(self):
     global is_select_A
     if is_select_A % 2 == 0:
         is_select_A += 1
         Utils.config_write('A', True)
         log('info', 'level A test is_select')
         self.text.insert("insert", '优先级 A 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_A += 1
         Utils.config_write('A', False)
         log('info', 'level A  test not_is_select')
         self.text.insert("insert", '优先级 A 测试未选择\n')
         self.text.see("insert")
コード例 #21
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_SETTINGS_A_CallBack(self):
     global is_select_SETTINGS_A
     if is_select_SETTINGS_A % 2 == 0:
         is_select_SETTINGS_A += 1
         Utils.config_write('SETTINGS_A', True)
         log('info', 'SETTINGS_A test is_select')
         self.text.insert("insert", '设置 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_SETTINGS_A += 1
         Utils.config_write('SETTINGS_A', False)
         log('info', 'SETTINGS_A test not_is_select')
         self.text.insert("insert", '设置 测试未选择\n')
         self.text.see("insert")
コード例 #22
0
 def write_data(self, filepath=None):
     """
     Write the trade history to the database
     """
     path = filepath.replace('{home}', Utils.get_home_path()) if filepath is not None else self.db_filepath
     logging.info('DatabaseHandler - writing data to {}'.format(path))
     # Create a json object and store the trade history into it
     json_obj = {
         'trades': []
     }
     for t in self.trading_history:
         json_obj['trades'].append(t.to_dict())
     # Write to file
     return Utils.write_json_file(path, json_obj)
コード例 #23
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_Music_A_CallBack(self):
     global is_select_Music_A
     if is_select_Music_A % 2 == 0:
         is_select_Music_A += 1
         Utils.config_write('MUSIC_A', True)
         log('info', 'MUSIC_A test is_select')
         self.text.insert("insert", '音乐 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_Music_A += 1
         Utils.config_write('MUSIC_A', False)
         log('info', 'MUSIC_A test not_is_select')
         self.text.insert("insert", '音乐 测试未选择\n')
         self.text.see("insert")
コード例 #24
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def select_d(self):
     global is_select_D
     if is_select_D % 2 == 0:
         is_select_D += 1
         Utils.config_write('D', True)
         log('info', 'level D test is_select')
         self.text.insert("insert", '优先级 D 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_D += 1
         Utils.config_write('D', False)
         log('info', 'level D not_is_select')
         self.text.insert("insert", '优先级 D 测试未选择\n')
         self.text.see("insert")
コード例 #25
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def select_c(self):
     global is_select_C
     if is_select_C % 2 == 0:
         is_select_C += 1
         Utils.config_write('C', True)
         log('info', 'level C test is_select')
         self.text.insert("insert", '优先级 C 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_C += 1
         Utils.config_write('C', False)
         log('info', 'level C not_is_select')
         self.text.insert("insert", '优先级 C 测试未选择\n')
         self.text.see("insert")
コード例 #26
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def select_b(self):
     global is_select_B
     if is_select_B % 2 == 0:
         is_select_B += 1
         Utils.config_write('B', True)
         log('info', 'level B test is_select')
         self.text.insert("insert", '优先级 B 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_B += 1
         Utils.config_write('B', False)
         log('info', 'level B  test not_is_select')
         self.text.insert("insert", '优先级 B 测试未选择\n')
         self.text.see("insert")
コード例 #27
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_FileManager_A_CallBack(self):
     global is_select_FileManager_A
     if is_select_FileManager_A % 2 == 0:
         is_select_FileManager_A += 1
         Utils.config_write('FileManager_A', True)
         log('info', 'FileManager_A test is_select')
         self.text.insert("insert", '文件管理器 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_FileManager_A += 1
         Utils.config_write('FileManager_A', False)
         log('info', 'FileManager_A test not_is_select')
         self.text.insert("insert", '文件管理器 测试未选择\n')
         self.text.see("insert")
コード例 #28
0
ファイル: main.py プロジェクト: YiQingZi/MeigUiTest
 def cv_MESSAGING_CallBack(self):
     global is_select_MESSAGING
     if is_select_MESSAGING % 2 == 0:
         is_select_MESSAGING += 1
         Utils.config_write('MESSAGING', True)
         log('info', 'MESSAGING test is_select')
         self.text.insert("insert", '短信 测试已选择\n')
         self.text.see("insert")
     else:
         is_select_MESSAGING += 1
         Utils.config_write('MESSAGING', False)
         log('info', 'MESSAGING test not_is_select')
         self.text.insert("insert", '短息 测试未选择\n')
         self.text.see("insert")
コード例 #29
0
def ExceptionApi(code, e):
    """
    接口异常处理
    :param code:
    :param e:
    :return:
    """
    exc_type, exc_value, exc_traceback = sys.exc_info()
    if DEBUG_LOG:
        # 文件形式
        if SAVE_LOG == 1:
            log().exception(e)
        # 数据库形式
        elif SAVE_LOG == 2:
            # 日志服务
            LogService().add(e, 1, 3)
    body = {}
    body['error_code'] = code
    body['error'] = True
    body['show'] = False
    body['debug_id'] = Utils.unique_id()
    dbSession.close()
    body['trackback'] = traceback.format_exception(exc_type, exc_value,
                                                   exc_traceback)
    return make_response(jsonify(body))
コード例 #30
0
def Find_newest_log():
    if not os.path.exists(f'{Utils.get_sys_path()}\Log'):
        os.mkdir(f'{Utils.get_sys_path()}\Log')
    if not os.path.exists(f'{Utils.get_sys_path()}\Logcat'):
        os.mkdir(f'{Utils.get_sys_path()}\Logcat')
    dir = r'{0}\Log'.format(Utils.get_sys_path())
    lists = os.listdir(dir)
    if len(lists) == 0:
        p = r'{0}\Log\RunTestLog-{1}.log'.format(Utils.get_sys_path(),
                                                 TimeUtils.strTimeName())
        with open(p, mode='w+') as f:
            f.write(p)
        return p
    lists.sort(key=lambda fn: os.path.getmtime(dir + "\\" + fn))  # 按时间排序
    file_new = os.path.join(dir, lists[-1])
    return file_new