From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.5377.1587598161246945471 for ; Wed, 22 Apr 2020 16:29:21 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: ashley.e.desimone@intel.com) IronPort-SDR: jqM5t26akchRsc0vhFHNis4XjrPd6u+B/OKgzYOgFaskw0/YkLnPivq5dq/c6Kq5nDpfhz4Egy 2P3K2hHnQSCw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 16:29:20 -0700 IronPort-SDR: 7ZL7JOeSwFzHPH7rXYXPUmQjyD+yHbrBWV7uzFxmcNOsrKYhXurjy4aEr60K4QcPYwSGen7rMh bwlP5HJqBAwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,304,1583222400"; d="scan'208";a="259238870" Received: from aedesimo-desk.amr.corp.intel.com ([10.7.159.171]) by orsmga006.jf.intel.com with ESMTP; 22 Apr 2020 16:29:20 -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 V3 1/3] EdkRepo: Initial commit of workspace_maitenance.py Date: Wed, 22 Apr 2020 16:29:13 -0700 Message-Id: <20200422232915.18640-2-ashley.e.desimone@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200422232915.18640-1-ashley.e.desimone@intel.com> References: <20200422232915.18640-1-ashley.e.desimone@intel.com> Add workspace_maitenance.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_maitenance/workspace_maitenance.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 edkrepo/common/workspace_maitenance/workspace_maitenance.py diff --git a/edkrepo/common/workspace_maitenance/workspace_maitenance.py b/edkrepo/common/workspace_maitenance/workspace_maitenance.py new file mode 100644 index 0000000..83204f8 --- /dev/null +++ b/edkrepo/common/workspace_maitenance/workspace_maitenance.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# +## @file +# workspace_maitenance.py +# +# Copyright (c) 2017- 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' Contains shared workspace maitenance 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 -- 2.16.2.windows.1