From 33252d45e4076d15cf26ffdf8bbb52f6168345dd Mon Sep 17 00:00:00 2001 From: Ashley E Desimone Date: Tue, 28 Feb 2023 14:29:59 -0800 Subject: [PATCH] EdkRepo: Move sync specific strings to a sync specific location Resolves #137 Signed-off-by: Ashley E Desimone Reviewed-by: Nate Desimone Reviewed-by: Kevin Sun --- edkrepo/commands/humble/sync_humble.py | 41 +++++++++++++++++ edkrepo/commands/sync_command.py | 63 ++++++++++++-------------- edkrepo/common/humble.py | 34 +------------- 3 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 edkrepo/commands/humble/sync_humble.py diff --git a/edkrepo/commands/humble/sync_humble.py b/edkrepo/commands/humble/sync_humble.py new file mode 100644 index 0000000..948eeed --- /dev/null +++ b/edkrepo/commands/humble/sync_humble.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# +## @file +# sync_humble.py +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' Contains informational and error messages outputted by +the run_command function method of the Sync command +''' + +from edkrepo.common.humble import BRANCH_BEHIND + +SYNC_EXIT = 'Exiting without performing sync operations.' +SYNC_UPDATE_FIX = 'To checkout the new SHA/tag/branch run edkrepo checkout on the current combo.\n' +SYNC_MANIFEST_NOT_FOUND = 'A manifest for project, {}, was not found.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT +SYNC_MANIFEST_UPDATE_FAILED = 'Failed to update manifest.' +SYNC_SOURCE_MOVE_WARNING = '{} being moved to {}' +SYNC_REMOVE_WARNING = 'The following repos no longer exist in the new manifest and can no \nlonger be used for submitting code. Please manually delete the following \ndirectories after saving any work you have in them:' +SYNC_MANIFEST_DIFF_WARNING = 'The global manifest for this project differs from the local manifest.' +SYNC_MANIFEST_UPDATE = 'To update to the latest manifest please run edkrepo sync --update-local-manifest.' +SYNC_REPO_CHANGE = 'The latest manifest for project, {}, requires a change in currently cloned repositories.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT +SYNCING = 'Syncing {0} to latest {1} branch ...' +FETCHING = 'Fetching latest code for {0} from {1} branch ...' +UPDATING_MANIFEST = 'Updating local manifest file ...' +NO_SYNC_DETACHED_HEAD = 'No need to sync repo {0} since it is in detached HEAD state' +SYNC_COMMITS_ON_TARGET = 'Commits were found on {0} branch.\n (use the "--override" flag to overwrite these commits)\nRepo {1} was not updated.' +SYNC_ERROR = '\nError: Some repositories were not updated.' +SYNC_NEEDS_REBASE = BRANCH_BEHIND + '\n' + ' (use "git rebase {target_remote}/{target_branch} {local_branch}" inside the {repo_folder} folder to rebase your commit)' +SYNC_BRANCH_CHANGE_ON_LOCAL = 'The SHA, tag or branch defined in the current combo has changed from {} to {} for the {} repo.\n The current workspace is not on the SHA/tag/branch defined in the initial combo. Unable to checkout new SHA/tag/branch.\n' + SYNC_UPDATE_FIX +SYNC_REBASE_CALC_FAIL = 'Unable to calculate if a rebase is required for the current branch' +SYNC_MOVE_FAILED = '''Moving {initial_dir} to {new_dir} failed. +Most likely files from the original directory are open in an editor or IDE. +It is likely that {new_dir} contains your original code now. +Please close any open editors to reconcile this problem. +You may need to manually rename {new_dir} to {initial_dir} in some circumstances.\n''' +SYNC_AUTOMATIC_REMOTE_PRUNE = 'Performing automatic remote prune...' + + diff --git a/edkrepo/commands/sync_command.py b/edkrepo/commands/sync_command.py index 36317e7..511ba1f 100644 --- a/edkrepo/commands/sync_command.py +++ b/edkrepo/commands/sync_command.py @@ -3,7 +3,7 @@ ## @file # sync_command.py # -# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -22,16 +22,10 @@ from edkrepo.commands.edkrepo_command import EdkrepoCommand from edkrepo.commands.edkrepo_command import SubmoduleSkipArgument, SourceManifestRepoArgument import edkrepo.commands.arguments.sync_args as arguments +import edkrepo.commands.humble.sync_command as humble from edkrepo.common.edkrepo_exception import EdkrepoException, EdkrepoManifestNotFoundException from edkrepo.common.edkrepo_exception import EdkrepoManifestChangedException -from edkrepo.common.humble import SYNC_MANIFEST_NOT_FOUND, SYNC_MANIFEST_UPDATE_FAILED -from edkrepo.common.humble import SYNC_SOURCE_MOVE_WARNING, SYNC_REMOVE_WARNING, SYNC_REMOVE_LIST_END_FORMATTING -from edkrepo.common.humble import SYNC_MANIFEST_DIFF_WARNING, SYNC_MANIFEST_UPDATE -from edkrepo.common.humble import SPARSE_RESET, SPARSE_CHECKOUT, SYNC_REPO_CHANGE, SYNCING, FETCHING, UPDATING_MANIFEST -from edkrepo.common.humble import NO_SYNC_DETACHED_HEAD, SYNC_COMMITS_ON_TARGET, SYNC_ERROR -from edkrepo.common.humble import MIRROR_BEHIND_PRIMARY_REPO, SYNC_NEEDS_REBASE, INCLUDED_FILE_NAME -from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL -from edkrepo.common.humble import SYNC_REBASE_CALC_FAIL, SYNC_MOVE_FAILED, SYNC_AUTOMATIC_REMOTE_PRUNE +from edkrepo.common.humble import SPARSE_RESET, SPARSE_CHECKOUT, INCLUDED_FILE_NAME from edkrepo.common.workspace_maintenance.humble.manifest_repos_maintenance_humble import SOURCE_MANIFEST_REPO_NOT_FOUND from edkrepo.common.pathfix import get_actual_path, expanduser from edkrepo.common.common_cache_functions import get_repo_cache_obj @@ -136,7 +130,7 @@ def run_command(self, args, config): except EdkrepoException as e: if args.verbose: print(e) - print(SYNC_MANIFEST_UPDATE_FAILED) + print(humble.SYNC_MANIFEST_UPDATE_FAILED) manifest = get_workspace_manifest() if args.update_local_manifest: try: @@ -189,9 +183,9 @@ def run_command(self, args, config): #The new branch may not exist in the heads list yet if it is a new branch repo.git.checkout(repo_to_sync.branch) if not args.fetch: - ui_functions.print_info_msg(SYNCING.format(repo_to_sync.root, repo.active_branch), header = False) + ui_functions.print_info_msg(humble.SYNCING.format(repo_to_sync.root, repo.active_branch), header = False) else: - ui_functions.print_info_msg(FETCHING.format(repo_to_sync.root, repo.active_branch), header = False) + ui_functions.print_info_msg(humble.FETCHING.format(repo_to_sync.root, repo.active_branch), header = False) try: repo.remotes.origin.fetch() except GitCommandError as e: @@ -207,7 +201,7 @@ def run_command(self, args, config): if e.stderr.strip().find(prune_needed_heuristic_str) != -1: prune_needed = True if prune_needed: - ui_functions.print_info_msg(SYNC_AUTOMATIC_REMOTE_PRUNE) + ui_functions.print_info_msg(humble.SYNC_AUTOMATIC_REMOTE_PRUNE) time.sleep(1.0) repo.git.remote('prune', 'origin') time.sleep(1.0) @@ -216,7 +210,7 @@ def run_command(self, args, config): raise if not args.override and not repo.is_ancestor(ancestor_rev='HEAD', rev='origin/{}'.format(repo_to_sync.branch)): - ui_functions.print_info_msg(SYNC_COMMITS_ON_TARGET.format(repo_to_sync.branch, repo_to_sync.root), header = False) + ui_functions.print_info_msg(humble.SYNC_COMMITS_ON_TARGET.format(repo_to_sync.branch, repo_to_sync.root), header=False) local_commits = True sync_error = True if not args.fetch and (not local_commits or args.override): @@ -232,23 +226,23 @@ def run_command(self, args, config): branch_origin = next(itertools.islice(repo.iter_commits(), commit_count, commit_count + 1)) behind_count = int(repo.git.rev_list('--count', '{}..{}'.format(branch_origin.hexsha, latest_sha))) if behind_count: - ui_functions.print_info_msg(SYNC_NEEDS_REBASE.format( + ui_functions.print_info_msg(humble.SYNC_NEEDS_REBASE.format( behind_count=behind_count, target_remote='origin', target_branch=repo_to_sync.branch, local_branch=initial_active_branch.name, - repo_folder=repo_to_sync.root), header = False) + repo_folder=repo_to_sync.root), header=False) except: - ui_functions.print_error_msg(SYNC_REBASE_CALC_FAIL, header = False) + ui_functions.print_error_msg(humble.SYNC_REBASE_CALC_FAIL, header=False) elif args.verbose: - ui_functions.print_warning_msg(NO_SYNC_DETACHED_HEAD.format(repo_to_sync.root), header = False) + ui_functions.print_warning_msg(humble.NO_SYNC_DETACHED_HEAD.format(repo_to_sync.root), header=False) # Update commit message templates if global_manifest_directory is not None: update_repo_commit_template(workspace_path, repo, repo_to_sync, global_manifest_directory) if sync_error: - ui_functions.print_error_msg(SYNC_ERROR, header = False) + ui_functions.print_error_msg(humble.SYNC_ERROR, header=False) # Initialize submodules if not args.skip_submodule: @@ -292,7 +286,7 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path if e.stderr.strip().find(prune_needed_heuristic_str) != -1: prune_needed = True if prune_needed: - ui_functions.print_info_msg(SYNC_AUTOMATIC_REMOTE_PRUNE) + ui_functions.print_info_msg(humble.SYNC_AUTOMATIC_REMOTE_PRUNE) # The sleep is to give the operating system time to close all the file handles that Git has open time.sleep(1.0) repo.git.remote('prune', 'origin') @@ -305,7 +299,7 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path index_path = os.path.join(global_manifest_directory, 'CiIndex.xml') ci_index_xml = CiIndexXml(index_path) if initial_manifest.project_info.codename not in ci_index_xml.project_list: - raise EdkrepoManifestNotFoundException(SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) + raise EdkrepoManifestNotFoundException(humble.SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) initial_manifest_remotes = {name:url for name, url in initial_manifest.remotes} ci_index_xml_rel_path = os.path.normpath(ci_index_xml.get_project_xml(initial_manifest.project_info.codename)) global_manifest = os.path.join(global_manifest_directory, ci_index_xml_rel_path) @@ -329,7 +323,7 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path initial_source_repos = set([(source.remote_name, source.remote_url, source.root) for source in set(initial_sources)]) new_source_repos = set([(source.remote_name, source.remote_url, source.root) for source in set(new_sources)]) if not args.override and initial_source_repos != new_source_repos: - raise EdkrepoManifestChangedException(SYNC_REPO_CHANGE.format(initial_manifest.project_info.codename)) + raise EdkrepoManifestChangedException(humble.SYNC_REPO_CHANGE.format(initial_manifest.project_info.codename)) elif args.override and initial_source_repos != new_source_repos: # get a set of repo source tuples that are not in both the new and old manifest uncommon_sources = [] @@ -394,21 +388,20 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path for source in sources_to_move: old_dir = os.path.join(workspace_path, source.root) new_dir = generate_name_for_obsolete_backup(old_dir) - ui_functions.print_warning_msg(SYNC_SOURCE_MOVE_WARNING.format(source.root, new_dir), header = False) + ui_functions.print_warning_msg(humble.SYNC_SOURCE_MOVE_WARNING.format(source.root, new_dir), header = False) new_dir = os.path.join(workspace_path, new_dir) try: shutil.move(old_dir, new_dir) except: - ui_functions.print_error_msg(SYNC_MOVE_FAILED.format(initial_dir=source.root, new_dir=new_dir), header = False) + ui_functions.print_error_msg(humble.SYNC_MOVE_FAILED.format(initial_dir=source.root, new_dir=new_dir), header=False) raise # Tell the user about any Git repositories that are no longer used. if len(sources_to_remove) > 0: - ui_functions.print_warning_msg(SYNC_REMOVE_WARNING, header = False) + ui_functions.print_warning_msg(humble.SYNC_REMOVE_WARNING, header = False) for source in sources_to_remove: path_to_source = os.path.join(workspace_path, source.root) ui_functions.print_warning_msg(path_to_source, header = False) - if len(sources_to_remove) > 0: - ui_functions.print_warning_msg(SYNC_REMOVE_LIST_END_FORMATTING, header = False) + # Clone any new Git repositories clone_repos(args, workspace_path, sources_to_clone, new_manifest_to_check.repo_hooks, config, new_manifest_to_check, global_manifest_directory) # Make a list of and only checkout repos that were newly cloned. Sync keeps repos on their initial active branches @@ -437,7 +430,7 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path create_repos(repos_to_create, workspace_path, new_manifest_to_check, global_manifest_directory) #remove the old manifest file and copy the new one - ui_functions.print_info_msg(UPDATING_MANIFEST, header = False) + ui_functions.print_info_msg(humble.UPDATING_MANIFEST, header=False) local_manifest_path = os.path.join(local_manifest_dir, 'Manifest.xml') os.remove(local_manifest_path) shutil.copy(global_manifest, local_manifest_path) @@ -476,18 +469,18 @@ def __check_combo_patchset_sha_tag_branch(self, workspace_path, initial_sources, break elif initial_source.commit and initial_source.commit != new_source.commit: if repo.head.object.hexsha != initial_source.commit: - ui_functions.print_info_msg(SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header = False) + ui_functions.print_info_msg(humble.SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header=False) repos_to_checkout.append(new_source) break elif initial_source.tag and initial_source.tag != new_source.tag: tag_sha = repo.git.rev_list('-n 1', initial_source.tag) #according to gitpython docs must change - to _ if tag_sha != repo.head.object.hexsha: - ui_functions.print_info_msg(SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header = False) + ui_functions.print_info_msg(humble.SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header=False) repos_to_checkout.append(new_source) break elif initial_source.branch and initial_source.branch != new_source.branch: if repo.active_branch.name != initial_source.branch: - ui_functions.print_info_msg(SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header = False) + ui_functions.print_info_msg(humble.SYNC_BRANCH_CHANGE_ON_LOCAL.format(initial_source.branch, new_source.branch, initial_source.root), header = False) repos_to_checkout.append(new_source) break return repos_to_checkout, repos_to_create @@ -499,7 +492,7 @@ def __check_for_new_manifest(self, args, config, initial_manifest, workspace_pat if args.override: return else: - raise EdkrepoManifestNotFoundException(SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) + raise EdkrepoManifestNotFoundException(humble.SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) #see if there is an entry in CiIndex.xml that matches the prject name of the current manifest index_path = os.path.join(global_manifest_directory, 'CiIndex.xml') @@ -508,13 +501,13 @@ def __check_for_new_manifest(self, args, config, initial_manifest, workspace_pat if args.override: return else: - raise EdkrepoManifestNotFoundException(SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) + raise EdkrepoManifestNotFoundException(humble.SYNC_MANIFEST_NOT_FOUND.format(initial_manifest.project_info.codename)) ci_index_xml_rel_path = ci_index_xml.get_project_xml(initial_manifest.project_info.codename) global_manifest_path = os.path.join(global_manifest_directory, os.path.normpath(ci_index_xml_rel_path)) global_manifest = ManifestXml(global_manifest_path) if not initial_manifest.equals(global_manifest, True): - ui_functions.print_warning_msg(SYNC_MANIFEST_DIFF_WARNING, header = False) - ui_functions.print_info_msg(SYNC_MANIFEST_UPDATE, header = False) + ui_functions.print_warning_msg(humble.SYNC_MANIFEST_DIFF_WARNING, header=False) + ui_functions.print_info_msg(humble.SYNC_MANIFEST_UPDATE, header = False) def __check_submodule_config(self, workspace_path, manifest, repo_sources): gitconfigpath = os.path.normpath(expanduser("~/.gitconfig")) diff --git a/edkrepo/common/humble.py b/edkrepo/common/humble.py index cdbeeb2..72b5586 100644 --- a/edkrepo/common/humble.py +++ b/edkrepo/common/humble.py @@ -3,7 +3,7 @@ ## @file # humble.py # -# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -15,7 +15,6 @@ # General error messages used by commands UNSUPPORTED_COMBO = 'The selected COMBINATION/SHA is not present in the project manifest file or does not exist. ' UNCOMMITED_CHANGES = 'Uncommited changes present in {0} repo. ' -UPDATING_MANIFEST = 'Updating local manifest file ...' MISSING_BRANCH_COMMIT = 'Either the BRANCH name, TAG name or COMMIT ID must be specified in the combination field of the manifest file.' WARNING_MESSAGE = 'One or more warnings present.\n (use the "--override" flag to ignore warnings)' AMEND = '"git commit --amend" to include these files in your commit' @@ -34,37 +33,6 @@ TAG_AND_BRANCH_SPECIFIED = 'BRANCH AND TAG name present in combination field for {} repo. Using TAG.\n' CHECKING_CONNECTION = 'Checking connection to remote url: {}\n' -#Error messages for sync_command.py -SYNC_EXIT = 'Exiting without performing sync operations.' -SYNC_UNCOMMITED_CHANGES = UNCOMMITED_CHANGES + SYNC_EXIT -SYNC_COMMITS_ON_TARGET = 'Commits were found on {0} branch.\n (use the "--override" flag to overwrite these commits)\nRepo {1} was not updated.' -SYNC_ERROR = '\nError: Some repositories were not updated.' -SYNC_MANIFEST_NOT_FOUND = 'A manifest for project, {0}, was not found.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT -SYNC_URL_CHANGE = 'The URL for the remote, {0} has changed.\n' + SYNC_EXIT -SYNC_COMBO_CHANGE = 'The current checked out combination, {0}, does not exist in the latest manifest for project, {1}\n' -SYNC_REPO_CHANGE = 'The latest manifest for project, {0}, requires a change in currently cloned repositories.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT -SYNC_SOURCE_MOVE_WARNING = '{}{}WARNING:{}{} {{}} being moved to {{}}'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED) -SYNC_REMOVE_WARNING = '{}{}WARNING:{}{} The following repos no longer exist in the new manifest and can no \nlonger be used for submitting code. Please manually delete the following \ndirectories after saving any work you have in them:'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED) -SYNC_MANIFEST_DIFF_WARNING = '{}{}WARNING:{}{} The global manifest for this project differs from the local manifest.'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED) -SYNC_NEEDS_REBASE = BRANCH_BEHIND + '\n' + ' (use "git rebase {target_remote}/{target_branch} {local_branch}" inside the {repo_folder} folder to rebase your commit)' -SYNC_UPDATE_FIX = 'To checkout the new SHA/tag/branch run edkrepo checkout on the current combo.\n' -SYNC_BRANCH_CHANGE_ON_LOCAL = 'The SHA, tag or branch defined in the current combo has changed from {} to {} for the {} repo.\n The current workspace is not on the SHA/tag/branch defined in the initial combo. Unable to checkout new SHA/tag/branch.\n' + SYNC_UPDATE_FIX -SYNC_REBASE_CALC_FAIL = 'Unable to calculate if a rebase is required for the current branch' -SYNC_INCOMPATIBLE_COMBO = 'No compatible combinations found in the latest manifest file. Cloning a new workspace is recommended. ' + SYNC_EXIT -SYNC_AUTOMATIC_REMOTE_PRUNE = 'Performing automatic remote prune...' -SYNC_MANIFEST_UPDATE_FAILED = 'Failed to update manifest.' - -#informational messages for sync_command.py -SYNCING = 'Syncing {0} to latest {1} branch ...' -FETCHING = 'Fetching latest code for {0} from {1} branch ...' -NO_SYNC_DETACHED_HEAD = 'No need to sync repo {0} since it is in detached HEAD state' -SYNC_MANIFEST_UPDATE = 'To update to the latest manifest please run edkrepo sync --update-local-manifest. {}'.format(Fore.RESET) -SYNC_REMOVE_LIST_END_FORMATTING = '{}'.format(Style.RESET_ALL) -SYNC_MOVE_FAILED = '''{}{}WARNING:{}{} Moving {{initial_dir}} to {{new_dir}} failed. -{}{}{}Most likely files from the original directory are open in an editor or IDE. -It is likely that {{new_dir}} contains your original code now. -Please close any open editors to reconcile this problem. -You may need to manually rename {{new_dir}} to {{initial_dir}} in some circumstances.\n{}'''.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED, Style.RESET_ALL, Style.BRIGHT, Fore.YELLOW, Style.RESET_ALL) #error messages for clone_command.py CLONE_EXIT = '\nExiting without performing clone operation.'