def post_patch(self, destination, color='bluef'): if destination in self.debian_branches: return # Tag after patches have been applied with inbranch(destination): # Tag tag_name = self.tag_names[destination] if tag_exists(tag_name): if self.interactive: warning("Tag exists: " + tag_name) warning("Do you wish to overwrite it?") if not maybe_continue('y'): error("Answered no to continue, aborting.", exit=True) else: warning("Overwriting tag: " + tag_name) else: info("Creating tag: " + tag_name) execute_command('git tag -f ' + tag_name) # Report of success name = destination.split('/')[-1] package = self.packages[name] distro = destination.split('/')[-2] info(ansi(color) + "####" + ansi('reset'), use_prefix=False) info(ansi(color) + "#### " + ansi('greenf') + "Successfully" + ansi(color) + " generated '" + ansi('boldon') + distro + ansi('boldoff') + "' debian for package" " '" + ansi('boldon') + package.name + ansi('boldoff') + "'" + " at version '" + ansi('boldon') + package.version + "-" + str(self.debian_inc) + ansi('boldoff') + "'" + ansi('reset'), use_prefix=False) info(ansi(color) + "####\n" + ansi('reset'), use_prefix=False)
def post_patch(self, destination, color='bluef'): if destination in self.rpm_branches: return # Tag after patches have been applied with inbranch(destination): # Tag tag_name = self.tag_names[destination] if tag_exists(tag_name): if self.interactive: warning("Tag exists: " + tag_name) warning("Do you wish to overwrite it?") if not maybe_continue('y'): error("Answered no to continue, aborting.", exit=True) else: warning("Overwriting tag: " + tag_name) else: info("Creating tag: " + tag_name) execute_command('git tag -f ' + tag_name) # Report of success name = destination.split('/')[-1] package = self.packages[name] distro = destination.split('/')[-2] info(ansi(color) + "####" + ansi('reset'), use_prefix=False) info( ansi(color) + "#### " + ansi('greenf') + "Successfully" + ansi(color) + " generated '" + ansi('boldon') + distro + ansi('boldoff') + "' RPM for package" " '" + ansi('boldon') + package.name + ansi('boldoff') + "'" + " at version '" + ansi('boldon') + package.version + "-" + str(self.rpm_inc) + ansi('boldoff') + "'" + ansi('reset'), use_prefix=False ) info(ansi(color) + "####\n" + ansi('reset'), use_prefix=False)
def post_patch(self, destination, color='bluef'): # Tag after patches have been applied with inbranch(destination): # Tag tag_name = self.tag_names[destination] if tag_exists(tag_name): if self.interactive: warning("Tag exists: " + tag_name) warning("Do you wish to overwrite it?") if not maybe_continue('y'): error("Answered no to continue, aborting.") return code.ANSWERED_NO_TO_CONTINUE else: warning("Overwriting tag: " + tag_name) else: info("Creating tag: " + tag_name) execute_command('git tag -f ' + tag_name) # Report of success name = destination.split('/')[-1] stackage, kind = self.packages[name] distro = destination.split('/')[-2] info(ansi(color) + "####" + ansi('reset'), use_prefix=False) info( ansi(color) + "#### " + ansi('greenf') + "Successfully" + \ ansi(color) + " generated '" + ansi('boldon') + distro + \ ansi('boldoff') + "' debian for " + kind + \ " '" + ansi('boldon') + stackage.name + ansi('boldoff') + "'" + \ " at version '" + ansi('boldon') + stackage.version + \ "-" + str(self.debian_inc) + ansi('boldoff') + "'" + \ ansi('reset'), use_prefix=False ) info(ansi(color) + "####\n" + ansi('reset'), use_prefix=False)
def export_upstream(uri, tag, vcs_type, output_dir, show_uri, name): tag = tag if tag != ":{none}" else None output_dir = output_dir or os.getcwd() if uri.startswith("git@"): uri_is_path = False else: uri_parsed = urlparse(uri) uri = uri if uri_parsed.scheme else uri_parsed.path uri_is_path = False if uri_parsed.scheme else True name = name or "upstream" with temporary_directory() as tmp_dir: info( "Checking out repository at '{0}'".format(show_uri or uri) + (" to reference '{0}'.".format(tag) if tag else ".") ) if uri_is_path: upstream_repo = get_vcs_client(vcs_type, uri) else: repo_path = os.path.join(tmp_dir, "upstream") upstream_repo = get_vcs_client(vcs_type, repo_path) if not upstream_repo.checkout(uri, tag or ""): error( "Failed to clone repository at '{0}'".format(uri) + (" to reference '{0}'.".format(tag) if tag else "."), exit=True, ) if get_root() is not None and has_submodules(upstream_repo.get_path()): error( """\ bloom does not support exporting git repositories with submodules, see: - https://github.com/ros-infrastructure/bloom/issues/202 - https://github.com/ros-infrastructure/bloom/issues/217 - https://github.com/vcstools/vcstools/issues/84 """, exit=True, ) tarball_prefix = "{0}-{1}".format(name, tag) if tag else name tarball_path = os.path.join(output_dir, tarball_prefix) full_tarball_path = tarball_path + ".tar.gz" info("Exporting to archive: '{0}'".format(full_tarball_path)) if not upstream_repo.export_repository(tag or "", tarball_path): error("Failed to create archive of upstream repository at '{0}'".format(show_uri)) if tag and vcs_type == "git": # can only check for git repos with change_directory(upstream_repo.get_path()): if not tag_exists(tag): warning("'{0}' is not a tag in the upstream repository...".format(tag)) if not branch_exists(tag): warning("'{0}' is not a branch in the upstream repository...".format(tag)) if not os.path.exists(full_tarball_path): error("Tarball was not created.", exit=True) info("md5: {0}".format(calculate_file_md5(full_tarball_path)))
def export_upstream(uri, tag, vcs_type, output_dir, show_uri, name): tag = tag if tag != ':{none}' else None output_dir = output_dir or os.getcwd() if uri.startswith('git@'): uri_is_path = False else: uri_parsed = urlparse(uri) uri = uri if uri_parsed.scheme else uri_parsed.path uri_is_path = False if uri_parsed.scheme else True name = name or 'upstream' with temporary_directory() as tmp_dir: info("Checking out repository at '{0}'".format(show_uri or uri) + (" to reference '{0}'.".format(tag) if tag else '.')) if uri_is_path: upstream_repo = get_vcs_client(vcs_type, uri) else: repo_path = os.path.join(tmp_dir, 'upstream') upstream_repo = get_vcs_client(vcs_type, repo_path) if not upstream_repo.checkout(uri, tag or ''): error("Failed to clone repository at '{0}'".format(uri) + (" to reference '{0}'.".format(tag) if tag else '.'), exit=True) if get_root() is not None and has_submodules(upstream_repo.get_path()): error("""\ bloom does not support exporting git repositories with submodules, see: - https://github.com/ros-infrastructure/bloom/issues/202 - https://github.com/ros-infrastructure/bloom/issues/217 - https://github.com/vcstools/vcstools/issues/84 """, exit=True) tarball_prefix = '{0}-{1}'.format(name, tag) if tag else name tarball_path = os.path.join(output_dir, tarball_prefix) full_tarball_path = tarball_path + '.tar.gz' info("Exporting to archive: '{0}'".format(full_tarball_path)) if not upstream_repo.export_repository(tag or '', tarball_path): error("Failed to create archive of upstream repository at '{0}'". format(show_uri)) if tag and vcs_type == 'git': # can only check for git repos with change_directory(upstream_repo.get_path()): if not tag_exists(tag): warning( "'{0}' is not a tag in the upstream repository...". format(tag)) if not branch_exists(tag): warning( "'{0}' is not a branch in the upstream repository..." .format(tag)) if not os.path.exists(full_tarball_path): error("Tarball was not created.", exit=True) info("md5: {0}".format(calculate_file_md5(full_tarball_path)))
def export_upstream(uri, tag, vcs_type, output_dir, show_uri, name): tag = tag if tag != ':{none}' else None output_dir = output_dir or os.getcwd() if uri.startswith('git@'): uri_is_path = False else: uri_parsed = urlparse(uri) uri = uri if uri_parsed.scheme else uri_parsed.path uri_is_path = False if uri_parsed.scheme else True name = name or 'upstream' with temporary_directory() as tmp_dir: info("Checking out repository at '{0}'".format(show_uri or uri) + (" to reference '{0}'.".format(tag) if tag else '.')) if uri_is_path: upstream_repo = get_vcs_client(vcs_type, uri) else: repo_path = os.path.join(tmp_dir, 'upstream') upstream_repo = get_vcs_client(vcs_type, repo_path) if not upstream_repo.checkout(uri, tag or ''): error("Failed to clone repository at '{0}'".format(uri) + (" to reference '{0}'.".format(tag) if tag else '.'), exit=True) tarball_prefix = '{0}-{1}'.format(name, tag) if tag else name tarball_path = os.path.join(output_dir, tarball_prefix) full_tarball_path = tarball_path + '.tar.gz' info("Exporting to archive: '{0}'".format(full_tarball_path)) if not upstream_repo.export_repository(tag or '', tarball_path): error("Failed to create archive of upstream repository at '{0}'" .format(show_uri)) if tag and vcs_type == 'git': # can only check for git repos with change_directory(upstream_repo.get_path()): if not tag_exists(tag): warning("'{0}' is not a tag in the upstream repository..." .format(tag)) if not branch_exists(tag): warning("'{0}' is not a branch in the upstream repository..." .format(tag)) if not os.path.exists(full_tarball_path): error("Tarball was not created.", exit=True) info("md5: {0}".format(calculate_file_md5(full_tarball_path)))
def export_upstream(uri, tag, vcs_type, output_dir, show_uri, name): tag = tag if tag != ':{none}' else None output_dir = output_dir or os.getcwd() if uri.startswith('git@'): uri_is_path = False else: uri_parsed = urlparse(uri) uri = uri if uri_parsed.scheme else uri_parsed.path uri_is_path = False if uri_parsed.scheme else True name = name or 'upstream' with temporary_directory() as tmp_dir: info("Checking out repository at '{0}'".format(show_uri or uri) + (" to reference '{0}'.".format(tag) if tag else '.')) if uri_is_path: upstream_repo = get_vcs_client(vcs_type, uri) else: repo_path = os.path.join(tmp_dir, 'upstream') upstream_repo = get_vcs_client(vcs_type, repo_path) if not upstream_repo.checkout(uri, tag or ''): error("Failed to clone repository at '{0}'".format(uri) + (" to reference '{0}'.".format(tag) if tag else '.'), exit=True) tarball_prefix = '{0}-{1}'.format(name, tag) if tag else name tarball_path = os.path.join(output_dir, tarball_prefix) full_tarball_path = tarball_path + '.tar.gz' info("Exporting to archive: '{0}'".format(full_tarball_path)) if not upstream_repo.export_repository(tag or '', tarball_path): error("Failed to create archive of upstream repository at '{0}'" .format(show_uri)) if tag: with change_directory(upstream_repo.get_path()): if not tag_exists(tag): warning("'{0}' is not a tag in the upstream repository..." .format(tag)) if not branch_exists(tag): warning("'{0}' is not a branch in the upstream repository..." .format(tag)) if not os.path.exists(full_tarball_path): error("Tarball was not created.", exit=True) info("md5: {0}".format(calculate_file_md5(full_tarball_path)))
def import_upstream(tarball_path, patches_path, version, name, replace): # Check for a url and download it url = urlparse(tarball_path) if url.scheme: # Some scheme like http, https, or file... tmp_dir = tempfile.mkdtemp() try: info("Fetching file from url: '{0}'".format(tarball_path)) req = load_url_to_file_handle(tarball_path) tarball_path = os.path.join(tmp_dir, os.path.basename(url.path)) with open(tarball_path, 'wb') as f: chunk_size = 16 * 1024 while True: chunk = req.read(chunk_size) if not chunk: break f.write(chunk) return import_upstream(tarball_path, patches_path, version, name, replace) finally: shutil.rmtree(tmp_dir) # If there is not tarball at the given path, fail if not os.path.exists(tarball_path): error("Specified archive does not exists: '{0}'".format(tarball_path), exit=True) # If either version or name are not provided, guess from archive name if not version or not name: # Parse tarball name tarball_file = os.path.basename(tarball_path) ending = None if tarball_file.endswith('.tar.gz'): ending = '.tar.gz' elif tarball_file.endswith('.zip'): ending = '.zip' else: error("Cannot detect type of archive: '{0}'" .format(tarball_file), exit=True) tarball_file = tarball_file[:-len(ending)] split_tarball_file = tarball_file.split('-') if len(split_tarball_file) < 2 and not version or len(split_tarball_file) < 1: error("Cannot detect name and/or version from archive: '{0}'" .format(tarball_file), exit=True) if not name and len(split_tarball_file) == 1: name = split_tarball_file[0] elif not name and len(split_tarball_file) == 1: name = '-'.join(split_tarball_file[:-1]) if not version and len(split_tarball_file) < 2: error("Cannot detect version from archive: '{0}'" .format(tarball_file) + " and the version was not spcified.", exit=True) version = version if version else split_tarball_file[-1] # Check if the patches_path (if given) exists patches_path_dict = None if patches_path: patches_path_dict = ls_tree(BLOOM_CONFIG_BRANCH, patches_path) if not patches_path_dict: error("Given patches path '{0}' does not exist in bloom branch." .format(patches_path), exit=True) # Do version checking version_check(version) # Check for existing tags upstream_tag = 'upstream/{0}'.format(version) if tag_exists(upstream_tag): if not replace: error("Tag '{0}' already exists, use --replace to override it." .format(upstream_tag), exit=True) warning("Removing tag: '{0}'".format(upstream_tag)) delete_tag(upstream_tag) if not get_git_clone_state(): delete_remote_tag(upstream_tag) name_tag = '{0}/{1}'.format(name or 'upstream', version) if name_tag != upstream_tag and tag_exists(name_tag): if not replace: error("Tag '{0}' already exists, use --replace to override it." .format(name_tag), exit=True) warning("Removing tag: '{0}'".format(name_tag)) delete_tag(name_tag) if not get_git_clone_state(): delete_remote_tag(name_tag) # If there is not upstream branch, create one if not branch_exists('upstream'): info("Creating upstream branch.") create_branch('upstream', orphaned=True) else: track_branches(['upstream']) # Import the given tarball info("Importing archive into upstream branch...") import_tarball(tarball_path, 'upstream', version, name) # Handle patches_path if patches_path: import_patches(patches_path, patches_path_dict, 'upstream', version) # Create tags with inbranch('upstream'): info("Creating tag: '{0}'".format(upstream_tag)) create_tag(upstream_tag) if name_tag != upstream_tag: info("Creating tag: '{0}'".format(name_tag)) create_tag(name_tag)
def execute_branch(src, dst, interactive, directory=None): """ Changes to the destination branch, creates branch and patches/branch if they do not exist. If the dst branch does not exist yet, then it is created by branching the current working branch or the specified SRC_BRANCH. If the patches/dst branch branch does not exist yet then it is created. If the branches are created successful, then the working branch will be set to the dst branch, otherwise the working branch will remain unchanged. :param src: source branch from which to copy :param dst: destination branch :param interactive: if True actions are summarized before committing :param directory: directory in which to preform this action :raises: subprocess.CalledProcessError if any git calls fail """ # Determine if the srouce branch exists if src is None: error("No source specified and/or not a branch currently", exit=True) if branch_exists(src, local_only=False, directory=directory): if not branch_exists(src, local_only=True, directory=directory): debug("Tracking source branch: {0}".format(src)) track_branches(src, directory) elif tag_exists(src): pass else: error("Specified source branch does not exist: {0}".format(src), exit=True) # Determine if the destination branch needs to be created create_dst_branch = False if branch_exists(dst, local_only=False, directory=directory): if not branch_exists(dst, local_only=True, directory=directory): debug("Tracking destination branch: {0}".format(dst)) track_branches(dst, directory) else: create_dst_branch = True # Determine if the destination patches branch needs to be created create_dst_patches_branch = False dst_patches = "patches/" + dst if branch_exists(dst_patches, False, directory=directory): if not branch_exists(dst_patches, True, directory=directory): track_branches(dst_patches, directory) else: create_dst_patches_branch = True # Summarize if interactive: info("Summary of changes:") if create_dst_branch: info( " " * 22 + "- The specified destination branch, " + ansi("boldon") + dst + ansi("reset") + ", does not exist; it will be created from the source " "branch " + ansi("boldon") + src + ansi("reset") ) if create_dst_patches_branch: info( " " * 22 + "- The destination patches branch, " + ansi("boldon") + dst_patches + ansi("reset") + ", does not exist; it will be created" ) info(" " * 22 + "- The working branch will be set to " + ansi("boldon") + dst + ansi("reset")) if not maybe_continue(): error("Answered no to continue, aborting.", exit=True) # Make changes to the layout current_branch = get_current_branch(directory) try: # Change to the src branch checkout(src, directory=directory) # Create the dst branch if needed if create_dst_branch: create_branch(dst, changeto=True, directory=directory) else: checkout(dst, directory=directory) # Create the dst patches branch if needed if create_dst_patches_branch: create_branch(dst_patches, orphaned=True, directory=directory) # Create the starting config data if it does not exist patches_ls = ls_tree(dst_patches, directory=directory) if "patches.conf" not in patches_ls: # Patches config not setup, set it up config = { "parent": src, "previous": "", "base": get_commit_hash(dst, directory=directory), "trim": "", "trimbase": "", } set_patch_config(dst_patches, config, directory=directory) else: config = get_patch_config(dst_patches, directory=directory) if config["parent"] != src: warning("Updated parent to '{0}' from '{1}'".format(src, config["parent"])) config["parent"] = src config["base"] = get_commit_hash(dst, directory=directory) set_patch_config(dst_patches, config, directory=directory) # Command successful, do not switch back to previous branch current_branch = None finally: if current_branch is not None: checkout(current_branch, directory=directory)
def execute_branch(src, dst, interactive, directory=None): """ Changes to the destination branch, creates branch and patches/branch if they do not exist. If the dst branch does not exist yet, then it is created by branching the current working branch or the specified SRC_BRANCH. If the patches/dst branch branch does not exist yet then it is created. If the branches are created successful, then the working branch will be set to the dst branch, otherwise the working branch will remain unchanged. :param src: source branch from which to copy :param dst: destination branch :param interactive: if True actions are summarized before committing :param directory: directory in which to preform this action :raises: subprocess.CalledProcessError if any git calls fail """ # Determine if the srouce branch exists if src is None: error("No source specified and/or not a branch currently", exit=True) if branch_exists(src, local_only=False, directory=directory): if not branch_exists(src, local_only=True, directory=directory): debug("Tracking source branch: {0}".format(src)) track_branches(src, directory) elif tag_exists(src): pass else: error("Specified source branch does not exist: {0}".format(src), exit=True) # Determine if the destination branch needs to be created create_dst_branch = False if branch_exists(dst, local_only=False, directory=directory): if not branch_exists(dst, local_only=True, directory=directory): debug("Tracking destination branch: {0}".format(dst)) track_branches(dst, directory) else: create_dst_branch = True # Determine if the destination patches branch needs to be created create_dst_patches_branch = False dst_patches = 'patches/' + dst if branch_exists(dst_patches, False, directory=directory): if not branch_exists(dst_patches, True, directory=directory): track_branches(dst_patches, directory) else: create_dst_patches_branch = True # Summarize if interactive: info("Summary of changes:") if create_dst_branch: info(" " * 22 + "- The specified destination branch, " + ansi('boldon') + dst + ansi('reset') + ", does not exist; it will be created from the source " "branch " + ansi('boldon') + src + ansi('reset')) if create_dst_patches_branch: info(" " * 22 + "- The destination patches branch, " + ansi('boldon') + dst_patches + ansi('reset') + ", does not exist; it will be created") info(" " * 22 + "- The working branch will be set to " + ansi('boldon') + dst + ansi('reset')) if not maybe_continue(): error("Answered no to continue, aborting.", exit=True) # Make changes to the layout current_branch = get_current_branch(directory) try: # Change to the src branch checkout(src, directory=directory) # Create the dst branch if needed if create_dst_branch: create_branch(dst, changeto=True, directory=directory) else: checkout(dst, directory=directory) # Create the dst patches branch if needed if create_dst_patches_branch: create_branch(dst_patches, orphaned=True, directory=directory) # Create the starting config data if it does not exist patches_ls = ls_tree(dst_patches, directory=directory) if 'patches.conf' not in patches_ls: # Patches config not setup, set it up config = { 'parent': src, 'previous': '', 'base': get_commit_hash(dst, directory=directory), 'trim': '', 'trimbase': '' } set_patch_config(dst_patches, config, directory=directory) else: config = get_patch_config(dst_patches, directory=directory) if config['parent'] != src: warning("Updated parent to '{0}' from '{1}'".format( src, config['parent'])) config['parent'] = src config['base'] = get_commit_hash(dst, directory=directory) set_patch_config(dst_patches, config, directory=directory) # Command successful, do not switch back to previous branch current_branch = None finally: if current_branch is not None: checkout(current_branch, directory=directory)
def import_upstream(cwd, tmp_dir, args): # Ensure the bloom and upstream branches are tracked locally track_branches(['bloom', 'upstream']) # Create a clone of the bloom_repo to help isolate the activity bloom_repo_clone_dir = os.path.join(tmp_dir, 'bloom_clone') os.makedirs(bloom_repo_clone_dir) os.chdir(bloom_repo_clone_dir) bloom_repo = get_vcs_client('git', bloom_repo_clone_dir) bloom_repo.checkout('file://{0}'.format(cwd)) # Ensure the bloom and upstream branches are tracked from the original track_branches(['bloom', 'upstream']) ### Fetch the upstream tag upstream_repo = None upstream_repo_dir = os.path.join(tmp_dir, 'upstream_repo') # If explicit svn url just export and git-import-orig if args.explicit_svn_url is not None: if args.upstream_version is None: error("'--explicit-svn-url' must be specified with " "'--upstream-version'") return 1 info("Checking out upstream at version " + ansi('boldon') + \ str(args.upstream_version) + ansi('reset') + \ " from repository at " + ansi('boldon') + \ str(args.explicit_svn_url) + ansi('reset')) upstream_repo = get_vcs_client('svn', upstream_repo_dir) retcode = try_vcstools_checkout(upstream_repo, args.explicit_svn_url) if retcode != 0: return retcode meta = { 'name': None, 'version': args.upstream_version, 'type': 'manual' } # Else fetching from bloom configs else: # Check for a bloom branch check_for_bloom() # Parse the bloom config file upstream_url, upstream_type, upstream_branch = parse_bloom_conf() # If the upstream_tag is specified, don't search just fetch upstream_repo = get_vcs_client(upstream_type, upstream_repo_dir) if args.upstream_tag is not None: warning("Using specified upstream tag '" + args.upstream_tag + "'") if upstream_type == 'svn': upstream_url += '/tags/' + args.upstream_tag upstream_tag = '' else: upstream_tag = args.upstream_tag retcode = try_vcstools_checkout(upstream_repo, upstream_url, upstream_tag) if retcode != 0: return retcode meta = { 'name': None, 'version': args.upstream_tag, 'type': 'manual' } # We have to search for the upstream tag else: if args.upstream_devel is not None: warning("Overriding the bloom.conf upstream branch with " + args.upstream_devel) devel_branch = args.upstream_devel else: devel_branch = upstream_branch if args.upstream_version is None: meta = auto_upstream_checkout( upstream_repo, upstream_url, devel_branch ) else: meta = { 'version': args.upstream_version } if type(meta) not in [dict] and meta != 0: return meta ### Export the repository version = meta['version'] # Export the repository to a tar ball tarball_prefix = 'upstream-' + str(version) info('Exporting version {0}'.format(version)) tarball_path = os.path.join(tmp_dir, tarball_prefix) if upstream_repo.get_vcs_type_name() == 'svn': upstream_repo.export_repository('', tarball_path) else: if args.upstream_tag is not None: upstream_repo.export_repository(args.upstream_tag, tarball_path) else: upstream_repo.export_repository(version, tarball_path) # Get the gbp version elements from either the last tag or the default last_tag = get_last_tag_by_version() if last_tag == '': gbp_major, gbp_minor, gbp_patch = segment_version(version) else: gbp_major, gbp_minor, gbp_patch = \ get_versions_from_upstream_tag(last_tag) info("The latest upstream tag in the release repository is " + ansi('boldon') + last_tag + ansi('reset')) # Ensure the new version is greater than the last tag last_tag_version = '.'.join([gbp_major, gbp_minor, gbp_patch]) if parse_version(version) < parse_version(last_tag_version): warning("""\ Version discrepancy: The upstream version, {0}, is not newer than the previous \ release version, {1}. """.format(version, last_tag_version)) if parse_version(version) <= parse_version(last_tag_version): if args.replace: # Remove the conflicting tag first warning("""\ The upstream version, {0}, is equal to or less than a previous \ import version. Removing conflicting tag before continuing \ because the '--replace' options was specified.\ """.format(version)) else: warning("""\ The upstream version, {0}, is equal to a previous import version. \ git-buildpackage will fail, if you want to replace the existing \ upstream import use the '--replace' option.\ """.format(version)) if args.replace: if tag_exists('upstream/' + version): execute_command('git tag -d {0}'.format('upstream/' + version)) execute_command('git push origin :refs/tags/' '{0}'.format('upstream/' + version)) # Look for upstream branch if not branch_exists('upstream', local_only=True): create_branch('upstream', orphaned=True, changeto=True) # Go to the bloom branch during import bloom_repo.update('bloom') # Detect if git-import-orig is installed tarball_path += '.tar.gz' import_orig(tarball_path, 'upstream', upstream_repo.get_url(), version) # Push changes back to the original bloom repo execute_command('git push --all -f') execute_command('git push --tags')
def import_upstream(tarball_path, patches_path, version, name, replace): # If there is not tarball at the given path, fail if not os.path.exists(tarball_path): error("Specified archive does not exists: '{0}'".format(tarball_path), exit=True) # If either version or name are not provided, guess from archive name if not version or not name: # Parse tarball name tarball_file = os.path.basename(tarball_path) ending = None if tarball_file.endswith(".tar.gz"): ending = ".tar.gz" elif tarball_file.endswith(".zip"): ending = ".zip" else: error("Cannot detect type of archive: '{0}'".format(tarball_file), exit=True) tarball_file = tarball_file[: -len(ending)] split_tarball_file = tarball_file.split("-") if len(split_tarball_file) < 2 and not version or len(split_tarball_file) < 1: error("Cannot detect name and/or version from archive: '{0}'".format(tarball_file), exit=True) if not name and len(split_tarball_file) == 1: name = split_tarball_file[0] elif not name and len(split_tarball_file) == 1: name = "-".join(split_tarball_file[:-1]) if not version and len(split_tarball_file) < 2: error( "Cannot detect version from archive: '{0}'".format(tarball_file) + " and the version was not spcified.", exit=True, ) version = version if version else split_tarball_file[-1] # Check if the patches_path (if given) exists patches_path_dict = None if patches_path: patches_path_dict = ls_tree("bloom", patches_path) if not patches_path_dict: error("Given patches path '{0}' does not exist in bloom branch.".format(patches_path), exit=True) # Do version checking version_check(version) # Check for existing tags upstream_tag = "upstream/{0}".format(version) if tag_exists(upstream_tag): if not replace: error("Tag '{0}' already exists, use --replace to override it.".format(upstream_tag), exit=True) warning("Removing tag: '{0}'".format(upstream_tag)) delete_tag(upstream_tag) if not get_git_clone_state(): delete_remote_tag(upstream_tag) name_tag = "{0}/{1}".format(name or "upstream", version) if name_tag != upstream_tag and tag_exists(name_tag): if not replace: error("Tag '{0}' already exists, use --replace to override it.".format(name_tag), exit=True) warning("Removing tag: '{0}'".format(name_tag)) delete_tag(name_tag) if not get_git_clone_state(): delete_remote_tag(name_tag) # If there is not upstream branch, create one if not branch_exists("upstream"): info("Creating upstream branch.") create_branch("upstream", orphaned=True) else: track_branches(["upstream"]) # Import the given tarball info("Importing archive into upstream branch...") import_tarball(tarball_path, "upstream", version, name) # Handle patches_path if patches_path: import_patches(patches_path, patches_path_dict, "upstream", version) # Create tags with inbranch("upstream"): info("Creating tag: '{0}'".format(upstream_tag)) create_tag(upstream_tag) if name_tag != upstream_tag: info("Creating tag: '{0}'".format(name_tag)) create_tag(name_tag)