File logging.patch of Package multibootusb-devel

From a1922b871daf28decc4bc59704f0cc0e78c705ad Mon Sep 17 00:00:00 2001
From: Shinji Suzuki <shinji.suzuki@gmail.com>
Date: Wed, 9 May 2018 02:49:49 +0900
Subject: [PATCH] Delay initialisation of the python logging so that running
 setup.py under unpriviledged user will not raise an exception.

---
 multibootusb        |  3 +++
 scripts/osdriver.py | 16 ++++++++--------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/multibootusb b/multibootusb
index 7535314..9ff7406 100644
--- a/multibootusb
+++ b/multibootusb
@@ -33,12 +33,14 @@ try:
     from scripts import admin
     from scripts import gen
     from scripts import config
+    from scripts import osdriver
 except ImportError:
     try:
         from .scripts.mbusb_cli import *
         from .scripts import admin
         from .scripts import gen
         from .scripts import config
+        from .scripts import osdriver
     except ImportError:
         import scripts
 
@@ -219,6 +221,7 @@ def main():
 
 
 if __name__ == '__main__':
+    osdriver.init_logging()
     try:
         main()
     finally:
diff --git a/scripts/osdriver.py b/scripts/osdriver.py
index ca0ef39..9d03c91 100644
--- a/scripts/osdriver.py
+++ b/scripts/osdriver.py
@@ -131,11 +131,11 @@ def mbusb_log_file(self):
         ]:
     globals()[func_name] = getattr(osdriver, func_name)
 
-
-logging.root.setLevel(logging.DEBUG)
-fmt = '%(asctime)s.%(msecs)03d %(name)s %(levelname)s %(message)s'
-datefmt = '%H:%M:%S'
-the_handler = logging.handlers.RotatingFileHandler(
-    osdriver.mbusb_log_file(), 'a', 1024*1024, 5)
-the_handler.setFormatter(logging.Formatter(fmt, datefmt))
-logging.root.addHandler(the_handler)
+def init_logging():
+    logging.root.setLevel(logging.DEBUG)
+    fmt = '%(asctime)s.%(msecs)03d %(name)s %(levelname)s %(message)s'
+    datefmt = '%H:%M:%S'
+    the_handler = logging.handlers.RotatingFileHandler(
+        osdriver.mbusb_log_file(), 'a', 1024*1024, 5)
+    the_handler.setFormatter(logging.Formatter(fmt, datefmt))
+    logging.root.addHandler(the_handler)
openSUSE Build Service is sponsored by