Esempio n. 1
0
def static_hash_map_test():
    logger.warning('static_hash_map_test start!')
    django = search('django')
    distri = file_distribute(django)
    logger.info('file_distribute end.')
    target_website = 'http://127.0.0.1:8000/'
    map_ = static_hash_map(target_website, distri, depth=0)
    logger.info(json.dumps(map_, indent=4, sort_keys=True))
    logger.info('static_hash_map_test pass!')
Esempio n. 2
0
def make_version_test():
    logger.warning('make_version_test start!')
    import ext.err_hunter as err_hunter
    from test_data import target_tmp_hash_map3 as target_tmp_hash_map
    from observer.version import make_version
    django = search('django')
    logger.critical(
        'make_version return: %s',
        make_version(target_tmp_hash_map, django.get('fingerprint')))
    logger.critical(
        'make_version return: %s',
        make_version(target_tmp_hash_map, django.get('reverse_fingerprint'),
                     False))
    logger.info('make_version_test pass!')
Esempio n. 3
0
    def reverse_diff(self):
        """Comparison between versions one by one from old to new."""
        # version_lst in here must start from min version in fingerprint
        fingerprint_versions = self.info_result.get('fingerprint').keys()
        min_version = min(
            sorted((str2version(vstr) for vstr in fingerprint_versions)))
        version_lst = self.version_lst
        version_lst.reverse()
        logger.warning(version_lst)
        version_lst = version_lst[version_lst.index(min_version):]

        start_version = version_lst[1]
        logger.verbose('the first version with static file is %s',
                       start_version.vstring)
        logger.verbose('reverse version list %s', version_lst)
        logger.verbose('git checkout to %s', start_version.vstring)
        self._git_exec('checkout', start_version.vstring)
        self.last_hash(version_lst[1:], 'reverse_fingerprint')
        self.make_diff(version_lst[1:], 'reverse_fingerprint')
        logger.verbose('git checkout to HEAD')
        self._git_exec('checkout', '-')
Esempio n. 4
0
 def _check(version_compare_lst):
     compare_lst = ['>']
     # avoid [>= 1.1, <= 1.0]
     for compare, _ in version_compare_lst:
         compare = compare.strip('=')
         if compare != compare_lst[-1]:
             compare_lst.append(compare)
     length = len(compare_lst)
     if version_compare_lst and 0 < length < 3:
         return True
     logger.warning('maybe framework or cms had be change by developer')
     if len(version_compare_lst) < 1:
         logger.warning(
             'Reducing depth(--depth), set smaller number maybe useful')
         logger.error('unable to judge version')
         sys.exit()
     elif length > 2:
         logger.warning(
             'Enlarge depth(--depth), set larger number or max(0) maybe useful'
         )
         lst = [('version cond', )]
         for comb, ver in version_compare_lst:
             lst.append(('{} {}'.format(comb, ver), ))
         show_output(AsciiTable(lst).table)
         sys.exit()
Esempio n. 5
0
def call_multi_process(function, args_lst, timeout=float('inf')):
    """
    use multiprocessing to call the function like pool.map.

    :param function: function to call.
    :param function: iterable object contains args.
    """
    process_pool = init_process_pool()
    results = {}
    childs = []
    start_time = time.time()

    for args in args_lst:

        def _callback(result, args_=args):
            results[args_] = result

        if not isinstance(args, (list, tuple, collections.Generator)):
            args = (args, )
        childs.append(
            process_pool.apply_async(function, args, callback=_callback))

    try:
        while True:
            time.sleep(0.5)
            now = time.time()
            if (now - start_time) > timeout:
                raise ProcessTimeoutError(
                    "main process time cost: {}".format(now))
            if all((child.ready() for child in childs)):
                break
    except (KeyboardInterrupt, ProcessTimeoutError) as ex:
        logger.warning("stopping by user interrupt. exception info: %s", ex)
        process_pool.terminate()
        process_pool.join()
    else:
        process_pool.close()
        process_pool.join()
    return results
Esempio n. 6
0
def mdf_of_file_and_byte_content_test():
    logger.warning('mdf_of_file_and_byte_content_test start!')
    filepath = './observer.py'
    fbyte = open(filepath, 'rb').read()
    assert (file_md5(filepath) == byte_md5(fbyte)) is True
    logger.info('mdf_of_file_and_byte_content_test pass!')