def find_repo_candidate(voinfo, vofiles=None):
    '''Find repository URL for the given plugin

    Iterates for all candidates returned by _find_repo_candidates and returns first candidate with 
    best score found.'''
    global _checked_URLs
    candidates = sorted(_find_repo_candidates(voinfo),
                        key=lambda o: o.key,
                        reverse=True)
    best_candidate = None
    already_checked = set()
    for candidate in candidates:
        if vofiles is None:
            vofiles = get_file_list(voinfo)
            vofiles = {fname for fname in vofiles if not fname.endswith('/')}
            logger.info('>> vim.org files: ' + repr(vofiles))
        url = candidate.url
        if url in already_checked:
            logger.debug(
                '>>> Omitting {0} because it was already checked'.format(url))
            continue
        already_checked.add(url)
        logger.info('>> Checking candidate {0} with key {1}: {2}'.format(
            candidate.__class__.__name__, candidate.key,
            candidate.match.group(0)))
        try:
            files = get_scm_file_list(candidate)
            logger.info('>>> Repository files: {0!r}'.format(files))
            prefix, score = compare_file_lists(candidate, vofiles, files)
        except NotLoggedError:
            pass
        except Exception as e:
            logger.exception(e)
        else:
            candidate.prefix = prefix
            if score == 100:
                logger.info('>> Found candidate {0}: {1} (100)'.format(
                    candidate.__class__.__name__, candidate.match.group(0)))
                return candidate
            elif score and (not best_candidate
                            or score > best_candidate.score):
                best_candidate = candidate
                best_candidate.score = score
    if best_candidate:
        logger.info('Found candidate {0}: {1} ({2})'.format(
            best_candidate.__class__.__name__, best_candidate.match.group(0),
            best_candidate.score))
    return best_candidate
def find_repo_candidate(voinfo, vofiles=None):
    '''Find repository URL for the given plugin

    Iterates for all candidates returned by _find_repo_candidates and returns first candidate with 
    best score found.'''
    global _checked_URLs
    candidates = sorted(_find_repo_candidates(voinfo), key=lambda o: o.key, reverse=True)
    best_candidate = None
    already_checked = set()
    for candidate in candidates:
        if vofiles is None:
            vofiles = get_file_list(voinfo)
            vofiles = {fname for fname in vofiles if not fname.endswith('/')}
            logger.info('>> vim.org files: ' + repr(vofiles))
        url = candidate.url
        if url in already_checked:
            logger.debug('>>> Omitting {0} because it was already checked'.format(url))
            continue
        already_checked.add(url)
        logger.info('>> Checking candidate {0} with key {1}: {2}'.format(
            candidate.__class__.__name__,
            candidate.key,
            candidate.match.group(0)
        ))
        try:
            files = get_scm_file_list(candidate)
            logger.info('>>> Repository files: {0!r}'.format(files))
            prefix, score = compare_file_lists(candidate, vofiles, files)
        except NotLoggedError:
            pass
        except Exception as e:
            logger.exception(e)
        else:
            candidate.prefix = prefix
            if score == 100:
                logger.info('>> Found candidate {0}: {1} (100)'.format(candidate.__class__.__name__,
                                                                    candidate.match.group(0)))
                return candidate
            elif score and (not best_candidate or score > best_candidate.score):
                best_candidate = candidate
                best_candidate.score = score
    if best_candidate:
        logger.info('Found candidate {0}: {1} ({2})'.format(
                                                best_candidate.__class__.__name__,
                                                best_candidate.match.group(0),
                                                best_candidate.score))
    return best_candidate
Esempio n. 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))