Browse Source

Merge branch 'handle_debug_env_vars' of DebenOldert/Music-Downloader into master

Deben Oldert 6 năm trước cách đây
mục cha
commit
8d2b759c80
3 tập tin đã thay đổi với 21 bổ sung8 xóa
  1. 3 3
      console.py
  2. 14 5
      main.py
  3. 4 0
      settings.py

+ 3 - 3
console.py

@@ -1,8 +1,7 @@
 import sys
 import sys
 
 
 import colorama as color
 import colorama as color
-
-DEBUG_LEVEL = 2
+from settings import Settings
 
 
 OUTPUT = 0
 OUTPUT = 0
 DBG_ERROR = 1
 DBG_ERROR = 1
@@ -14,12 +13,13 @@ CACHE = []
 
 
 color.init(True)
 color.init(True)
 
 
+
 def output(text='', level=OUTPUT, end='\n'):
 def output(text='', level=OUTPUT, end='\n'):
     if LOCKED:
     if LOCKED:
         CACHE.append((text, level, end))
         CACHE.append((text, level, end))
         return
         return
 
 
-    if level <= DEBUG_LEVEL:
+    if level <= Settings.Debuglvl:
 
 
         if level == 1:
         if level == 1:
             text = color.Fore.RED + '[ERROR] ' + text
             text = color.Fore.RED + '[ERROR] ' + text

+ 14 - 5
main.py

@@ -4,12 +4,22 @@ import os.path
 from settings import Settings
 from settings import Settings
 
 
 
 
-def main():
-    console.output('Music downloader by Deben Oldert')
-    console.output()
+def init():
+    dbg_lvl = os.getenv('MD_LOGGING', 'ERROR')
+
+    if dbg_lvl.lower() == 'info':
+        Settings.Debuglvl = console.DBG_INFO
+    else:
+        Settings.Debuglvl = console.DBG_ERROR
 
 
     directory(os.getenv('MD_SAVEDIR', '~/Music/iTunes/iTunes Media/Automatically Add to iTunes'))
     directory(os.getenv('MD_SAVEDIR', '~/Music/iTunes/iTunes Media/Automatically Add to iTunes'))
 
 
+
+def main():
+    init()
+
+    console.output('Music downloader by Deben Oldert')
+    console.output()
     console.output('Download directory: {0}'.format(Settings.SaveDir))
     console.output('Download directory: {0}'.format(Settings.SaveDir))
     console.output()
     console.output()
     help()
     help()
@@ -115,6 +125,7 @@ def directory(dir=None):
     if dir is None:
     if dir is None:
         dir = console.ask_input('Enter new save directory')
         dir = console.ask_input('Enter new save directory')
     Settings.SaveDir = os.path.expanduser(dir)
     Settings.SaveDir = os.path.expanduser(dir)
+    console.output('New save directory: {0}'.format(Settings.SaveDir), level=console.DBG_INFO)
     return True
     return True
 
 
 
 
@@ -145,8 +156,6 @@ commands = [
     ('quit', quit, 'Quit the program')
     ('quit', quit, 'Quit the program')
 ]
 ]
 
 
-# DOWNLOAD_DIR = os.path.expanduser('~/Music/iTunes/iTunes Media/Automatically Add to iTunes')
-# DOWNLOAD_DIR = os.path.expanduser('~/Downloads')
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     main()
     main()

+ 4 - 0
settings.py

@@ -1,2 +1,6 @@
+import console as console
+
+
 class Settings:
 class Settings:
     SaveDir = None
     SaveDir = None
+    Debuglvl = None