Browse Source

make discid a non required dependency

master
Dirk Alders 1 month ago
parent
commit
a9b16a8a72
3 changed files with 20 additions and 2 deletions
  1. 1
    1
      CDDB.py
  2. 15
    1
      common.py
  3. 4
    0
      metadata.py

+ 1
- 1
CDDB.py View File

18
 if 'EMAIL' in os.environ:
18
 if 'EMAIL' in os.environ:
19
     (default_user, hostname) = os.environ['EMAIL'].split('@')
19
     (default_user, hostname) = os.environ['EMAIL'].split('@')
20
 else:
20
 else:
21
-    default_user = os.environ['USER'] or os.geteuid() or 'user'
21
+    default_user = os.environ.get('USER') or os.geteuid() or 'user'
22
     hostname = socket.gethostname() or 'host'
22
     hostname = socket.gethostname() or 'host'
23
 
23
 
24
 proto = 6
24
 proto = 6

+ 15
- 1
common.py View File

1
 import os
1
 import os
2
-import discid
2
+import logging
3
+
4
+try:
5
+    from config import APP_NAME as ROOT_LOGGER_NAME
6
+except ImportError:
7
+    ROOT_LOGGER_NAME = 'root'
8
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
9
+
10
+# make module usable without discid dependency
11
+try:
12
+    import discid
13
+except ModuleNotFoundError:
14
+    logger.warning("Python module discid not installed")
15
+except OSError:
16
+    logger.exception("You might install python3-libdiscid")
3
 
17
 
4
 KEY_ALBUM = 'album'
18
 KEY_ALBUM = 'album'
5
 KEY_APERTURE = 'aperture'
19
 KEY_APERTURE = 'aperture'

+ 4
- 0
metadata.py View File

14
 except ImportError:
14
 except ImportError:
15
     ROOT_LOGGER_NAME = 'root'
15
     ROOT_LOGGER_NAME = 'root'
16
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
16
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
17
+
18
+# make module usable without discid dependency
17
 try:
19
 try:
18
     import discid
20
     import discid
21
+except ModuleNotFoundError:
22
+    logger.warning("Python module discid not installed")
19
 except OSError:
23
 except OSError:
20
     logger.exception("You might install python3-libdiscid")
24
     logger.exception("You might install python3-libdiscid")
21
 
25
 

Loading…
Cancel
Save