Commits

Travis Shirk  committed 0be1568

Use of eyed3.utils.console

  • Participants
  • Parent commits 3b59bf1
  • Branches stable

Comments (0)

Files changed (7)

File src/eyed3/main.py

 import textwrap
 import eyed3
 import eyed3.utils
-import eyed3.utils.cli
+import eyed3.utils.console
 import eyed3.plugins
 import eyed3.info
 from eyed3.compat import ConfigParser, ConfigParserError, StringIO
 
 
 def _listPlugins(config):
-    from eyed3.utils.cli import GREEN, GREY, boldText
+    from eyed3.utils.console import Fore, Style
 
     print("")
 
     def header(name):
         is_default = name == DEFAULT_PLUGIN
-        return (boldText("* ", c=GREEN if is_default else None) +
-                boldText(name, c=None))
+        return (Style.BRIGHT + (Fore.GREEN if is_default else '') + "* " +
+                name + Style.RESET_ALL)
 
     all_plugins = eyed3.plugins.load(reload=True, paths=_getPluginPath(config))
     # Create a new dict for sorted display
         for l in textwrap.wrap(plugin.SUMMARY,
                                initial_indent=' ' * 2,
                                subsequent_indent=' ' * 2):
-            print(boldText(l, c=GREY))
+            print(Style.BRIGHT + Fore.GREY + l + Style.RESET_ALL)
         print("")
 
 
 
 
 def makeCmdLineParser(subparser=None):
-    from eyed3.utils.cli import ArgumentParser
+    from eyed3.utils import ArgumentParser
 
     p = (ArgumentParser(prog=eyed3.info.NAME, add_help=True)
             if not subparser else subparser)
 
     PluginClass = eyed3.plugins.load(plugin_name, paths=_getPluginPath(config))
     if PluginClass is None:
-        eyed3.utils.cli.printError("Plugin not found: %s" % plugin_name)
+        eyed3.utils.console.printError("Plugin not found: %s" % plugin_name)
         parser.exit(1)
     plugin = PluginClass(parser)
 
 
     try:
         args, _, config = parseCommandLine()
-
-        for fp in [sys.stdout, sys.stderr]:
-            color = not args.no_color and os.isatty(fp.fileno())
-            eyed3.utils.cli.enableColorOutput(fp, color)
+        eyed3.utils.console.USE_ANSI = not args.no_color
 
         mainFunc = main if args.debug_profile is False else profileMain
         retval = mainFunc(args, config)
     except KeyboardInterrupt:
         retval = 0
     except IOError as ex:
-        eyed3.utils.cli.printError(ex)
+        eyed3.utils.console.printError(ex)
     except Exception as ex:
-        eyed3.utils.cli.printError("Uncaught exception: %s\n" % str(ex))
+        eyed3.utils.console.printError("Uncaught exception: %s\n" % str(ex))
         eyed3.log.exception(ex)
 
         if args.debug_pdb:

File src/eyed3/plugins/classic.py

 from eyed3 import LOCAL_ENCODING
 from eyed3.plugins import LoaderPlugin
 from eyed3 import core, id3, mp3, utils
-from eyed3.utils.cli import (printMsg, printError, printWarning, boldText,
-                             getColor, RESET, HEADER_COLOR)
+from eyed3.utils.console import (printMsg, printError, printWarning, boldText,
+                                 HEADER_COLOR, Fore)
 from eyed3.id3.frames import ImageFrame
 
 import logging
         file_size = os.stat(file_path)[ST_SIZE]
         size_str = utils.formatSize(file_size)
         printMsg("%s\t%s[ %s ]%s" %
-                 (boldText(os.path.basename(file_path), c=HEADER_COLOR),
-                  getColor(HEADER_COLOR), size_str, getColor(RESET)))
+                 (boldText(os.path.basename(file_path), c=HEADER_COLOR()),
+                  HEADER_COLOR(), size_str, Fore.RESET))
 
     def printAudioInfo(self, info):
         if isinstance(info, mp3.Mp3AudioInfo):

File src/eyed3/plugins/examples.py

 import math, os
 from eyed3 import core
 from eyed3.plugins import Plugin, LoaderPlugin
-from eyed3.utils.cli import printMsg
+from eyed3.utils.console import printMsg
 
 
 class GenreListPlugin(Plugin):

File src/eyed3/plugins/lameinfo.py

 import os
 from eyed3 import LOCAL_ENCODING as ENCODING
 from eyed3.utils import formatSize, formatTime
