From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.75421.1584382630853583772 for ; Mon, 16 Mar 2020 11:17:11 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: D2NUAGyyHvRntbKdY+u3dk0duKC2bA7lz0JPh/xMu0Z9YPyWe+UtVeD+adw6MxyA59fiIHQQsl DZpA/ZribJMQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2020 11:17:06 -0700 IronPort-SDR: +ZomO6+GwpnUkUboQbUhB7b4Pfe71KJ3XJQ3lRCufAPDWKaw7IvN9hcTEPLoPwp72e4YubwLDv mysEvSiXoT2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,561,1574150400"; d="scan'208";a="244223117" Received: from aedesimo-desk.amr.corp.intel.com ([10.7.159.171]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2020 11:17:06 -0700 From: "Desimone, Ashley E" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya , Erik Bjorge Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial commit of checkout pin Date: Mon, 16 Mar 2020 11:16:52 -0700 Message-Id: <20200316181652.29664-1-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 Command to allow a user to checkout the contents of a previously commited PIN file. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Erik Bjorge --- edkrepo/commands/arguments/checkout_pin_args.py | 11 +++ edkrepo/commands/checkout_pin_command.py | 106 ++++++++++++++++++++++++ edkrepo/commands/humble/checkout_pin_humble.py | 14 ++++ edkrepo/common/edkrepo_exception.py | 4 + 4 files changed, 135 insertions(+) create mode 100644 edkrepo/commands/arguments/checkout_pin_args.py create mode 100644 edkrepo/commands/checkout_pin_command.py create mode 100644 edkrepo/commands/humble/checkout_pin_humble.py diff --git a/edkrepo/commands/arguments/checkout_pin_args.py b/edkrepo/commands/arguments/checkout_pin_args.py new file mode 100644 index 0000000..abd01b3 --- /dev/null +++ b/edkrepo/commands/arguments/checkout_pin_args.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_args.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +COMMAND_DESCRIPTION = ('Checks out the revisions described in a PIN file in ' + 'an existing workpace of the same project') diff --git a/edkrepo/commands/checkout_pin_command.py b/edkrepo/commands/checkout_pin_command.py new file mode 100644 index 0000000..a2afc41 --- /dev/null +++ b/edkrepo/commands/checkout_pin_command.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_command.py +# +# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import os + +from git import Repo + +from edkrepo.commands.edkrepo_command import EdkrepoCommand, OverrideArgument +import edkrepo.commands.arguments.checkout_pin_args as arguments +import edkrepo.commands.humble.checkout_pin_humble as humble +from edkrepo.common.common_repo_functions import sparse_checkout_enabled, reset_sparse_checkout, sparse_checkout +from edkrepo.common.common_repo_functions import check_dirty_repos, checkout_repos +from edkrepo.common.humble import SPARSE_CHECKOUT, SPARSE_RESET +from edkrepo.common.edkrepo_exception import EdkrepoInvalidParametersException, EdkrepoProjectMismatchException +from edkrepo.config.config_factory import get_workspace_path, get_workspace_manifest +from edkrepo_manifest_parser.edk_manifest import ManifestXml + +class CheckoutPinCommand(EdkrepoCommand): + def __init__(self): + super().__init__() + + def get_metadata(self): + metadata = {} + metadata['name'] = 'checkout-pin' + metadata['help-text'] = arguments.COMMAND_DESCRIPTION + metadata['alias'] = 'chp' + args = [] + metadata['arguments'] = args + args.append({'name' : 'pinfile', + 'positional' : True, + 'position' : 0, + 'required' : True, + 'help-text' : arguments.PIN_FILE_HELP}) + args.append(OverrideArgument) + return metadata + + def run_command(self, args, config): + workspace_path = get_workspace_path() + manifest = get_workspace_manifest() + pin_path = self.__get_pin_path(args, workspace_path, config['cfg_file'].manifest_repo_abs_local_path, manifest) + pin = ManifestXml(pin_path) + manifest_sources = manifest.get_repo_sources(manifest.general_config.current_combo) + check_dirty_repos(manifest, workspace_path) + for source in manifest_sources: + local_path = os.path.join(workspace_path, source.root) + repo = Repo(local_path) + origin = repo.remotes.origin + origin.fetch() + self.__pin_matches_project(pin, manifest, workspace_path) + manifest.write_current_combo(pin.general_config.current_combo) + sparse_enabled = sparse_checkout_enabled(workspace_path, manifest_sources) + if sparse_enabled: + print(SPARSE_RESET) + reset_sparse_checkout(workspace_path, manifest_sources) + pin_repo_sources = pin.get_repo_sources(pin.general_config.current_combo) + try: + checkout_repos(args.verbose, args.override, pin_repo_sources, workspace_path, manifest) + finally: + if sparse_enabled: + print(SPARSE_CHECKOUT) + sparse_checkout(workspace_path, pin_repo_sources, manifest) + + def __get_pin_path(self, args, workspace_path, manifest_repo_path, manifest): + if os.path.isabs(args.pinfile) and os.path.isfile(args.pinfile): + return os.path.normpath(args.pinfile) + elif os.path.isfile(os.path.join(manifest_repo_path, os.path.normpath(manifest.general_config.pin_path), args.pinfile)): + return os.path.join(manifest_repo_path, os.path.normpath(manifest.general_config.pin_path), args.pinfile) + elif os.path.isfile(os.path.join(manifest_repo_path, args.pinfile)): + return os.path.join(manifest_repo_path, args.pinfile) + elif os.path.isfile(os.path.join(workspace_path, args.pinfile)): + return os.path.join(workspace_path, args.pinfile) + elif os.path.isfile(os.path.join(workspace_path, 'repo', args.pinfile)): + return os.path.join(workspace_path, 'repo', args.pinfile) + elif not os.path.isfile(os.path.join(workspace_path, args.pinfile)) and os.path.dirname(args.pinfile) is None: + for dirpath, dirnames, filenames in os.walk(workspace_path): + if args.pinfile in filenames: + return os.path.join(dirpath, args.pinfile) + else: + raise EdkrepoInvalidParametersException(humble.NOT_FOUND) + + def __pin_matches_project(self, pin, manifest, workspace_path): + if pin.project_info.codename != manifest.project_info.codename: + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH) + elif not set(pin.remotes).issubset(set(manifest.remotes)): + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH) + elif pin.general_config.current_combo not in [c.name for c in manifest.combinations]: + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH) + combo_name = pin.general_config.current_combo + pin_sources = pin.get_repo_sources(combo_name) + pin_root_remote = {source.root:source.remote_name for source in pin_sources} + manifest_sources = manifest.get_repo_sources(combo_name) + manifest_root_remote = {source.root:source.remote_name for source in manifest_sources} + if set(pin_root_remote.items()).isdisjoint(set(manifest_root_remote.items())): + raise EdkrepoProjectMismatchException(humble.MANIFEST_MISMATCH) + pin_root_commit = {source.root:source.commit for source in pin_sources} + for source in pin_sources: + source_repo_path = os.path.join(workspace_path, source.root) + repo = Repo(source_repo_path) + if repo.commit(pin_root_commit[source.root]) is None: + raise EdkrepoProjectMismatchException(humble.NOT_FOUND) diff --git a/edkrepo/commands/humble/checkout_pin_humble.py b/edkrepo/commands/humble/checkout_pin_humble.py new file mode 100644 index 0000000..b5a9cfb --- /dev/null +++ b/edkrepo/commands/humble/checkout_pin_humble.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# +## @file +# checkout_pin_humble.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +CHP_EXIT = 'Exiting without checkout out PIN data.' +NOT_FOUND = 'The selected PIN file was not found.' +MANIFEST_MISMATCH = ('The selected PIN file does not refer to the same project ' + 'as the local manifest file. {}'.format(CHP_EXIT)) +COMMIT_NOT_FOUND = 'The commit referenced by the PIN file does not exist. {}'.format(CHP_EXIT) \ No newline at end of file diff --git a/edkrepo/common/edkrepo_exception.py b/edkrepo/common/edkrepo_exception.py index b6ea3dd..a56e709 100644 --- a/edkrepo/common/edkrepo_exception.py +++ b/edkrepo/common/edkrepo_exception.py @@ -58,6 +58,10 @@ class EdkrepoConfigFileReadOnlyException(EdkrepoException): def __init__(self, message): super().__init__(message, 112) +class EdkrepoProjectMismatchException(EdkrepoException): + def __init__(self, message): + super().__init__(message, 113) + class EdkrepoVerificationException(EdkrepoException): def __init__(self, message): super().__init__(message, 114) -- 2.16.2.windows.1