This repository has been archived by the owner on Jun 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
139 lines (108 loc) · 4.81 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
import os
import sys
from pkg_resources import require
import click
import yaml
import catkin_pkg.packages
from pandoradep import utils
from pandoradep.config import COLORS, MASTER_BRANCH
@click.group(invoke_without_command=True)
@click.option('--version', is_flag=True, help='Return the current version.')
def cli(version):
""" A tiny cli tool to manage PANDORA's dependencies. """
if version:
click.echo(require('pandoradep')[0].version)
@cli.command()
@click.argument('root_of_pkgs', type=click.Path(exists=True, readable=True))
def create(root_of_pkgs):
""" Create a repos.yml file, mapping each package to
the corresponding repo. [used by CI]
"""
package_dirs = {}
for root, dirs, files in os.walk(root_of_pkgs):
if '.git' in dirs:
package_dirs[root] = []
for repo in package_dirs:
for root, dirs, files in os.walk(repo):
if 'package.xml' in files:
package_dirs[repo].append(os.path.basename(root))
for repo in package_dirs:
package_dirs[os.path.basename(repo)] = package_dirs.pop(repo)
click.echo(package_dirs)
with open('repos.yml', 'w') as file_handler:
file_handler.write(yaml.dump(package_dirs))
@cli.command()
@click.argument('root', type=click.Path(exists=True, readable=True))
@click.argument('repo_name', type=click.STRING)
@click.argument('repos_file', type=click.STRING)
@click.option('--env', type=click.STRING, default='JENKINS_SCRIPTS',
help="""Specify environmental variable for
the scripts. The default is JENKINS_SCRIPTS.
""")
def update(root, repo_name, repos_file, env):
""" Update dependencies [used by CI] """
repos_file = os.path.abspath(repos_file)
try:
with open(repos_file, 'r') as file_handler:
repos = yaml.safe_load(file_handler)
except IOError as err:
click.echo(click.style(str(err), fg=COLORS['error']))
sys.exit(1)
catkin_output = catkin_pkg.packages.find_packages(root)
local_pkgs = [pkg.name for pkg in catkin_output.values()]
try:
repo_dependencies = set(repos[repo_name])
except KeyError as err:
click.echo(click.style(str(err) + ' not found in ' + repos_file,
fg=COLORS['error']))
click.echo(click.style(str(repos.keys()), fg=COLORS['debug']))
sys.exit(1)
if repo_dependencies == set(local_pkgs):
click.echo(click.style('Nothing changed', fg=COLORS['success']))
else:
click.echo(click.style('Updating packages...', fg=COLORS['info']))
repos[repo_name] = local_pkgs
utils.update_upstream(repos_file, repos, env)
@cli.command()
@click.argument('directory', type=click.Path(exists=True, readable=True))
@click.option('--http', is_flag=True,
help='Return rosinstall entries with https.')
@click.option('--exclude', '-x', multiple=True, default=None,
type=click.Path(exists=True, readable=True),
help='Exclude a directory from the scan.')
@click.option('--force', is_flag=True, help='Use it to suppress warnings.')
@click.option('--branch', default=MASTER_BRANCH, help='Set the default branch')
def scan(directory, http, exclude, force, branch):
""" Scans the directory tree for dependencies. By default returns
rosinstall entries that you can feed into the wstool.
"""
depends = utils.get_dependencies(directory, excluded=exclude, force=force, branch=branch)
utils.print_repos(depends, http)
@cli.command()
@click.argument('directory', default='.', type=click.Path(exists=True,
readable=True))
@click.option('--http', is_flag=True, help='Clone the repos with http.')
@click.option('--branch', default=MASTER_BRANCH, help='Set the default branch')
def fetch(directory, http, branch):
""" Fetch PANDORA's dependencies. """
dependencies = utils.get_dependencies(directory, branch=branch)
repos = [dep['repo'] for dep in dependencies]
utils.download(repos, http, branch=branch)
@cli.command()
@click.argument('repo')
@click.option('--without-deps', is_flag=True,
help="Don't fetch the dependencies.")
@click.option('--http', is_flag=True, help='Clone the repo using http.')
@click.option('--branch', default=MASTER_BRANCH, help='Set the default branch')
@click.pass_context
def get(ctx, repo, without_deps, http, branch):
""" Download a PANDORA repo with its dependencies. """
repo_list = utils.fetch_upstream()
if not utils.pandora_lookup(repo, repo_list):
click.echo(click.style('✘ ' + str(repo) + ' is not a PANDORA repo.',
fg=COLORS['error']))
sys.exit(1)
utils.download_package(repo, http, branch=branch)
if not without_deps:
ctx.invoke(fetch, directory=repo, http=http, branch=branch)