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
Command to allow a user to checkout the contents of a
previously commited PIN file.
Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
---
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.<BR>
+# 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.<BR>
+# 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.<BR>
+# 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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#55904): https://edk2.groups.io/g/devel/message/55904
Mute This Topic: https://groups.io/mt/72005418/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com> -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Desimone, Ashley E Sent: Monday, March 16, 2020 11:17 AM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>; Bjorge, Erik C <erik.c.bjorge@intel.com> Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial commit of checkout pin Command to allow a user to checkout the contents of a previously commited PIN file. Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> Cc: Puja Pandya <puja.pandya@intel.com> Cc: Erik Bjorge <erik.c.bjorge@intel.com> --- 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.<BR> # +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.<BR> # 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.<BR> # +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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55936): https://edk2.groups.io/g/devel/message/55936 Mute This Topic: https://groups.io/mt/72005418/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.