[edk2-devel] [edk2-staging/EdkRepo] [PATCH V3 1/3] EdkRepo: Initial commit of workspace_maitenance.py

Ashley E Desimone posted 3 patches 5 years, 9 months ago
There is a newer version of this series
[edk2-devel] [edk2-staging/EdkRepo] [PATCH V3 1/3] EdkRepo: Initial commit of workspace_maitenance.py
Posted by Ashley E Desimone 5 years, 9 months ago
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 (#57884): https://edk2.groups.io/g/devel/message/57884
Mute This Topic: https://groups.io/mt/73209016/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-staging/EdkRepo] [PATCH V3 1/3] EdkRepo: Initial commit of workspace_maitenance.py
Posted by Nate DeSimone 5 years, 9 months ago
Hi Ashley,

There is a misspelling, "maitenance" should be "maintenance". Other than that, looks good.

Thanks,
Nate

On 4/22/20, 4:29 PM, "Desimone, Ashley E" <ashley.e.desimone@intel.com> wrote:

    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 (#57991): https://edk2.groups.io/g/devel/message/57991
Mute This Topic: https://groups.io/mt/73209016/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-