forked from ros/rosdistro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_devel_repo.py
executable file
·46 lines (39 loc) · 1.72 KB
/
add_devel_repo.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
#!/usr/bin/env python
from __future__ import print_function
import argparse
import sys
import yaml
from sort_yaml import sort_yaml_data
def add_devel_repository(yaml_file, name, vcs_type, url, version=None):
data = yaml.load(open(yaml_file, 'r'))
if data['type'] != 'devel':
raise RuntimeError('The passed .yaml file is not of type "devel"')
if name in data['repositories']:
raise RuntimeError('Repository with name "%s" is already in the .yaml file' % name)
values = {
'type': vcs_type,
'url': url,
}
if version is None and vcs_type != 'svn':
raise RuntimeError('All repository types except SVN require a version attribute')
if version is not None:
if vcs_type == 'svn':
raise RuntimeError('SVN repository must not have a version attribute but must contain the version in the URL')
values['version'] = version
data['repositories'][name] = values
sort_yaml_data(data)
yaml.dump(data, file(yaml_file, 'w'), default_flow_style=False)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Insert a repository into the .yaml file.')
parser.add_argument('yaml_file', help='The yaml file to update')
parser.add_argument('name', help='The unique name of the repo')
parser.add_argument('type', help='The type of the repository (i.e. "git", "hg", "svn")')
parser.add_argument('url', help='The url of the repository')
parser.add_argument('version', nargs='?', help='The version')
args = parser.parse_args()
try:
print(args)
add_devel_repository(args.yaml_file, args.name, args.type, args.url, args.version)
except Exception as e:
print(str(e), file=sys.stderr)
exit(1)