summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__init__.py1
-rw-r--r--__pycache__/commands.cpython-35.pycbin0 -> 1078 bytes
-rw-r--r--app.py63
-rw-r--r--commands.py0
4 files changed, 34 insertions, 30 deletions
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1 @@
+
diff --git a/__pycache__/commands.cpython-35.pyc b/__pycache__/commands.cpython-35.pyc
new file mode 100644
index 0000000..b2272bf
--- /dev/null
+++ b/__pycache__/commands.cpython-35.pyc
Binary files differ
diff --git a/app.py b/app.py
index 923a23a..8bab59d 100644
--- a/app.py
+++ b/app.py
@@ -26,7 +26,7 @@ class Colors(object):
bold = '\033[1m'
-class Command(object):
+class ListCommand(object):
info = {
"info" : "this is stout",
@@ -51,7 +51,32 @@ class Command(object):
pass
-class Stout(object):
+class Commands(object):
+
+ def command(self, what, cmd):
+ if what == 'set':
+ try:
+ if cmd[1] == 'user' and cmd[2] is not None:
+ if len(cmd[2]) > 10: raise PersonalError("lunghezza maggiore del consetito. Max 10")
+
+ if Stout.userexist(cmd[2]) == True: raise PersonalError("questo nome utente esiste già")
+
+ if self.user != '': r.zrem('usersname', self.user)
+
+ self.user = cmd[2]
+ r.hset('user:'+host, 'name', self.user)
+ r.zadd('usersname', self.user, 0)
+
+ print("Ok")
+ elif cmd[1] is not ListCommand.commands['set']:
+ raise IndexError
+ except IndexError:
+ ListCommand.err('wrong')
+ except PersonalError as e:
+ ListCommand.err('personal', e.value)
+
+
+class Stout(Commands):
def __init__(self):
self.name = 'stout'
@@ -80,28 +105,6 @@ class Stout(object):
else:
return False
- def command(self, what, cmd):
- if what == 'set':
- try:
- if cmd[1] == 'user' and cmd[2] is not None:
- if len(cmd[2]) > 10: raise PersonalError("lunghezza maggiore del consetito. Max 10")
-
- if Stout.userexist(cmd[2]) == True: raise PersonalError("questo nome utente esiste già")
-
- if self.user != '': r.zrem('usersname', self.user)
-
- self.user = cmd[2]
- r.hset('user:'+host, 'name', self.user)
- r.zadd('usersname', self.user, 0)
-
- print("Ok")
- elif cmd[1] is not Command.commands['set']:
- raise IndexError
- except IndexError:
- Command.err('wrong')
- except PersonalError as e:
- Command.err('personal', e.value)
-
def action(self, cmd):
if cmd is None:
return None
@@ -109,20 +112,20 @@ class Stout(object):
cmd = cmd.split()
count = len(cmd)
- if (count == 1 or count == 2) and cmd[0] not in Command.commands:
+ if (count == 1 or count == 2) and cmd[0] not in ListCommand.commands:
try:
if cmd[0] == 'info' and count == 1:
- print(Command.info['info'])
+ print(ListCommand.info['info'])
else:
- print(Command.info[cmd[1]])
+ print(ListCommand.info[cmd[1]])
except (KeyError, IndexError):
- Command.err('keyword')
+ ListCommand.err('keyword')
else:
what = cmd[0]
- if what in Command.commands:
+ if what in ListCommand.commands:
self.command(what, cmd)
else:
- Command.err('keyword')
+ ListCommand.err('keyword')
if __name__ == '__main__':
diff --git a/commands.py b/commands.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/commands.py