Пример #1
0
def process_voinfo(scm_generated,
                   found,
                   not_found,
                   description_hashes,
                   key,
                   voinfo,
                   recheck=False):
    '''Process given plugin

    If ``recheck`` is ``True`` then it only prints to stderr whether something changed.

    If ``recheck`` is ``False`` then it records found URL in scm_generated and puts corresponding 
    plugin number into ``found``. If no URL was found it records plugin number into ``not_found``.
    '''
    logger.info(
        '> Checking plugin {script_name} (vimscript #{script_id})'.format(
            **voinfo))
    try:
        candidate = find_repo_candidate(voinfo)
        if recheck:
            desc = '%s : %s' % (voinfo['script_id'], voinfo['script_name'])
            if candidate:
                c_sg = candidate_to_sg(candidate)
                s_sg = scm_generated[voinfo['script_id']]
                if c_sg == s_sg:
                    print('== ' + desc)
                else:
                    logger.info('> {0!r} (new) /= {1!r} (old)'.format(
                        c_sg, s_sg))
                    print('/= ' + desc)
            else:
                print('no ' + desc)
        else:
            if candidate:
                scm_generated[key] = candidate_to_sg(candidate)
                logger.info('> Recording found candidate for {0}: {1}'.format(
                    key, scm_generated[key]))
                not_found.discard(key)
            else:
                logger.info(
                    '> Recording failure to find candidates for {0}'.format(
                        key))
                not_found.add(key)
            found.add(key)
            if not args['--no-descriptions']:
                description_hashes[key] = get_voinfo_hash(voinfo)
    except Exception as e:
        logger.exception(e)
def process_voinfo(scm_generated, found, not_found, description_hashes, key, voinfo, recheck=False):
    '''Process given plugin

    If ``recheck`` is ``True`` then it only prints to stderr whether something changed.

    If ``recheck`` is ``False`` then it records found URL in scm_generated and puts corresponding 
    plugin number into ``found``. If no URL was found it records plugin number into ``not_found``.
    '''
    logger.info('> Checking plugin {script_name} (vimscript #{script_id})'
                .format(**voinfo))
    try:
        candidate = find_repo_candidate(voinfo)
        if recheck:
            desc = '%s : %s' % (voinfo['script_id'], voinfo['script_name'])
            if candidate:
                c_sg = candidate_to_sg(candidate)
                s_sg = scm_generated[voinfo['script_id']]
                if c_sg == s_sg:
                    print ('== ' + desc)
                else:
                    logger.info('> {0!r} (new) /= {1!r} (old)'.format(c_sg, s_sg))
                    print ('/= ' + desc)
            else:
                print ('no ' + desc)
        else:
            if candidate:
                scm_generated[key] = candidate_to_sg(candidate)
                logger.info('> Recording found candidate for {0}: {1}'
                            .format(key, scm_generated[key]))
                not_found.discard(key)
            else:
                logger.info('> Recording failure to find candidates for {0}'.format(key))
                not_found.add(key)
            found.add(key)
            if not args['--no-descriptions']:
                description_hashes[key] = get_voinfo_hash(voinfo)
    except Exception as e:
        logger.exception(e)
Пример #3
0
def annotate_scmsources():
    url_regex = re.compile('^(.*)$')
    line_regex_strict = re.compile(
        r"^let\s+scmnr\.(\d+)\s*=\s*\{'type':\s*'(\w+)',\s*'url':\s*'([^']+)'\s*\}\s*"
    )
    line_snr_regex = re.compile(r'(\d+)')
    line_url_regex = re.compile(r"'url': '([^']+)'")
    line_scm_regex = re.compile(r"'type': '([^']+)'")
    prnt(
        '┌ X if line contains information besides repository URL and SCM used')
    prnt('│┌ ? or ! if line failes to be parsed by regular expressions')
    prnt('││┌ A if scm type is unknown')
    prnt('│││┌ F if match failes')
    prnt(
        '││││┌ O if match deduced from the description is different, M if there are no'
    )
    prnt(
        '│││││┌ E if exception occurred, C if printing candidate on this line')
    prnt(
        '┴┴┴┴┴┴┬─────────────────────────────────────────────────────────────────────────'
    )
    with lshg.MercurialRemoteParser() as remote_parser:
        set_remote_parser(remote_parser)
        for line in process_scmsources(False):
            try:
                numcolumns = 5
                best_candidate = None
                line = line.decode('utf-8')
                logger.info('Checking line ' + line)
                match = line_regex_strict.match(line)
                if match:
                    write('  ')
                    numcolumns -= 2
                    snr, scm, url = match.groups()
                else:
                    write('X')
                    numcolumns -= 1
                    if args['--no-extra-check']:
                        raise NotLoggedError
                    snr = line_snr_regex.search(line)
                    scm = line_scm_regex.search(line)
                    url = line_url_regex.search(line)
                    if snr:
                        snr = snr.group(1)
                    if scm:
                        scm = scm.group(1)
                    if url:
                        url = url.group(1)
                    if not snr:
                        write('!')
                        numcolumns -= 1
                        raise ValueError('snr key not found')
                    if not scm:
                        write('?A')
                        numcolumns -= 2
                        url = None
                    elif not url:
                        write('?-')
                        numcolumns -= 2
                        scm = None
                    else:
                        write(' ')
                        numcolumns -= 1
                if scm not in scm_matches:
                    write('A')
                    numcolumns -= 1
                    url = None
                    scm = None
                else:
                    write(' ')
                    numcolumns -= 1

                voinfo = db[snr]
                vofiles = set(get_file_list(voinfo))
                if url:
                    match = url_regex.match(url)
                    candidate = scm_matches[scm](match, voinfo)
                    files = get_scm_file_list(candidate)
                    prefix, key2 = compare_file_lists(candidate, vofiles,
                                                      files)
                    write(' ' if key2 else 'F')
                    numcolumns -= 1
                else:
                    write('-')
                    numcolumns -= 1

                best_candidate = find_repo_candidate(voinfo, vofiles)
                if not best_candidate:
                    write('M')
                    numcolumns -= 1
                elif not (url and best_candidate.scm_url == url
                          and best_candidate.scm == scm):
                    write('O')
                    numcolumns -= 1
                else:
                    write(' ')
                    numcolumns -= 1
                    best_candidate = None
                write(' ')
                numcolumns -= 1
            except Exception as e:
                if not isinstance(e, NotLoggedError):
                    logger.exception(e)
                write(('-' * numcolumns) + 'E')
            finally:
                # XXX line ends with \n, thus not writing `+ '\n'` here.
                write('│' + line)
                if best_candidate and args['--print-other-candidate']:
                    write(
                        "-----C│let scmnr.%-4u = {'type': '%s', 'url': '%s'}\n"
                        %
                        (int(snr), best_candidate.scm, best_candidate.scm_url))
