예제 #1
0
def get_repos_in_rosinstall_format(root):
    repos = {}
    for i, item in enumerate(root):
        if len(item.keys()) != 1:
            raise RuntimeError('Input data is not valid format')
        repo = {'type': list(item.keys())[0]}
        attributes = list(item.values())[0]
        try:
            path = attributes['local-name']
        except AttributeError as e:
            print(
                ansi('yellowf') + (
                    'Repository #%d does not provide the necessary '
                    'information: %s' % (i, e)) + ansi('reset'),
                file=sys.stderr)
            continue
        try:
            repo['url'] = attributes['uri']
            if 'version' in attributes:
                repo['version'] = attributes['version']
        except AttributeError as e:
            print(
                ansi('yellowf') + (
                    "Repository '%s' does not provide the necessary "
                    'information: %s' % (path, e)) + ansi('reset'),
                file=sys.stderr)
            continue
        repos[path] = repo
    return repos
예제 #2
0
def get_repos_in_rosinstall_format(root):
    repos = {}
    for i, item in enumerate(root):
        if len(item.keys()) != 1:
            raise RuntimeError("Input data is not valid format")
        repo = {"type": list(item.keys())[0]}
        attributes = list(item.values())[0]
        try:
            path = attributes["local-name"]
        except AttributeError as e:
            print(
                ansi("yellowf")
                + ("Repository #%d does not provide the necessary information: %s" % (i, e))
                + ansi("reset"),
                file=sys.stderr,
            )
            continue
        try:
            repo["url"] = attributes["uri"]
            if "version" in attributes:
                repo["version"] = attributes["version"]
        except AttributeError as e:
            print(
                ansi("yellowf")
                + ("Repository '%s' does not provide the necessary information: %s" % (path, e))
                + ansi("reset"),
                file=sys.stderr,
            )
            continue
        repos[path] = repo
    return repos
예제 #3
0
def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    parser = get_parser()
    add_common_arguments(
        parser, skip_hide_empty=True, skip_nested=True, single_path=True,
        path_help='Base path to clone repositories to')
    args = parser.parse_args(args)
    try:
        repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)
    add_dependencies(jobs)

    if args.repos:
        output_repositories([job['client'] for job in jobs])

    results = execute_jobs(
        jobs, show_progress=True, number_of_workers=args.workers,
        debug_jobs=args.debug)
    output_results(results)

    any_error = any(r['returncode'] for r in results)
    return 1 if any_error else 0
예제 #4
0
def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    parser = get_parser()
    add_common_arguments(parser,
                         skip_hide_empty=True,
                         skip_nested=True,
                         path_nargs='?',
                         path_help='Base path to clone repositories to')
    args = parser.parse_args(args)
    try:
        repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)
    add_dependencies(jobs)

    if args.repos:
        output_repositories([job['client'] for job in jobs])

    results = execute_jobs(jobs,
                           show_progress=True,
                           number_of_workers=args.workers,
                           debug_jobs=args.debug)
    output_results(results)

    any_error = any(r['returncode'] for r in results)
    return 1 if any_error else 0
예제 #5
0
def get_repos_in_rosinstall_format(root):
    repos = {}
    for i, item in enumerate(root):
        if len(item.keys()) != 1:
            raise RuntimeError('Input data is not valid format')
        repo = {'type': list(item.keys())[0]}
        attributes = list(item.values())[0]
        try:
            path = attributes['local-name']
        except AttributeError as e:
            print(
                ansi('yellowf') + (
                    'Repository #%d does not provide the necessary '
                    'information: %s' % (i, e)) + ansi('reset'),
                file=sys.stderr)
            continue
        try:
            repo['url'] = attributes['uri']
            if 'version' in attributes:
                repo['version'] = attributes['version']
        except AttributeError as e:
            print(
                ansi('yellowf') + (
                    "Repository '%s' does not provide the necessary "
                    'information: %s' % (path, e)) + ansi('reset'),
                file=sys.stderr)
            continue
        repos[path] = repo
    return repos
예제 #6
0
파일: export.py 프로젝트: sloretz/vcstool
def output_error_information(result, hide_empty=False):
    # successful results are handled by a separate function
    if not result['returncode']:
        return

    if result['returncode'] == NotImplemented:
        color = 'yellow'
    else:
        color = 'red'

    line = '%s: %s' % (result['path'], result['output'])
    print(ansi('%sf' % color) + line + ansi('reset'), file=sys.stderr)
예제 #7
0
def output_error_information(result, hide_empty=False):
    # successful results are handled by a separate function
    if not result['returncode']:
        return

    if result['returncode'] == NotImplemented:
        color = 'yellow'
    else:
        color = 'red'

    path = get_path_of_result(result)
    line = '%s: %s' % (path, result['output'])
    print(ansi('%sf' % color) + line + ansi('reset'), file=sys.stderr)
