Exemplo n.º 1
0
    def search_all_ip_address(self):
        def map_ip_file(ipls, filels):
            ipls.sort()
            map_list = list()
            for sip in ipls:
                # Combine all same ip key
                map_list.append({
                    sip:
                    list(
                        set([
                            item[sip] for item in filels if sip in item.keys()
                        ]))
                })
            return map_list

        logger.info("Searching all ip address mapping...")
        ip_list = list()
        ip_file = list()
        file_size = len(self.file_list)
        for index, file in enumerate(self.file_list):
            show_progress(index, file_size)
            try:
                with open(file, "rt") as fr:
                    # Do not use readlines() since here might more than 2 ips in one line, and re.search() only
                    # returns the first match.
                    content = fr.read().split()
                    for entry in content:
                        ip = re.search(REGEX_IP, entry)
                        if ip is not None:
                            logger.debug("Get IP: %s in file: %s" %
                                         (ip.group(), file))
                            ip_list.append(ip.group())
                            ip_file.append({ip.group(): file})
            except (IOError, UnicodeDecodeError) as err:
                logger.warning("Ignore error: %s in file: %s" % (err, file))
                continue
        self.all_ip_map = map_ip_file(list(set(ip_list)), ip_file)
        return self.all_ip_map
Exemplo n.º 2
0
def show_end_info(key, path, branch, replace):
    logger.info(
        "============================================= Task End =============================================="
    )
    logger.info("Keyword: %s, Path: %s, Branch: %s, Replace: %s" %
                (key, path, branch, replace))
    logger.info(
        "====================================================================================================="
    )
Exemplo n.º 3
0
def show_title_info(key, path, branch, replace):
    logger.info(
        "============================================ Task Begin ============================================="
    )
    logger.info("Keyword: %s, Path: %s, Branch: %s, Replace: %s" %
                (key, path, branch, replace))
    logger.info(
        "====================================================================================================="
    )
Exemplo n.º 4
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        """
        Exit function will process error messages

        :param exc_type: error trace type
        :param exc_val: error trace value
        :param exc_tb: error trace traceback
        :return: True, it will continue to the next component, type: bool
        """
        logger.info("Processing error message...")
        # Print job errors after "with xx as xx:" part
        if any([exc_type, exc_val, exc_tb]):
            traceback.print_exception(exc_type, exc_val, exc_tb)
            logger.info(traceback.extract_tb(exc_tb))
        else:
            logger.info("None")
        # Based on your requirements to set True or remove return
        return True
Exemplo n.º 5
0
 def read_result_data(self):
     logger.info("Reading search result file data...")
     with open(self.result_file, "rt") as fr:
         self.result_data = json.loads(fr.read())
         fr.close()
Exemplo n.º 6
0
def perform_replace(path, keyword):
    logger.info("Performing replace user data...")
    with walk_replace.WalkReplaceWorkflow(path, keyword) as walk_rep:
        walk_rep.update_walk_replace()
Exemplo n.º 7
0
def perform_walk_keyword(path, keyword):
    logger.info("Performing walk keyword...")
    with walk_keyword.WalkKeyWorkflow(path, keyword) as walk_key:
        walk_key.save_walk_data()
Exemplo n.º 8
0
def perform_checkout_branch(branch):
    logger.info("Performing checkout branch...")
    if os.system("git checkout {}".format(branch)):
        logger.error("Checkout branch failed, please check branch name!")
        raise RuntimeError("Checkout branch failed, please check branch name!")