diff options
author | Santo Cariotti <sancn@live.com> | 2017-07-29 20:27:47 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-07-29 20:27:47 +0200 |
commit | efda27de3207e3471e2620d72487cdfcea8dd55e (patch) | |
tree | 7171903caa5f984fc674182f8454af684213527f | |
parent | 46d56ebe56a99c156bdade1d92f5c1fa41269a41 (diff) |
deleted COLORS class for COLORS constants
-rw-r--r-- | lib/app.py | 9 | ||||
-rw-r--r-- | lib/classes.py | 17 | ||||
-rw-r--r-- | lib/commands.py | 8 | ||||
-rw-r--r-- | lib/listcommands.py | 8 |
4 files changed, 20 insertions, 22 deletions
@@ -1,4 +1,4 @@ -from classes import PersonalError, Colors, r, clear +from classes import PersonalError, r, clear, YELLOW, BLACK, GREY from commands import Commands from listcommands import ListCommands @@ -13,7 +13,7 @@ class Stout(Commands): if self.user == '': return word else: - return word + Colors.grey + '(' + self.user + ') ' + return word + GREY + '(' + self.user + ') ' @staticmethod def username(): @@ -36,7 +36,7 @@ class Stout(Commands): else: cmd = cmd.split() count = len(cmd) - + if (count == 1 or count == 2) and cmd[0] not in ListCommands.commands: try: if cmd[0] == 'info' and count == 1: #general info @@ -58,12 +58,13 @@ class Stout(Commands): pass if __name__ == '__main__': + clear() app = Stout() cmd = '' while cmd != 'quit': try: - cmd = input('>' + Colors.yellow + app.getName() + Colors.black) + cmd = input('>' + YELLOW + app.getName() + BLACK) except (EOFError, KeyboardInterrupt): break diff --git a/lib/classes.py b/lib/classes.py index 9370241..c285828 100644 --- a/lib/classes.py +++ b/lib/classes.py @@ -1,10 +1,16 @@ import redis, socket, os +RED = '\033[91m' +YELLOW = '\033[93m' +GREY = '\033[90m' +BLACK = '\033[0m' +BOLD = '\033[1m' + try: from .config import config as co except: from config import config as co - + r = redis.Redis(host=co['host'], port=co['port'], unix_socket_path=co['unix_socket_path'], db=co['db']) def clear(): @@ -23,12 +29,3 @@ class PersonalError(Exception): def __str__(self): return repr(self.value) - - -class Colors(object): - - red = '\033[91m' - yellow = '\033[93m' - grey = '\033[90m' - black = '\033[0m' - bold = '\033[1m' diff --git a/lib/commands.py b/lib/commands.py index e8cb171..c727f90 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -1,4 +1,4 @@ -from classes import PersonalError, r, clear, Colors +from classes import PersonalError, r, clear, RED, GREY from listcommands import ListCommands from config import config as co @@ -17,7 +17,7 @@ class Commands(object): raise PersonalError('lunghezza maggiore del consetito. Max 10') if len(cmd) > ListCommands.info['set'][1]: - raise PersonalError(Colors.grey + 'set user' + Colors.red + ' accetta 1 parametro') + raise PersonalError(GREY + 'set user' + RED + ' accetta 1 parametro') self.user = cmd[2] @@ -35,7 +35,7 @@ class Commands(object): elif what == 'get': try: if len(cmd) > ListCommands.info['get'][1]: - raise PersonalError(Colors.grey + 'get ' + Colors.red + 'accetta 2 parametri') + raise PersonalError(GREY + 'get ' + RED + 'accetta 2 parametri') if cmd[1] == 'i': #if first word after get is 'i', there is an info if cmd[2] == 'user': @@ -93,7 +93,7 @@ class Commands(object): elif what == 'del': try: if len(cmd) > ListCommands.info['del'][1]: - raise PersonalError(Colors.grey + 'del ' + Colors.red + 'accetta 1 parametro') + raise PersonalError(GREY + 'del ' + RED + 'accetta 1 parametro') if r.get('idTODO') is None or r.get('idTODO') == 0: #idTODO is null or 0 print('nessun todo in lista: goditi una Stout') diff --git a/lib/listcommands.py b/lib/listcommands.py index d2f83a0..c779524 100644 --- a/lib/listcommands.py +++ b/lib/listcommands.py @@ -1,5 +1,5 @@ import sys -from classes import Colors +from classes import RED, BLACK class ListCommands(object): """ @@ -29,10 +29,10 @@ Se utilizzato con il "flag" i, si possono visualizzare le info: get i host, get @staticmethod def err(err, info = ''): if err == 'keyword': - sys.stderr.write(Colors.red + 'keyword inesistente\n' + Colors.black) + sys.stderr.write(RED + 'keyword inesistente\n' + BLACK) elif err == 'wrong': - sys.stderr.write(Colors.red + 'sintassi comando errata\n' + Colors.black) + sys.stderr.write(RED + 'sintassi comando errata\n' + BLACK) elif err == 'personal': - sys.stderr.write(Colors.red + str(info) + '\n' + Colors.black) + sys.stderr.write(RED + str(info) + '\n' + BLACK) else: pass |