예제 #8
0
def main(args=None):
    parser = get_parser()
    add_common_arguments(parser, skip_hide_empty=True, single_path=True, path_help='Base path to clone repositories to')
    args = parser.parse_args(args)
    try:
        repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)

    if args.repos:
        output_repositories([job['client'] for job in jobs])

    results = execute_jobs(jobs, show_progress=True)
    output_results(results)
    return 0
예제 #9
0
def get_repos_in_vcstool_format(repositories):
    repos = {}
    for path in repositories:
        repo = {}
        attributes = repositories[path]
        try:
            repo['type'] = attributes['type']
            repo['url'] = attributes['url']
            if 'version' in attributes:
                repo['version'] = attributes['version']
        except AttributeError as e:
            print(ansi('yellowf') +
                  ("Repository '%s' does not provide the necessary "
                   'information: %s' % (path, e)) + ansi('reset'),
                  file=sys.stderr)
            continue
        repos[path] = repo
    return repos
예제 #10
0
def main(args=None):
    parser = get_parser()
    add_common_arguments(parser, skip_hide_empty=True, single_path=True, path_help="Base path to clone repositories to")
    args = parser.parse_args(args)
    try:
        repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi("redf") + str(e) + ansi("reset"), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)

    if args.repos:
        output_repositories([job["client"] for job in jobs])

    results = execute_jobs(jobs, show_progress=True, number_of_workers=args.workers, debug_jobs=args.debug)
    output_results(results)

    any_error = any([r["returncode"] != 0 for r in results])
    return 1 if any_error else 0
예제 #11
0
파일: import_.py 프로젝트: codebot/vcstool
def main(args=None):
    parser = get_parser()
    add_common_arguments(parser, skip_hide_empty=True, single_path=True, path_help='Base path to clone repositories to')
    args = parser.parse_args(args)
    try:
        repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)

    if args.repos:
        output_repositories([job['client'] for job in jobs])

    results = execute_jobs(jobs, show_progress=True)
    output_results(results)

    any_error = any([r['returncode'] != 0 for r in results])
    return 1 if any_error else 0
예제 #12
0
def get_repos_in_vcstool_format(repositories):
    repos = {}
    for path in repositories:
        repo = {}
        attributes = repositories[path]
        try:
            repo["type"] = attributes["type"]
            repo["url"] = attributes["url"]
            if "version" in attributes:
                repo["version"] = attributes["version"]
        except AttributeError as e:
            print(
                ansi("yellowf")
                + ("Repository '%s' does not provide the necessary information: %s" % (path, e))
                + ansi("reset"),
                file=sys.stderr,
            )
            continue
        repos[path] = repo
    return repos
예제 #13
0
def output_export_data(result, hide_empty=False):
    # errors are handled by a separate function
    if result['returncode']:
        return

    try:
        lines = []
        lines.append('  %s:' % result['path'])
        lines.append('    type: ' + result['client'].__class__.type)
        export_data = result['export_data']
        lines.append('    url: ' + export_data['url'])
        if 'version' in export_data and export_data['version']:
            lines.append('    version: ' + export_data['version'])
        print('\n'.join(lines))
    except KeyError as e:
        print(ansi('redf') +
              ("Command '%s' failed for path '%s': %s: %s" %
               (result['command'].__class__.command, result['client'].path,
                e.__class__.__name__, e)) + ansi('reset'),
              file=sys.stderr)
예제 #14
0
def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    parser = get_parser()
    add_common_arguments(parser, skip_nested=True, path_nargs=False)
    parser.add_argument('--packages_txt_file', type=argparse.FileType('r'))
    args = parser.parse_args()

    pkg_name_list = args.packages_txt_file.read().split('\n')

    try:
        ros2_repos = get_repositories(args.input)
    except RuntimeError as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1

    vcs_format_repo_list = {}
    for repo_name in get_proposed_packages_repo_names(pkg_name_list):
        vcs_format_repo_list[repo_name] = ros2_repos[repo_name]

    print(yaml.dump(vcs_format_repo_list))
예제 #15
0
def output_export_data(result, hide_empty=False):
    client = result['client']
    path = os.path.relpath(client.path, result['command'].paths[0])
    if path == '.':
        path = os.path.basename(os.path.abspath(client.path))

    try:
        if result['returncode'] == NotImplemented:
            print(ansi('yellowf') + result['output'] + ansi('reset'),
                  file=sys.stderr)
        elif result['returncode']:
            print(ansi('redf') + result['output'] + ansi('reset'),
                  file=sys.stderr)
        else:
            lines = []
            lines.append('  %s:' % path)
            lines.append('    type: %s' % client.__class__.type)
            export_data = result['export_data']
            lines.append('    url: %s' % export_data['url'])
            if 'version' in export_data and export_data['version']:
                lines.append('    version: %s' % export_data['version'])
            print('\n'.join(lines))
    except KeyError as e:
        print(ansi('redf') +
              ("Command '%s' failed for path '%s': %s" %
               (result['command'].__class__.command, client.path, e)) +
              ansi('reset'),
              file=sys.stderr)
