def upconvert_bloom_to_config_branch(): global _has_checked_bloom_branch if _has_checked_bloom_branch: return # Assert that this repository does not have multiple remotes check_for_multiple_remotes() if get_root() is None: # Not a git repository return track_branches(['bloom', BLOOM_CONFIG_BRANCH]) if show('bloom', PLACEHOLDER_FILE) is not None: return if show('bloom', 'bloom.conf') is not None: # Wait for the bloom.conf upconvert... return if not branch_exists('bloom'): return _has_checked_bloom_branch = True info("Moving configurations from deprecated 'bloom' branch " "to the '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) tmp_dir = mkdtemp() git_root = get_root() try: # Copy the new upstream source into the temporary directory with inbranch('bloom'): ignores = ('.git', '.gitignore', '.svn', '.hgignore', '.hg', 'CVS') configs = os.path.join(tmp_dir, 'configs') my_copytree(git_root, configs, ignores) if [x for x in os.listdir(os.getcwd()) if x not in ignores]: execute_command('git rm -rf ./*') with open(PLACEHOLDER_FILE, 'w') as f: f.write("""\ This branch ('bloom') has been deprecated in favor of storing settings and overlay files in the master branch. Please goto the master branch for anything which referenced the bloom branch. You can delete this branch at your convenience. """) execute_command('git add ' + PLACEHOLDER_FILE) if has_changes(): execute_command('git commit -m "DEPRECATING BRANCH"') if not branch_exists(BLOOM_CONFIG_BRANCH): info("Creating '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) create_branch(BLOOM_CONFIG_BRANCH, orphaned=True) with inbranch(BLOOM_CONFIG_BRANCH): my_copytree(configs, git_root) execute_command('git add ./*') if has_changes(): execute_command('git commit -m ' '"Moving configs from bloom branch"') finally: # Clean up if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def get_tracks_dict_raw(directory=None): if not branch_exists('bloom'): info("Creating bloom branch.") create_branch('bloom', orphaned=True, directory=directory) tracks_yaml = show('bloom', 'tracks.yaml', directory=directory) if not tracks_yaml: write_tracks_dict_raw( {'tracks': {}}, 'Initial tracks.yaml', directory=directory ) tracks_yaml = show('bloom', 'tracks.yaml', directory=directory) try: return yaml.load(tracks_yaml) except: # TODO handle yaml errors raise
def get_tracks_dict_raw(directory=None): upconvert_bloom_to_config_branch() if not branch_exists(BLOOM_CONFIG_BRANCH): info("Creating '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) create_branch(BLOOM_CONFIG_BRANCH, orphaned=True, directory=directory) tracks_yaml = show(BLOOM_CONFIG_BRANCH, 'tracks.yaml', directory=directory) if not tracks_yaml: write_tracks_dict_raw( {'tracks': {}}, 'Initial tracks.yaml', directory=directory ) tracks_yaml = show(BLOOM_CONFIG_BRANCH, 'tracks.yaml', directory=directory) tracks_dict = yaml.load(tracks_yaml) validate_track_versions(tracks_dict) return tracks_dict
def handle_tree(tree, directory, root_path, version): for path, kind in tree.iteritems(): if kind == 'directory': # Path relative to start path rel_path = os.path.join(directory, path) # If it is a file, error if os.path.isfile(rel_path): error("In patches path '{0}' is a directory".format(rel_path) + ", but it exists in the upstream branch as a file.", exit=True) # If it is not already a directory, create it if not os.path.isdir(rel_path): info(" Createing directory... '{0}'".format(rel_path)) os.mkdir(rel_path) # Recurse on the directory handle_tree(ls_tree(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path)), rel_path, root_path, version) if kind == 'file': # Path relative to start path rel_path = os.path.join(directory, path) # If the local version is a directory, error if os.path.isdir(rel_path): error("In patches path '{0}' is a file, ".format(rel_path) + "but it exists in the upstream branch as a directory.", exit=True) # If the file already exists, warn if os.path.isfile(rel_path): warning(" File '{0}' already exists, overwriting..." .format(rel_path)) execute_command('git rm {0}'.format(rel_path), shell=True) # If package.xml tempalte in version, else grab data if path in ['stack.xml']: warning(" Skipping '{0}' templating, fuerte not supported" .format(rel_path)) if path in ['package.xml']: info(" Templating '{0}' into upstream branch..." .format(rel_path)) file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path)) file_data = file_data.replace(':{version}', version) else: info(" Overlaying '{0}' into upstream branch..." .format(rel_path)) file_data = show(BLOOM_CONFIG_BRANCH, os.path.join(root_path, rel_path)) # Write file with open(rel_path, 'wb') as f: f.write(file_data) # Add it with git execute_command('git add {0}'.format(rel_path), shell=True)
def get_tracks_dict_raw(directory=None): upconvert_bloom_to_config_branch() if not branch_exists(BLOOM_CONFIG_BRANCH): info("Creating '{0}' branch.".format(BLOOM_CONFIG_BRANCH)) create_branch(BLOOM_CONFIG_BRANCH, orphaned=True, directory=directory) tracks_yaml = show(BLOOM_CONFIG_BRANCH, 'tracks.yaml', directory=directory) if not tracks_yaml: write_tracks_dict_raw( {'tracks': {}}, 'Initial tracks.yaml', directory=directory ) tracks_yaml = show(BLOOM_CONFIG_BRANCH, 'tracks.yaml', directory=directory) try: return yaml.load(tracks_yaml) except: # TODO handle yaml errors raise
def handle_tree(tree, directory, root_path, version): for path, kind in tree.iteritems(): if kind == "directory": # Path relative to start path rel_path = os.path.join(directory, path) # If it is a file, error if os.path.isfile(rel_path): error( "In patches path '{0}' is a directory".format(rel_path) + ", but it exists in the upstream branch as a file.", exit=True, ) # If it is not already a directory, create it if not os.path.isdir(rel_path): info(" Createing directory... '{0}'".format(rel_path)) os.mkdir(rel_path) # Recurse on the directory handle_tree(ls_tree("bloom", os.path.join(root_path, rel_path)), rel_path, root_path, version) if kind == "file": # Path relative to start path rel_path = os.path.join(directory, path) # If the local version is a directory, error if os.path.isdir(rel_path): error( "In patches path '{0}' is a file, ".format(rel_path) + "but it exists in the upstream branch as a directory.", exit=True, ) # If the file already exists, warn if os.path.isfile(rel_path): warning(" File '{0}' already exists, overwriting...".format(rel_path)) execute_command("git rm {0}".format(rel_path), shell=True) # If package.xml tempalte in version, else grab data if path in ["package.xml", "stack.xml"]: info(" Templating '{0}' into upstream branch...".format(rel_path)) file_data = show("bloom", os.path.join(root_path, rel_path)) file_data = file_data.replace(":{version}", version) else: info(" Overlaying '{0}' into upstream branch...".format(rel_path)) file_data = show("bloom", os.path.join(root_path, rel_path)) # Write file with open(rel_path, "wb") as f: f.write(file_data) # Add it with git execute_command("git add {0}".format(rel_path), shell=True)
def get_patch_config(patches_branch, directory=None): config_str = show(patches_branch, 'patches.conf') if config_str is None: error("Failed to get patches info: patches.conf does not exist") return None lines = config_str.splitlines() meta = {} for key in _patch_config_keys: meta[key] = '' for line in lines: if line.count('=') == 0: continue key, value = line.split('=', 1) meta[key.strip()] = value.strip() return meta
def parse_bloom_conf(cwd=None): """ Parses the bloom.conf file in the current directory and returns info in it. """ bloom_conf = show('bloom', 'bloom.conf', directory=cwd) with open('.bloom.conf', 'w+') as f: f.write(bloom_conf) cmd = 'git config -f .bloom.conf bloom.upstream' upstream_repo = check_output(cmd, shell=True, cwd=cwd).strip() cmd = 'git config -f .bloom.conf bloom.upstreamtype' upstream_type = check_output(cmd, shell=True, cwd=cwd).strip() try: cmd = 'git config -f .bloom.conf bloom.upstreambranch' upstream_branch = check_output(cmd, shell=True, cwd=cwd).strip() except CalledProcessError: upstream_branch = '' os.remove('.bloom.conf') return upstream_repo, upstream_type, upstream_branch
def load_original_config(self, patches_branch): config_store = show(patches_branch, 'rpm.store') if config_store is None: return config_store return json.loads(config_store)
def read_tracks_file(): tracks_yaml = show('master', 'tracks.yaml') if tracks_yaml: return yaml.safe_load(tracks_yaml) else: raise ValueError('repository is missing tracks.yaml in master branch.')
def read_tracks_file(): return yaml.safe_load(show('master', 'tracks.yaml'))
'This script must be run from a rosdistro index directory.') rosdistro_dir = os.path.abspath(os.getcwd()) rosdistro_index_url = f'file://{rosdistro_dir}/index-v4.yaml' index = get_index(rosdistro_index_url) index_yaml = yaml.safe_load(open('index-v4.yaml', 'r')) if len(index_yaml['distributions'][args.source]['distribution']) != 1 or \ len(index_yaml['distributions'][args.dest]['distribution']) != 1: raise RuntimeError( 'Both source and destination distributions must have a single distribution file.' ) # There is a possibility that the source_ref has a different distribution file # layout. Check that they match. source_ref_index_yaml = yaml.safe_load(show(args.source_ref, 'index-v4.yaml')) if source_ref_index_yaml['distributions'][args.source]['distribution'] != \ index_yaml['distributions'][args.source]['distribution']: raise RuntimeError( 'The distribution file layout has changed between the source ref and now.' ) source_distribution_filename = index_yaml['distributions'][ args.source]['distribution'][0] dest_distribution_filename = index_yaml['distributions'][ args.dest]['distribution'][0] # Fetch the source distribution file from the exact point in the repository history requested. source_distfile_data = yaml.safe_load( show(args.source_ref, source_distribution_filename)) source_distribution = DistributionFile(args.source, source_distfile_data)
def get_ignored_packages(release_directory=None): prefix = os.environ.get("BLOOM_TRACK", "packages") data = show(BLOOM_CONFIG_BRANCH, "{0}.ignored".format(prefix), directory=release_directory) or "" return [p.strip() for p in data.split() if p.strip()]
def get_releaser_history(self): # Assumes that this is called in the target branch patches_branch = 'patches/' + get_current_branch() raw = show(patches_branch, 'releaser_history.json') return None if raw is None else json.loads(raw)
def load_original_config(self, patches_branch): config_store = show(patches_branch, 'debian.store') if config_store is None: return config_store return json.loads(config_store)
def get_ignored_packages(release_directory=None): prefix = os.environ.get('BLOOM_TRACK', 'packages') data = show(BLOOM_CONFIG_BRANCH, '{0}.ignored'.format(prefix), directory=release_directory) or '' return [p.strip() for p in data.split() if p.strip()]