From e745f086ce816201066810b6eeb2710d09fa09a6 Mon Sep 17 00:00:00 2001 From: Kepoor Hampond Date: Mon, 12 Dec 2016 20:46:28 -0800 Subject: [PATCH] Added a version argument and slightly updated the README --- README.md | 2 +- irs/__main__.py | 12 ++++++++++++ irs/utils.py | 51 +++++++++++++++++++++++++++++++++++++------------ setup.py | 2 +- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 310d614..bcea05f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ optional arguments: ``` [![asciicast](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug.png)](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug?speed=3&autoplay=true) -[![asciicast](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia.png)](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3&autoplay=true) +[![asciicast](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia.png)](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3) ___ ### Installation diff --git a/irs/__main__.py b/irs/__main__.py index 62a6e40..af740ce 100644 --- a/irs/__main__.py +++ b/irs/__main__.py @@ -32,6 +32,7 @@ def console(): def main(): parser = argparse.ArgumentParser() parser.add_argument('-a', '--artist', dest="artist", help="Specify the artist name") + parser.add_argument('-v', '--version', dest="version", action='store_true', help="Display the version and exit.") media = parser.add_mutually_exclusive_group() media.add_argument('-A', '--album', dest="album", help="Specify album name of the artist") @@ -39,6 +40,17 @@ def main(): args = parser.parse_args() + + if args.version: + import pkg_resources + print ("\n\n" + color("Ingenious Redistribution System", ["HEADER", "BOLD"])) + print ("Homepage: " + color("https://github.com/kepoorhampond/irs", ["OKGREEN"])) + print ("License: " + color("The GNU", ["YELLOW"]) + " (http://www.gnu.org/licenses/gpl.html)") + print ("Version: " + pkg_resources.get_distribution("irs").version) + + print ("\n") + exit(0) + if args.artist and not (args.album or args.song): print ("usage: __init__.py [-h] [-a ARTIST] [-A ALBUM | -s SONG] \n\ error: must specify -A/--album or -s/--song if specifying -a/--artist") diff --git a/irs/utils.py b/irs/utils.py index 33d052a..5700abc 100644 --- a/irs/utils.py +++ b/irs/utils.py @@ -4,21 +4,48 @@ def strip_special_chars(string): string.replace(char, "") return string -class bc: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[32m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - GRAY = '\033[30m' - YELLOW = '\033[33m' +def supports_color(): + """ + Returns True if the running system's terminal supports color, and False + otherwise. + """ + plat = sys.platform + supported_platform = plat != 'Pocket PC' and (plat != 'win32' or + 'ANSICON' in os.environ) + # isatty is not always implemented, #6223. + is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() + if not supported_platform or not is_a_tty: + return False + return True + +if supports_color(): + class bc: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[32m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + GRAY = '\033[30m' + YELLOW = '\033[33m' +else: + class bc: + HEADER = '' + OKBLUE = '' + OKGREEN = '' + WARNING = '' + FAIL = '' + ENDC = '' + BOLD = '' + UNDERLINE = '' + GRAY = '' + YELLOW = '' def color(text, colors=[]): color_string = "" for color in colors: color_string += "bc.%s + " % color color_string = color_string[:-2] - return (eval(color_string) + text + bc.ENDC) + return (bc.ENDC + eval(color_string) + text + bc.ENDC) diff --git a/setup.py b/setup.py index 0e3208d..d0286e7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='irs', - version='1.1.4', + version='1.2.4', description='A music downloader that just gets metadata.', url='https://github.com/kepoorhampond/irs', author='Kepoor Hampond',