[elbe-devel] [PATCH] filesystem: add debug mode Parameter to TmpdirFilesystem

Manuel Traut manut at linutronix.de
Fri Oct 12 16:34:02 CEST 2018


From: Torben Hohn <torben.hohn at linutronix.de>

> debugging things, that happen in TmpdirFilesystem, is not really
> possible.
> 
> Add a debug parameter to TmpdirFilesystem.__init__() that makes
> it leave the directory undeleted, and also makes it print out
> the path to the directory.
> 
> Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
Signed-off-by: Manuel Traut <manut at linutronix.de>

basicly OK, reworked a bit (see below) and applied.

---
 elbepack/filesystem.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index c0089173..36e006e6 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -4,6 +4,8 @@
 #
 # SPDX-License-Identifier: GPL-3.0-or-later
 
+from __future__ import print_function
+
 import os
 import shutil
 
@@ -239,12 +241,17 @@ class Filesystem(object):
 
 
 class TmpdirFilesystem (Filesystem):
-    def __init__(self):
+    def __init__(self, debug=False):
         tmpdir = mkdtemp()
         Filesystem.__init__(self, tmpdir)
+        self.debug = debug
 
     def __del__(self):
-        shutil.rmtree(self.path, True)
+        # dont delete files in debug mode
+        if self.debug:
+            print('leaving TmpdirFilesystem in "%s"' % self.path)
+        else:
+            shutil.rmtree(self.path, True)
 
 
 hostfs = Filesystem('/')
-- 
2.19.1




More information about the elbe-devel mailing list