예제 #16
0
파일: export.py 프로젝트: ablasdel/vcstool
def output_export_data(result):
    client = result['client']
    path = os.path.relpath(client.path, result['command'].paths[0])
    if path == '.':
        path = os.path.basename(os.path.abspath(client.path))

    try:
        if result['returncode'] == NotImplemented:
            print(ansi('yellowf') + result['output'] + ansi('reset'), file=sys.stderr)
        elif result['returncode']:
            print(ansi('redf') + result['output'] + ansi('reset'), file=sys.stderr)
        else:
            lines = []
            lines.append('  %s:' % path)
            lines.append('    type: %s' % client.__class__.type)
            export_data = result['export_data']
            lines.append('    url: %s' % export_data['url'])
            if 'version' in export_data and export_data['version']:
                lines.append('    version: %s' % export_data['version'])
            print('\n'.join(lines))
    except KeyError as e:
        print(ansi('redf') + ("Command '%s' failed for path '%s': %s" % (result['command'].__class__.command, client.path, e)) + ansi('reset'), file=sys.stderr)
예제 #17
0
파일: import_.py 프로젝트: dotjairo/vcstool
def get_repos_in_vcstool_format(repositories):
    repos = {}
    for path in repositories:
        repo = {}
        attributes = repositories[path]
        try:
            repo['type'] = attributes['type']
            repo['url'] = attributes['url']
            if 'version' in attributes:
                repo['version'] = attributes['version']
        except AttributeError as e:
            print(ansi('yellowf') + ("Repository '%s' does not provide the necessary information: %s" % (path, e)) + ansi('reset'), file=sys.stderr)
            continue
        repos[path] = repo
    return repos
예제 #18
0
def output_export_data(result, hide_empty=False):
    # errors are handled by a separate function
    if result['returncode']:
        return

    path = get_path_of_result(result)

    try:
        lines = []
        lines.append('  %s:' % path)
        lines.append('    type: ' + result['client'].__class__.type)
        export_data = result['export_data']
        lines.append('    url: ' + export_data['url'])
        if 'version' in export_data and export_data['version']:
            lines.append('    version: ' + export_data['version'])
        print('\n'.join(lines))
    except KeyError as e:
        print(
            ansi('redf') + (
                "Command '%s' failed for path '%s': %s: %s" % (
                    result['command'].__class__.command,
                    result['client'].path, e.__class__.__name__, e)) +
            ansi('reset'),
            file=sys.stderr)
예제 #19
0
def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    parser = get_parser()
    add_common_arguments(parser,
                         skip_hide_empty=True,
                         skip_nested=True,
                         path_nargs='?',
                         path_help='Base path to clone repositories to')
    args = parser.parse_args(args)
    try:
        input_ = args.input
        if isinstance(input_, request.Request):
            input_ = request.urlopen(input_)
        repos = get_repositories(input_)
    except (RuntimeError, request.URLError) as e:
        print(ansi('redf') + str(e) + ansi('reset'), file=sys.stderr)
        return 1
    jobs = generate_jobs(repos, args)
    add_dependencies(jobs)

    if args.repos:
        output_repositories([job['client'] for job in jobs])

    workers = args.workers
    # for ssh URLs check if the host is known to prevent ssh asking for
    # confirmation when using more than one worker
    if workers > 1:
        ssh_keygen = None
        checked_hosts = set()
        for job in list(jobs):
            if job['command'] is None:
                continue
            url = job['command'].url
            # only check the host from a ssh URL
            if not url.startswith('git@') or ':' not in url:
                continue
            host = url[4:].split(':', 1)[0]

            # only check each host name once
            if host in checked_hosts:
                continue
            checked_hosts.add(host)

            # get ssh-keygen path once
            if ssh_keygen is None:
                ssh_keygen = which('ssh-keygen') or False
            if not ssh_keygen:
                continue

            result = run_command([ssh_keygen, '-F', host], '')
            if result['returncode']:
                print('At least one hostname (%s) is unknown, switching to a '
                      'single worker to allow interactively answering the ssh '
                      'question to confirm the fingerprint' % host)
                workers = 1
                break

    results = execute_jobs(jobs,
                           show_progress=True,
                           number_of_workers=workers,
                           debug_jobs=args.debug)
    output_results(results)

    any_error = any(r['returncode'] for r in results)
    return 1 if any_error else 0