def annotate_scmsources():
    url_regex = re.compile('^(.*)$')
    line_regex_strict = re.compile(r"^let\s+scmnr\.(\d+)\s*=\s*\{'type':\s*'(\w+)',\s*'url':\s*'([^']+)'\s*\}\s*")
    line_snr_regex = re.compile(r'(\d+)')
    line_url_regex = re.compile(r"'url': '([^']+)'")
    line_scm_regex = re.compile(r"'type': '([^']+)'")
    prnt ('┌ X if line contains information besides repository URL and SCM used')
    prnt ('│┌ ? or ! if line failes to be parsed by regular expressions')
    prnt ('││┌ A if scm type is unknown')
    prnt ('│││┌ F if match failes')
    prnt ('││││┌ O if match deduced from the description is different, M if there are no')
    prnt ('│││││┌ E if exception occurred, C if printing candidate on this line')
    prnt ('┴┴┴┴┴┴┬─────────────────────────────────────────────────────────────────────────')
    with lshg.MercurialRemoteParser() as remote_parser:
        set_remote_parser(remote_parser)
        for line in process_scmsources(False):
            try:
                numcolumns = 5
                best_candidate = None
                line = line.decode('utf-8')
                logger.info('Checking line ' + line)
                match = line_regex_strict.match(line)
                if match:
                    write('  ')
                    numcolumns -= 2
                    snr, scm, url = match.groups()
                else:
                    write('X')
                    numcolumns -= 1
                    if args['--no-extra-check']:
                        raise NotLoggedError
                    snr = line_snr_regex.search(line)
                    scm = line_scm_regex.search(line)
                    url = line_url_regex.search(line)
                    if snr:
                        snr = snr.group(1)
                    if scm:
                        scm = scm.group(1)
                    if url:
                        url = url.group(1)
                    if not snr:
                        write('!')
                        numcolumns -= 1
                        raise ValueError('snr key not found')
                    if not scm:
                        write('?A')
                        numcolumns -= 2
                        url = None
                    elif not url:
                        write('?-')
                        numcolumns -= 2
                        scm = None
                    else:
                        write(' ')
                        numcolumns -= 1
                if scm not in scm_matches:
                    write('A')
                    numcolumns -= 1
                    url = None
                    scm = None
                else:
                    write(' ')
                    numcolumns -= 1

                voinfo = db[snr]
                vofiles = set(get_file_list(voinfo))
                if url:
                    match = url_regex.match(url)
                    candidate = scm_matches[scm](match, voinfo)
                    files = get_scm_file_list(candidate)
                    prefix, key2 = compare_file_lists(candidate, vofiles, files)
                    write(' ' if key2 else 'F')
                    numcolumns -= 1
                else:
                    write('-')
                    numcolumns -= 1

                best_candidate = find_repo_candidate(voinfo, vofiles)
                if not best_candidate:
                    write('M')
                    numcolumns -= 1
                elif not (url and best_candidate.scm_url == url and best_candidate.scm == scm):
                    write('O')
                    numcolumns -= 1
                else:
                    write(' ')
                    numcolumns -= 1
                    best_candidate = None
                write(' ')
                numcolumns -= 1
            except Exception as e:
                if not isinstance(e, NotLoggedError):
                    logger.exception(e)
                write(('-' * numcolumns) + 'E')
            finally:
                # XXX line ends with \n, thus not writing `+ '\n'` here.
                write('│' + line)
                if best_candidate and args['--print-other-candidate']:
                    write("-----C│let scmnr.%-4u = {'type': '%s', 'url': '%s'}\n"
                            % (int(snr), best_candidate.scm, best_candidate.scm_url))