[virt-tools-list] [virt-manager PATCH 01/12] util: Add {make, get}_unattended_cache_dir()

Fabiano Fidêncio fidencio at redhat.com
Thu Jun 6 14:11:32 UTC 2019


The "make" method will help to create a "unattended" dir based on the
virt-install process id, so we can store unattended installations
related files without the possibility of another process overwritting
the files.

The "get" method will help to clean up the dirs created by the "make"
method.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/util.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/virtinst/util.py b/virtinst/util.py
index 7219d49f..d8b19b7e 100644
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -271,6 +271,19 @@ def get_cache_dir():
     return os.path.join(ret, "virt-manager")
 
 
+def get_unattended_cache_dir():
+    pid = str(os.getpid())
+    return os.path.join(get_cache_dir(), pid, "unattended")
+
+
+def make_unattended_cache_dir():
+    scratch = get_unattended_cache_dir()
+    if not os.path.exists(scratch):
+        os.makedirs(scratch, 0o751)
+
+    return scratch
+
+
 def register_libvirt_error_handler():
     """
     Ignore libvirt error reporting, we just use exceptions
-- 
2.21.0




More information about the virt-tools-list mailing list