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.2173.1587683402016859444 for ; Thu, 23 Apr 2020 16:10:02 -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: 3PB+j9GzP7oFqQ8K8hyoRQCpufu931FpS9pO4Yx3GvCOp4teaMVDuzOLbV9FNWyEBtM1U6kGb1 GIstTKf1WB8g== 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: UmqBnV2X/QWTVz8bMTLBcgfwclsEgeCYUAQa85uC7dSbuhjGJ7kfij9jHB2UO/JNKxHo7Li5DH gf3DW/L8emcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,309,1583222400"; d="scan'208";a="430533032" 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 1/3] EdkRepo: Initial commit of workspace_maintenance.py Date: Thu, 23 Apr 2020 16:09:55 -0700 Message-Id: <20200423230957.38936-2-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 workspace_maintenance.py including the implementation of generate_name_for_obsolete_backup() Signed-off-by: Ashley E Desimone Cc: Nate DeSimone Cc: Puja Pandya Cc: Erik Bjorge Cc: Bret Barkelew Cc: Prince Agyeman --- .../workspace_maintenance/workspace_maintenance.py | 30 ++++++++++++++++++++++ setup.py | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 edkrepo/common/workspace_maintenance/workspace_maintenance.py diff --git a/edkrepo/common/workspace_maintenance/workspace_maintenance.py b/edkrepo/common/workspace_maintenance/workspace_maintenance.py new file mode 100644 index 0000000..d45759a --- /dev/null +++ b/edkrepo/common/workspace_maintenance/workspace_maintenance.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# +## @file +# workspace_maintenance.py +# +# Copyright (c) 2017- 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' Contains shared workspace maintenance functions. ''' + +import os + +def generate_name_for_obsolete_backup(absolute_path): + if not os.path.exists(absolute_path): + raise ValueError("{} does not exist".format(absolute_path)) + original_name = os.path.basename(absolute_path) + dir_name = os.path.dirname(absolute_path) + unique_name = "" + unique_name_found = False + index = 1 + while not unique_name_found: + if index == 1: + unique_name = "{}_old".format(original_name) + else: + unique_name = "{}_old{}".format(original_name, index) + if not os.path.exists(os.path.join(dir_name, unique_name)): + unique_name_found = True + index += 1 + return unique_name \ No newline at end of file diff --git a/setup.py b/setup.py index 06a382b..af173bb 100755 --- a/setup.py +++ b/setup.py @@ -12,8 +12,8 @@ setup(name='edkrepo', version='2.0.0', description='The edkrepo tools', packages=['edkrepo', 'edkrepo.commands', 'edkrepo.commands.arguments', 'edkrepo.commands.humble', - 'edkrepo.git_automation', 'edkrepo.common', 'edkrepo.config', 'edkrepo.config.humble', - 'edkrepo_manifest_parser', 'project_utils'], + 'edkrepo.git_automation', 'edkrepo.common', 'edkrepo.common.workspace_maintenance', + 'edkrepo.config', 'edkrepo.config.humble', 'edkrepo_manifest_parser', 'project_utils'], package_data={ }, include_package_data=True, -- 2.16.2.windows.1