-from eyed3.utils.cli import (printMsg, printError, printWarning, boldText,
-                             getColor, RESET, HEADER_COLOR)
+from eyed3.utils.console import (printMsg, printError, printWarning, boldText,
+                                 Fore, HEADER_COLOR)
 from eyed3.plugins import LoaderPlugin
 
 class LameInfoPlugin(LoaderPlugin):
         fileSize = os.stat(filePath)[ST_SIZE]
         size_str = formatSize(fileSize).encode(ENCODING)
         print("\n%s\t%s[ %s ]%s" % (boldText(os.path.basename(filePath),
-                                             HEADER_COLOR),
-                                    getColor(HEADER_COLOR), size_str,
-                                    getColor(RESET)))
+                                             HEADER_COLOR()),
+                                    HEADER_COLOR(), size_str,
+                                    Fore.RESET))
         print("-" * 79)
 
     def handleFile(self, f):

File src/eyed3/plugins/nfo.py

 from __future__ import print_function
 import time
 from eyed3 import LOCAL_ENCODING as ENCODING
-from eyed3.utils.cli import printMsg, printError
+from eyed3.utils.console import printMsg, printError
 from eyed3.utils import formatSize, formatTime
 from eyed3.info import VERSION
 from eyed3.id3 import versionToString

File src/eyed3/plugins/statistics.py

 
 from eyed3 import id3, mp3
 from eyed3.core import AUDIO_MP3
-from eyed3.utils import guessMimetype, cli
+from eyed3.utils import guessMimetype
+from eyed3.utils.console import Fore, Style, printMsg
 from eyed3.plugins import LoaderPlugin
 
 ID3_VERSIONS = [id3.ID3_V1_0, id3.ID3_V1_1,
                     "key":   str(key_name).ljust(key_col_width),
                     "value": str(value).rjust(val_col_width),
                     "percent": " ( %s%.2f%%%s )" %
-                                 (cli.GREEN, percent, cli.RESET) if percent
-                                                                 else "",
+                                 (Fore.GREEN, percent, Fore.RESET) if percent
+                                                                   else "",
                   })
 
     def percent(self, key):
             self[self.OTHER_FILES] += 1
 
     def _report(self):
-        print(cli.BOLD + cli.GREY + "Files:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "Files:" + Style.RESET_ALL)
         super(FileCounterStat, self)._report()
 
 
         self[mt] += 1
 
     def _report(self):
-        print(cli.BOLD + cli.GREY + "Mime-Types:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "Mime-Types:" + Style.RESET_ALL)
         super(MimeTypeStat, self)._report(most_common=True)
 
 
             self[None] += 1
 
     def _report(self):
-        print(cli.BOLD + cli.GREY + "ID3 versions:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "ID3 versions:" + Style.RESET_ALL)
         super(Id3VersionCounter, self)._report()
 
 
                 self[frame_id] += len(audio_file.tag.frame_set[frame_id])
 
     def _report(self):
-        print(cli.BOLD + cli.GREY + "ID3 frames:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "ID3 frames:" + Style.RESET_ALL)
         super(Id3FrameCounter, self)._report(most_common=True)
 
 
                 break
 
     def _report(self):
-        print(cli.BOLD + cli.GREY + "MP3 bitrates:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "MP3 bitrates:" + Style.RESET_ALL)
         super(BitrateCounter, self)._report(most_common=True)
 
     def _sortedKeys(self, most_common=False):
 
 class RuleViolationStat(Stat):
     def _report(self):
-        print(cli.BOLD + cli.GREY + "Rule Violations:" + cli.RESET)
+        print(Style.BRIGHT + Fore.GREY + "Rule Violations:" + Style.RESET_ALL)
         super(RuleViolationStat, self)._report(most_common=True)
 
 
         # Detailed rule violations
         if self.args.verbose:
             for path in self._rules_log:
-                cli.printMsg(path) # does the right thing for unicode
+                printMsg(path) # does the right thing for unicode
                 for score, text in self._rules_log[path]:
-                    print("\t%s%s%s (%s)" % (cli.RED, str(score).center(3),
-                                             cli.RESET, text))
+                    print("\t%s%s%s (%s)" % (Fore.RED, str(score).center(3),
+                                             Fore.RESET, text))
 
         def prettyScore():
             score = float(self._score_sum) / float(self._score_count)
             if score > 80:
-                color = cli.GREEN
+                color = Fore.GREEN
             elif score > 70:
-                color = cli.YELLOW
+                color = Fore.YELLOW
             else:
-                color = cli.RED
+                color = Fore.RED
             return (score, color)
 
         score, color = prettyScore()
-        print("%sScore%s = %s%d%%%s" % (cli.BOLD, cli.BOLD_OFF,
-                                        color, score, cli.RESET))
+        print("%sScore%s = %s%d%%%s" % (Style.BRIGHT, Style.RESET_BRIGHT,
+                                        color, score, Fore.RESET))
         if not self.args.verbose:
             print("Run with --verbose to see files and their rule violations")
         print()

File src/eyed3/plugins/xep_118.py

 ################################################################################
 import os
 
-from eyed3.utils.cli import printMsg, printError
+from eyed3.utils.console import printMsg, printError
 from eyed3.plugins import LoaderPlugin
 
 class Xep118Plugin(LoaderPlugin):