From 1f32e483d9d21526064ec75c2b39e015644c60f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Husiaty=C5=84ski?= Date: Sat, 9 Feb 2008 12:53:13 +0100 Subject: [PATCH] Alias bugfix. Few changes in showinfo module. Better color output support. New module - colors, where the colors definitions are. --- aur-shell.py | 5 ++-- colors.py | 44 ++++++++++++++++++++++++++++ conf.py | 68 ++++++++++++++++++-------------------------- plugin/package_management.py | 7 +++-- showinfo.py | 41 ++++++++++++++++++++------ 5 files changed, 111 insertions(+), 54 deletions(-) create mode 100644 colors.py rewrite conf.py (76%) diff --git a/aur-shell.py b/aur-shell.py index 3d5ed89..fabef34 100644 --- a/aur-shell.py +++ b/aur-shell.py @@ -50,11 +50,10 @@ class AurShell(cmd.Cmd): # cmd[1] can be empty # cmd[2:] should be method argumments, can be empty cmd = cmd.split() - # check if alias exists + # check if alias exists and if so, replace command if cmd[0] in conf.alias.keys(): - # change the first command with its alias cmd[0] = conf.alias[cmd[0]] - self.onecmd(" ".join(cmd)) + self.onecmd(" ".join(cmd)) # operations for single command with no arguments elif len(cmd) == 1: # if there's no such command (or plugin class) diff --git a/colors.py b/colors.py new file mode 100644 index 0000000..4f77da0 --- /dev/null +++ b/colors.py @@ -0,0 +1,44 @@ +""" +Color definitions +""" + + +color = { + "none" : "\033[0m", + "bold" : "\033[1m", + "BOLD" : "\033[1m", + "red" : "\033[0;31m", + "RED" : "\033[1;31m", + "black" : "\033[0;30m", + "BLACK" : "\033[1;30m", + "green" : "\033[0;32m", + "GREEN" : "\033[1;32m", + "brown" : "\033[0;33m", + "BROWN" : "\033[1;33m", + "blue" : "\033[0;34m", + "BLUE" : "\033[1;34m", + "magenta" : "\033[0;35m", + "MAGENTA" : "\033[1;35m", + "cyan" : "\033[0;36m", + "CYAN" : "\033[1;36m", + "gray" : "\033[0;37m", + "GRAY" : "\033[1;37m", + "darkgray" : "\033[0;30m", + "DARKGRAY" : "\033[1;30m", + "lightred" : "\033[0;31m", + "LIGHTRED" : "\033[1;31m", + "lightgreen" : "\033[0;32m", + "LIGHTGREEN" : "\033[1;32m", + "yellow" : "\033[0;33m", + "YELLOW" : "\033[1;33m", + "lightblue" : "\033[0;34m", + "LIGHTBLUE" : "\033[1;34m", + "lightmagenta" : "\033[0;35m", + "LIGHTMAGENTA" : "\033[1;35m", + "lightcyan" : "\033[0;36m", + "LIGHTCYAN" : "\033[1;36m", + "white" : "\033[0;37m", + "WHITE" : "\033[1;37m", + } + + diff --git a/conf.py b/conf.py dissimilarity index 76% index 5668790..fbfcdff 100644 --- a/conf.py +++ b/conf.py @@ -1,40 +1,28 @@ -#!/usr/bin/python -# -*- coding: utf-8-*- - -"""Configuration file""" - -import os -import os.path - - -modules_path = os.path.join(os.getcwd(), "plugin/") -history_file = os.path.join(os.path.expanduser("~"), ".aurshell_history") -history_length = 500 -shell_prompt = " \033[1;34m[\033[0m\033[1m aurshell \033[34m]\033[0m " - -alias = { - "up" : "pacman -Suy", - "s" : "pacman -Ss", - "info" : "help", - } - - -color = { - "none" : "\033[0m", - "red" : "\033[31m", - "black" : "\033[30m", - "green" : "\033[32m", - "brown" : "\033[33m", - "blue" : "\033[34m", - "magenta" : "\033[35m", - "cyan" : "\033[36m", - "gray" : "\033[37m", - "darkgray" : "\033[30m", - "lightred" : "\033[31m", - "lightgreen" : "\033[32m", - "yellow" : "\033[33m", - "lightblue" : "\033[34m", - "lightmagenta" : "\033[35m", - "lightcyan" : "\033[36m", - "white" : "\033[37m", - } +#!/usr/bin/python +# -*- coding: utf-8-*- + +""" +Configuration file +""" + +from colors import * +import os +import os.path + +alias = { + "up" : "pacman -Suy ", + "p -Ss" : "pacman -Ss ", + "p -Suy" : "pacman -Suy ", + "Ss" : "search ", + "s" : "pacman -Ss ", + "info" : "help ", + } + + +modules_path = os.path.join(os.getcwd(), "plugin/") +history_file = os.path.join(os.path.expanduser("~"), ".aurshell_history") +history_length = 500 +shell_prompt = color["BLUE"] + " [ " + color["WHITE"] + "aurshell" + \ + color["BLUE"] + " ] " + color["none"] + + diff --git a/plugin/package_management.py b/plugin/package_management.py index bc25637..86e84e1 100644 --- a/plugin/package_management.py +++ b/plugin/package_management.py @@ -70,13 +70,16 @@ class search(object): if args: return self.pacman(*args) else: - return self.__doc__() + return self.__doc__ def help(self, *ignore): return "blah!\nno help for this class" def pacman(self, *args): - return os.popen("pacman -Ss %s" % " ".join(args)).read() + try: + return os.popen("pacman -Ss %s" % " ".join(args)).read() + except TypeError: + return "Bad usage. Try:\n$ search pacman [ ...]" def info(self, *args): return os.popen("pacman -Si %s" % " ".join(args)).read() diff --git a/showinfo.py b/showinfo.py index 9786da9..6bffc20 100644 --- a/showinfo.py +++ b/showinfo.py @@ -1,24 +1,47 @@ -import conf +try: + import conf +except ImportError: + import sys + sys.exit("Can't find conf module.") + class Put(object): """Show info class""" - def __call__(self, message, **args): - self.normal(message, **args) + def __call__(self, message, color=None, newline=False, *ignore): + """Show message on stdout + + message - message that would be shown + color - opional color of the message + newline - end with newline? + """ + if not color: + self.normal(message) + else: + self.color(message, color, newline) + def normal(self, message="", **args): """Default message printer""" if not args: - print("%s " % message) + print(message) else: - # TODO colors, some args, etc - # 2008-01-27 20:07:48 - print(" %s %s" % (message, " ".join(args))) + print("%s %s" % (message, " ".join(args))) def noline(self, message): + """Print message, but don't end it with new line character""" print message, - def color(self, msg, color="none"): - self.noline(conf.color[color] + msg + conf.color["none"]) + def color(self, msg, color=None, newline=False): + """Print message with colors + By default it doesn't end with new line character. + """ + if not color: + color = "none" + if newline: + newline = "\n" + else: + newline = "" + self.noline(conf.color[color] + msg + conf.color["none"] + newline) -- 2.11.4.GIT