From 9fe74e506b8a1d36aa37293b794048d4fc3cdf74 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 23 Mar 2015 18:29:54 -0400 Subject: [PATCH] work with or without colorama --- install | 9 --------- pirate-get.py | 25 +++++++++++++------------ requirements.txt | 1 - 3 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 requirements.txt diff --git a/install b/install index 117bb97..10ad915 100755 --- a/install +++ b/install @@ -11,13 +11,6 @@ TMP=$(mktemp pirate-get-XXXXXX) python='python' fi - if [ $(which pip3) ] - then - pip='pip3' - else - pip='pip' - fi - echo "#!/usr/bin/env $python" > "$TMP" && sed 1d $(dirname $0)/pirate-get.py >> "$TMP" @@ -26,7 +19,5 @@ TMP=$(mktemp pirate-get-XXXXXX) chmod +x /usr/bin/pirate-get && chmod 755 /usr/bin/pirate-get && - $pip install -r requirements.txt && - rm $TMP } || rm $TMP diff --git a/pirate-get.py b/pirate-get.py index 77ff74f..60e5e07 100755 --- a/pirate-get.py +++ b/pirate-get.py @@ -145,22 +145,23 @@ class BayParser(HTMLParser): def print(*args, **kwargs): if kwargs.get('color', False): - import colorama - colorama.init() - color_dict = { - 'default': '', - 'header': colorama.Back.BLACK + colorama.Fore.WHITE, - 'alt': colorama.Fore.YELLOW, - 'zebra_0': '', - 'zebra_1': colorama.Fore.BLUE, - 'WARN': colorama.Fore.MAGENTA, - 'ERROR': colorama.Fore.RED} - try: + import colorama + colorama.init() + color_dict = { + 'default': '', + 'header': colorama.Back.BLACK + colorama.Fore.WHITE, + 'alt': colorama.Fore.YELLOW, + 'zebra_0': '', + 'zebra_1': colorama.Fore.BLUE, + 'WARN': colorama.Fore.MAGENTA, + 'ERROR': colorama.Fore.RED} + c = color_dict[kwargs.pop('color')] args = (c + args[0],) + args[1:] + (colorama.Style.RESET_ALL,) - except (KeyError, IndexError): + except (KeyError, IndexError, ImportError): pass + kwargs.pop('color', None) return builtins.print(*args, **kwargs) else: kwargs.pop('color', None) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9c086f0..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -colorama==0.3.2