From nobody Wed May 8 11:57:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55772+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55772+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1583966015; cv=none; d=zohomail.com; s=zohoarc; b=VZRE4tITky+RkD4coaW4BF56GMddud0yIKgYy5KtkZEyr24Z7w8LVTEMF/YAfb9EkMrhkU2ZDcksVvssULfoEkDnsEmS4KOFyieDIX/J54a3m4hvIlmiPXNPMmjEosyKBQz3hpdj/3xVzsG8OF11tMIj3YnwDwkFTTFUi9RareI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583966015; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=qUzTL0pCzqxuYZo7XzREqAnHIU9oq0BSTwbodR/rRYs=; b=VMK1QrzGhD4l364zOSQCWrqZMo3MBCxSBFW2advzIfi2T7xeB/vMssD33e29vIXNKyHVRDKmi/Y2WOa3QEc78uSsER6wpD5E/U22v0TkvX3hLxOal3y1jUihE14Gl7wojw0oR+hNpzMk5c3K5/QJ6EvXJRiqHOAivN8Wvx3fqFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55772+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583966015262300.9937768708851; Wed, 11 Mar 2020 15:33:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 59XNYY1788612xvQecevfaH8; Wed, 11 Mar 2020 15:33:33 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.1380.1583966012953911577 for ; Wed, 11 Mar 2020 15:33:33 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Mar 2020 15:33:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,542,1574150400"; d="scan'208";a="389409834" X-Received: from aedesimo-desk.amr.corp.intel.com ([10.7.159.171]) by orsmga004.jf.intel.com with ESMTP; 11 Mar 2020 15:33:31 -0700 From: "Desimone, Ashley E" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya , Erik Bjorge Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Initial commit of the Create Pin command Date: Wed, 11 Mar 2020 15:33:29 -0700 Message-Id: <20200311223329.22952-1-ashley.e.desimone@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ashley.e.desimone@intel.com X-Gm-Message-State: 6iI0azjr9IKh1ajQFiITB05px1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583966013; bh=eG+Lua4sXQb+Jzt8ZaA31seloej+yWn5TPwrEL+dcLg=; h=Cc:Date:From:Reply-To:Subject:To; b=lsmZ6CogVyMggxYCrFTB8FVwfanA6rr1vrzUQmSU0jf3wZa93Cto2TziUnHwhfEBQfI EmaKIi43gQwgaEMoXrfdvh0rWQCKHFms78NyzpU1hitNrvg0bFj5m7bLJKTEOlch4Xsik 39T1zjTWKOIT1XCs7iSDoRqNaiiZynYjwSk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add edkrepo create-pin command allowing users to create a pin file to record their workspace status at a specific point in time. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Erik Bjorge Reviewed-by: Nate DeSimone --- edkrepo/commands/arguments/create_pin_args.py | 21 +++++ edkrepo/commands/create_pin_command.py | 127 ++++++++++++++++++++++= ++++ edkrepo/common/edkrepo_exception.py | 6 +- edkrepo/common/humble.py | 17 +++- 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 edkrepo/commands/arguments/create_pin_args.py create mode 100644 edkrepo/commands/create_pin_command.py diff --git a/edkrepo/commands/arguments/create_pin_args.py b/edkrepo/comman= ds/arguments/create_pin_args.py new file mode 100644 index 0000000..92958ef --- /dev/null +++ b/edkrepo/commands/arguments/create_pin_args.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# +## @file +# create_pin_command.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' Contains the help and description strings for arguments in the create = pin +command meta data. +''' + +COMMAND_DESCRIPTION =3D 'Creates a PIN file based on the current workspace= state' +NAME_HELP =3D ('The name of the PIN file. Extension must be .xml. File pat= hs are ' + 'supported only if the --push option is not used.') +DESCRIPTION_HELP =3D 'A short summary of the PIN file contents. Must be co= ntained in ""' +PUSH_HELP =3D ('Automatically commit and push the PIN file to the global m= anifest ' + 'repository at the location specified by the Pin-Path field i= n ' + 'the project manifest file.') + diff --git a/edkrepo/commands/create_pin_command.py b/edkrepo/commands/crea= te_pin_command.py new file mode 100644 index 0000000..df3fccc --- /dev/null +++ b/edkrepo/commands/create_pin_command.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +# +## @file +# create_pin_command.py +# +# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import os +from collections import namedtuple + +from git import Repo + +from edkrepo.commands.edkrepo_command import EdkrepoCommand +import edkrepo.commands.arguments.create_pin_args as arguments +from edkrepo.common.common_repo_functions import pull_latest_manifest_repo +from edkrepo.common.edkrepo_exception import EdkrepoManifestInvalidExcepti= on, EdkrepoInvalidParametersException +from edkrepo.common.edkrepo_exception import EdkrepoWorkspaceCorruptExcept= ion +from edkrepo.common.humble import WRITING_PIN_FILE, GENERATING_PIN_DATA, G= ENERATING_REPO_DATA, BRANCH, COMMIT +from edkrepo.common.humble import COMMIT_MESSAGE, PIN_PATH_NOT_PRESENT, PI= N_FILE_ALREADY_EXISTS, PATH_AND_FILEPATH_USED +from edkrepo.common.humble import MISSING_REPO +from edkrepo.config.config_factory import get_workspace_manifest, get_work= space_path +from edkrepo_manifest_parser.edk_manifest import ManifestXml + + +class CreatePinCommand(EdkrepoCommand): + def __init__(self): + super().__init__() + + def get_metadata(self): + metadata =3D {} + metadata['name'] =3D 'create-pin' + metadata['help-text'] =3D arguments.COMMAND_DESCRIPTION + metadata['alias'] =3D 'crp' + args =3D [] + metadata['arguments'] =3D args + args.append({'name' : 'PinFileName', + 'positional' : True, + 'position' : 0, + 'required' : True, + 'help-text' : arguments.NAME_HELP}) + args.append({'name' : 'Description', + 'positional' : True, + 'position' : 1, + 'required' : True, + 'help-text' : arguments.DESCRIPTION_HELP}) + args.append({'name': 'push', + 'positional': False, + 'required': False, + 'help-text': arguments.PUSH_HELP}) + return metadata + + def run_command(self, args, config): + # Check if --push and file path provided + if args.push and os.path.dirname(args.PinFileName): + raise EdkrepoInvalidParametersException(PATH_AND_FILEPATH_USED) + + pull_latest_manifest_repo(args, config) + workspace_path =3D get_workspace_path() + manifest =3D get_workspace_manifest() + + # If the push flag is enabled use general_config.pin_path to deter= mine global manifest relative location to save + # pin file to. + if args.push and manifest.general_config.pin_path is not None: + pin_dir =3D os.path.join(config['cfg_file'].manifest_repo_abs_= local_path, os.path.normpath(manifest.general_config.pin_path)) + pin_file_name =3D os.path.join(pin_dir, args.PinFileName) + elif args.push and manifest.general_config.pin_path is None: + raise EdkrepoManifestInvalidException(PIN_PATH_NOT_PRESENT) + # If not using the push flag ignore the local manifest's pin file = field and set the pinname/path =3D=3D to the file + # name provided. If a relative paths is provided save the file rel= ative to the current working directory. + elif not args.push and os.path.isabs(os.path.normpath(args.PinFile= Name)): + pin_file_name =3D os.path.normpath(args.PinFileName) + elif not args.push: + pin_file_name =3D os.path.abspath(os.path.normpath(args.PinFil= eName)) + # If the directory that the pin file is saved in does not exist cr= eate it and ensure pin file name uniqueness. + if os.path.isfile(pin_file_name): + raise EdkrepoInvalidParametersException(PIN_FILE_ALREADY_EXIST= S) + if not os.path.exists(os.path.dirname(pin_file_name)): + os.mkdir(os.path.dirname(pin_file_name)) + + repo_sources =3D manifest.get_repo_sources(manifest.general_config= .current_combo) + + # get the repo sources and commit ids for the pin + print(GENERATING_PIN_DATA.format(manifest.project_info.codename, m= anifest.general_config.current_combo)) + updated_repo_sources =3D [] + for repo_source in repo_sources: + local_repo_path =3D os.path.join(workspace_path, repo_source.r= oot) + if not os.path.exists(local_repo_path): + raise EdkrepoWorkspaceCorruptException(MISSING_REPO.format= (repo_source.root)) + repo =3D Repo(local_repo_path) + commit_id =3D repo.head.commit.hexsha + if args.verbose: + print(GENERATING_REPO_DATA.format(repo_source.root)) + print(BRANCH.format(repo_source.branch)) + print(COMMIT.format(commit_id)) + updated_repo_source =3D repo_source._replace(commit=3Dcommit_i= d) + updated_repo_sources.append(updated_repo_source) + + # create the pin + print(WRITING_PIN_FILE.format(pin_file_name)) + manifest.generate_pin_xml(args.Description, manifest.general_confi= g.current_combo, updated_repo_sources, + filename=3Dpin_file_name) + + # commit and push the pin file + if args.push: + manifest_repo =3D Repo(config['cfg_file'].manifest_repo_abs_lo= cal_path) + # Create a local branch with the same name as the pin file arg= and check it out before attempting the push + # to master + master_branch =3D manifest_repo.active_branch + local_branch =3D manifest_repo.create_head(args.PinFileName) + manifest_repo.heads[local_branch.name].checkout() + manifest_repo.git.add(pin_file_name) + manifest_repo.git.commit(m=3DCOMMIT_MESSAGE.format(manifest.pr= oject_info.codename, args.Description)) + # Try to push if the push fails re update the manifest repo an= d rebase from master + try: + manifest_repo.git.push('origin', 'HEAD:master') + except: + manifest_repo.heads[master_branch.name].checkout() + origin =3D manifest_repo.remotes.origin + origin.pull() + manifest_repo.heads[local_branch.name].checkout() + manifest_repo.git.rebase('master') + manifest_repo.git.push('origin', 'HEAD:master') + finally: + manifest_repo.heads[master_branch.name].checkout() + manifest_repo.delete_head(local_branch, '-D') \ No newline at end of file diff --git a/edkrepo/common/edkrepo_exception.py b/edkrepo/common/edkrepo_e= xception.py index 9d2b102..b6ea3dd 100644 --- a/edkrepo/common/edkrepo_exception.py +++ b/edkrepo/common/edkrepo_exception.py @@ -3,7 +3,7 @@ ## @file # edkrepo_exception.py # -# Copyright (c) 2017- 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017- 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -74,6 +74,10 @@ class EdkrepoFoundMultipleException(EdkrepoException): def __init__(self, message): super().__init__(message, 117) =20 +class EdkrepoWorkspaceCorruptException(EdkrepoException): + def __ini__(self, message): + super().__init__(message, 118) + class EdkrepoWarningException(EdkrepoException): def __init__(self, message): super().__init__(message, 123) diff --git a/edkrepo/common/humble.py b/edkrepo/common/humble.py index f0fbd29..5326e88 100644 --- a/edkrepo/common/humble.py +++ b/edkrepo/common/humble.py @@ -3,7 +3,7 @@ ## @file # humble.py # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -147,3 +147,18 @@ VERIFY_PROJ_FAIL =3D 'Unable to verify the global mani= fest repository entry for pr =20 # Git Command Error Messages GIT_CMD_ERROR =3D 'The git command: {} failed to complete successfully wit= h the following errors.\n' + +# Error messages for create_pin_command.py +CREATE_PIN_EXIT =3D 'Exiting without creating pin file ...' +PIN_PATH_NOT_PRESENT =3D 'Pin Path not present in Manifest.xml ' + CREATE_= PIN_EXIT +PIN_FILE_ALREADY_EXISTS =3D 'A pin file with that name already exists for = this project. Please rerun the command with a new filename. ' + CREATE_PIN_= EXIT +PATH_AND_FILEPATH_USED =3D 'Providing a file path for the PinFileName argu= ment is not supported when using the --push flag. ' + CREATE_PIN_EXIT +MISSING_REPO =3D 'The {} repository is missing from your workspace. ' + CR= EATE_PIN_EXIT + +# Informational messages for create_pin_command.py +GENERATING_PIN_DATA =3D 'Generating pin data for {0} project based on {1} = combination ...' +GENERATING_REPO_DATA =3D 'Generating pin data for {0} repo:' +BRANCH =3D ' Branch : {0}' +COMMIT =3D ' Commit Id: {0}' +WRITING_PIN_FILE =3D 'Writing pin file to {0} ...' +COMMIT_MESSAGE =3D 'Pin file for project: {0} \nPin Description: {1}' --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55772): https://edk2.groups.io/g/devel/message/55772 Mute This Topic: https://groups.io/mt/71890604/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-