From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.2171.1587683401614848289 for ; Thu, 23 Apr 2020 16:10:01 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: YL8cdiXgrr3kHzhHC+SXJOJRC8eWQQfudXZouw7HV4H9YJk607iQdxUkwwiYfJphGEgTvIeSLw 4lK3iObIqvgg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2020 16:10:00 -0700 IronPort-SDR: /46BRh/oicaX2oxDmsK5M4THf1cqd7//ihvn15E8G+mZXMA0h10KaYX+nsKAHaWcxDP5dV0Azy NzbK1Vt49cbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,309,1583222400"; d="scan'208";a="430533035" Received: from aedesimo-desk.amr.corp.intel.com ([10.7.159.171]) by orsmga005.jf.intel.com with ESMTP; 23 Apr 2020 16:10:00 -0700 From: "Ashley E Desimone" To: devel@edk2.groups.io Cc: Nate DeSimone , Puja Pandya , Erik Bjorge , Bret Barkelew , Prince Agyeman Subject: [edk2-staging/EdkRepo] [PATCH V5 2/3] EdkRepo: Add edkrepo/common/workspace_maintenance/manifest_repos_maintenance Date: Thu, 23 Apr 2020 16:09:56 -0700 Message-Id: <20200423230957.38936-3-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200423230957.38936-1-ashley.e.desimone@intel.com> References: <20200423230957.38936-1-ashley.e.desimone@intel.com> Add a directory to edkrepo/common to store workspace maintenance functionatlity. Add edkrepo/common/workspace_maintenance/humble directory to store related strings and included manifest_repos_maintenance_humble.py Add edkrepo/common/workspace_maintenance/manifest_repos_maitenance.py to support the mmaintenance of multiple manifest repositories. Added pull_single_manifest_repo() to manifest_repos_maintenance.py Updated setup.py to include the new directories. Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Erik Bjorge Cc: Bret Barkelew Cc: Prince Agyeman --- .../humble/manifest_repos_maintenance_humble.py | 23 +++++++++ .../manifest_repos_maintenance.py | 59 ++++++++++++++++++++++ setup.py | 3 +- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 edkrepo/common/workspace_maintenance/humble/manifest_repos_maintenance_humble.py create mode 100644 edkrepo/common/workspace_maintenance/manifest_repos_maintenance.py diff --git a/edkrepo/common/workspace_maintenance/humble/manifest_repos_maintenance_humble.py b/edkrepo/common/workspace_maintenance/humble/manifest_repos_maintenance_humble.py new file mode 100644 index 0000000..440fd8a --- /dev/null +++ b/edkrepo/common/workspace_maintenance/humble/manifest_repos_maintenance_humble.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# +## @file +# manifest_repos_maintenance_humble.py +# +# Copyright (c) 2017- 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' Contains user facing strings for manifest_repos_mgmt.py ''' + +from colorama import Fore +from colorama import Style + +CLONE_SINGLE_MAN_REPO = 'Cloning global manifest repository to: {} from: {}' +SYNC_SINGLE_MAN_REPO = 'Syncing the global manifest repository: {}' +SINGLE_MAN_REPO_DIRTY = ('Uncommited changes present in the global manifest ' + 'repository: {} Resolve these changes and attempt your' + ' operation again.') +SINGLE_MAN_REPO_NOT_CFG_BRANCH = ('The current active branch, {}, is not the ' + 'specified branch for global manifst repository: {}') +SINGLE_MAN_REPO_CHECKOUT_CFG_BRANCH = 'Checking out the specified branch: {} prior to syncing' +SINGLE_MAN_REPO_MOVED = '{}{}WARNING:{}{} The global manifest repository has moved. Backing up previous global manifest repository to: {{}}{}\n'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED, Style.RESET_ALL) diff --git a/edkrepo/common/workspace_maintenance/manifest_repos_maintenance.py b/edkrepo/common/workspace_maintenance/manifest_repos_maintenance.py new file mode 100644 index 0000000..6e26d4f --- /dev/null +++ b/edkrepo/common/workspace_maintenance/manifest_repos_maintenance.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# +## @file +# manifest_repos_maintenance.py +# +# Copyright (c) 2017- 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import os +import traceback +import shutil + +import git +from git import Repo + +import edkrepo.config.config_factory as cfg +from edkrepo.common.edkrepo_exception import EdkrepoUncommitedChangesException +from edkrepo.common.progress_handler import GitProgressHandler +import edkrepo.common.workspace_maintenance.humble.manifest_repos_maintenance_humble as humble +from edkrepo.common.workspace_maintenance.workspace_maintenance import generate_name_for_obsolete_backup + + +def pull_single_manifest_repo(url, branch, local_path, reset_hard=False): + ''' + Clones or syncs a single global manifest repository as defined in either + the edkrepo.cfg or the edkrepo_user.cfg + ''' + # If a relative path is used join to the edkrepo global data directory path + if not os.path.isabs(local_path): + local_path = os.path.join(cfg.get_edkrepo_global_data_directory(), local_path) + # Clone the repository if it does not exist locally + if not os.path.exists(local_path): + print(humble.CLONE_SINGLE_MAN_REPO.format(local_path, url)) + repo = Repo.clone_from(url, local_path, progress=GitProgressHandler(), branch=branch) + # Sync the repository if it exists locally + else: + repo = Repo(local_path) + if url in repo.remotes['origin'].urls: + if repo.is_dirty(untracked_files=True) and not reset_hard: + raise EdkrepoUncommitedChangesException(humble.SINGLE_MAN_REPO_DIRTY.format(local_path)) + elif repo.is_dirty(untracked_files=True) and reset_hard: + repo.git.reset('--hard') + print(humble.SYNC_SINGLE_MAN_REPO.format(local_path)) + if repo.active_branch.name != branch: + print(humble.SINGLE_MAN_REPO_NOT_CFG_BRANCH.format(repo.active_branch.name, local_path)) + print(humble.SINGLE_MAN_REPO_CHECKOUT_CFG_BRANCH.format(branch)) + repo.git.checkout(branch) + repo.remotes.origin.pull() + # If the URL specified for this manifest repo has moved back up the existing + # local copy and clone the new repository + else: + new_path = generate_name_for_obsolete_backup(local_path) + new_path = os.path.join(os.path.dirname(local_path), new_path) + print(humble.SINGLE_MAN_REPO_MOVED.format(new_path)) + shutil.move(local_path, new_path) + print (humble.CLONE_SINGLE_MAN_REPO.format(local_path, url)) + repo = Repo.clone_from(url, local_path, progress=GitProgressHandler(), branch=branch) + diff --git a/setup.py b/setup.py index af173bb..5053b1a 100755 --- a/setup.py +++ b/setup.py @@ -13,7 +13,8 @@ setup(name='edkrepo', description='The edkrepo tools', packages=['edkrepo', 'edkrepo.commands', 'edkrepo.commands.arguments', 'edkrepo.commands.humble', 'edkrepo.git_automation', 'edkrepo.common', 'edkrepo.common.workspace_maintenance', - 'edkrepo.config', 'edkrepo.config.humble', 'edkrepo_manifest_parser', 'project_utils'], + 'edkrepo.common.workspace_maintenance.humble', 'edkrepo.config', 'edkrepo.config.humble', + 'edkrepo_manifest_parser', 'project_utils'], package_data={ }, include_package_data=True, -- 2.16.2.windows.1