Add workspace_maitenance.py including the implementation
of generate_name_for_obsolete_backup()
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>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
---
.../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.<BR>
+# 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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#57878): https://edk2.groups.io/g/devel/message/57878
Mute This Topic: https://groups.io/mt/73207042/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-