Travis Shirk avatar Travis Shirk committed b2c9703

Removed. All moved to eyed3.utils or eyed3.utils.console

Comments (0)

Files changed (1)

src/eyed3/utils/cli.py

-# -*- coding: utf-8 -*-
-################################################################################
-#  Copyright (C) 2011  Travis Shirk <travis@pobox.com>
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-################################################################################
-import argparse, logging, sys
-from collections import defaultdict
-from .. import utils
-
-class ArgumentParser(argparse.ArgumentParser):
-    '''Subclass of argparse.ArgumentParser that adds version and log level
-    options.'''
-
-    def __init__(self, *args, **kwargs):
-        from eyed3.info import VERSION_MSG
-        from eyed3.utils.log import LEVELS
-
-        self.log_levels = [logging.getLevelName(l).lower() for l in LEVELS]
-
-        formatter = argparse.RawDescriptionHelpFormatter
-        super(ArgumentParser, self).__init__(*args, formatter_class=formatter,
-                                             **kwargs)
-
-        self.add_argument("--version", action="version", version=VERSION_MSG,
-                          help="Display version information and exit")
-
-        self.debug_arg_group = self.add_argument_group("Debugging")
-        self.debug_arg_group.add_argument(
-                "-l", "--log-level", metavar="LEVEL[:LOGGER]",
-                action=LoggingAction,
-                help="Set a log level. This option may be specified multiple "
-                     "times. If a logger name is specified than the level "
-                     "applies only to that logger, otherwise the level is set "
-                     "on the top-level logger. Acceptable levels are %s. " %
-                     (", ".join("'%s'" % l for l in self.log_levels)))
-
-
-class LoggingAction(argparse._AppendAction):
-    def __call__(self, parser, namespace, values, option_string=None):
-        from eyed3.utils.log import MAIN_LOGGER
-
-        values = values.split(':')
-        level, logger = values if len(values) > 1 else (values[0], MAIN_LOGGER)
-
-        logger = logging.getLogger(logger)
-        try:
-            logger.setLevel(logging._levelNames[level.upper()])
-        except KeyError:
-            msg = "invalid level choice: %s (choose from %s)" % \
-                   (level, parser.log_levels)
-            raise argparse.ArgumentError(self, msg)
-
-        super(LoggingAction, self).__call__(parser, namespace, values,
-                                            option_string)
-
-# ANSI terminal codes
-RESET           = b'\033[0m'
-BOLD            = b'\033[1m'
-BOLD_OFF        = b'\033[22m'
-REVERSE         = b'\033[2m'
-ITALICS         = b'\033[3m'
-ITALICS_OFF     = b'\033[23m'
-UNDERLINE       = b'\033[4m'
-UNDERLINE_OFF   = b'\033[24m'
-BLINK_SLOW      = b'\033[5m'
-BLINK_SLOW_OFF  = b'\033[25m'
-BLINK_FAST      = b'\033[6m'
-BLINK_FAST_OFF  = b'\033[26m'
-INVERSE         = b'\033[7m'
-INVERSE_OFF     = b'\033[27m'
-STRIKE_THRU     = b'\033[9m'
-STRIKE_THRU_OFF = b'\033[29m'
-
-GREY      = b'\033[30m'
-RED       = b'\033[31m'
-GREEN     = b'\033[32m'
-YELLOW    = b'\033[33m'
-BLUE      = b'\033[34m'
-MAGENTA   = b'\033[35m'
-CYAN      = b'\033[36m'
-WHITE     = b'\033[37m'
-
-GREYBG    = b'\033[40m'
-REDBG     = b'\033[41m'
-GREENBG   = b'\033[42m'
-YELLOWBG  = b'\033[43m'
-BLUEBG    = b'\033[44m'
-MAGENTABG = b'\033[45m'
-CYANBG    = b'\033[46m'
-WHITEBG   = b'\033[47m'
-
-# Default colors
-ERROR_COLOR   = RED
-WARNING_COLOR = YELLOW
-HEADER_COLOR  = GREEN
-
-# Set this to disable terminal color codes
-__ENABLE_COLOR_OUTPUT = defaultdict(bool)
-__ENABLE_COLOR_OUTPUT[sys.stdout] = True
-__ENABLE_COLOR_OUTPUT[sys.stderr] = True
-
-def getColor(color_code, fp=sys.stdout):
-    if __ENABLE_COLOR_OUTPUT[fp]:
-        return color_code or b""
-    else:
-        return b""
-
-def enableColorOutput(fp, state=True):
-    global __ENABLE_COLOR_OUTPUT
-    __ENABLE_COLOR_OUTPUT[fp] = bool(state)
-
-@utils.encodeUnicode()
-def printError(s):
-    fp = sys.stderr
-    fp.write('%s%s%s\n' % (getColor(ERROR_COLOR, fp), s, getColor(RESET, fp)))
-    fp.flush()
-
-@utils.encodeUnicode()
-def printWarning(s):
-    fp = sys.stderr
-    fp.write('%s%s%s\n' % (getColor(WARNING_COLOR, fp), s, getColor(RESET, fp)))
-    fp.flush()
-
-@utils.encodeUnicode()
-def printMsg(s):
-    fp = sys.stdout
-    fp.write("%s\n" % s)
-    fp.flush()
-
-@utils.encodeUnicode()
-def printHeader(s):
-    fp = sys.stdout
-    fp.write('%s%s%s\n' % (getColor(HEADER_COLOR, fp), s, getColor(RESET, fp)))
-    fp.flush()
-
-@utils.encodeUnicode()
-def boldText(s, fp=sys.stdout, c=None):
-    return "%s%s%s%s" % (getColor(BOLD, fp), getColor(c, fp),
-                         s, getColor(RESET, fp))
-
-@utils.encodeUnicode()
-def colorText(s, fp=sys.stdout, c=None):
-    return getColor(c, fp) + s + getColor(RESET)
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.