def sort_yaml(yaml_file): data = yaml.load(open(yaml_file, 'r')) if 'version' in data: print('This script does not support the new rosdistro yaml files', file=sys.stderr) sys.exit(1) sort_yaml_data(data) yaml.dump(data, file(yaml_file, 'w'), default_flow_style=False)
def sort_yaml_data(data): # sort lists if isinstance(data, list): data.sort() # recurse into each value of a dict elif isinstance(data, dict): for k in data: sort_yaml_data(data[k])
def add_release_repository_fuerte(yaml_file, data, name, url, version): if name in data['repositories']: raise RuntimeError('Repository with name "%s" is already in the .yaml file' % name) data['repositories'][name] = { 'url': url, 'version': version, } sort_yaml_data(data) yaml.dump(data, file(yaml_file, 'w'), default_flow_style=False)
def add_release_repository(yaml_file, name, url, version): data = yaml.load(open(yaml_file, 'r')) if data['type'] != 'gbp': raise RuntimeError('The passed .yaml file is not of type "gbp"') if name in data['repositories']: raise RuntimeError( 'Repository with name "%s" is already in the .yaml file' % name) data['repositories'][name] = { 'url': url, 'version': version, } sort_yaml_data(data) yaml.dump(data, file(yaml_file, 'w'), default_flow_style=False)
def add_devel_repository_fuerte(yaml_file, data, name, vcs_type, url, version): 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)
def add_devel_repository_fuerte(yaml_file, data, name, vcs_type, url, version): 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) with open(yaml_file, 'w') as out_file: yaml.dump(data, out_file, default_flow_style=False)