Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

breaking command line client into an example

  • Loading branch information...
commit 5f2440e4e7fb566dd435600aa96e8dbc54c29b30 1 parent 6abe32d
@buzztroll buzztroll authored
Showing with 69 additions and 77 deletions.
  1. +0 −68 eeagent/client.py
  2. +4 −9 eeagent/util.py
  3. +65 −0 example/console_client.py
View
68 eeagent/client.py
@@ -1,27 +1,11 @@
-import dashi.bootstrap as bootstrap
import logging
import socket
-import sys
from threading import Thread
import simplejson as json
from dashi.bootstrap import dashi_connect
import uuid
from eeagent.types import EEAgentLaunchType
-from eeagent.util import determine_path, get_logging, build_cfg
-class TalkConsole(object):
-
- def __init__(self):
- self._prompt = ">> "
-
- def write(self, msg):
- sys.stdout.write("\r%s" % (msg))
- sys.stdout.write("\n" + self._prompt)
- sys.stdout.flush()
-
- def input(self):
- line = raw_input(self._prompt)
- return line.strip()
class EEAgentClient(object):
@@ -95,55 +79,3 @@ def end(self):
def run(self):
while not self.done:
self.client.poll(timeout=2)
-
-class EEAgentClientMain(object):
-
- def __init__(self, args):
- self._args = args
-
- def start(self):
- self.CFG = build_cfg(self._args)
- self.log = get_logging(self.CFG)
- self._done = False
- self.console = TalkConsole()
- self.talker = EEAgentClient(self.console.write, self.CFG, self.log)
- self.client_thread = EEAgentCLIMessageReaderThread(self.talker)
-
- def wait(self):
- self.client_thread.start()
- self._done = False
- while not self._done:
- line = self.console.input()
- line = line.strip()
- if not line:
- continue
- if line == "quit":
- self._done = True
- else:
- line_a = line.split()
- cmd = line_a[0].strip()
- try:
- func = g_command_table[cmd]
- func(self.talker, line_a[1:])
- except Exception, ex:
- self.console.write(str(ex))
- self.client_thread.end()
- return 0
-
- def death_handler(self, signum, frame):
- self.end()
-
- def end(self):
- self._done = True
-
-
-def main(args=sys.argv):
-
- client = EEAgentClientMain(args)
- client.start()
- return client.wait()
-
-if __name__ == '__main__':
- rc = main()
- sys.exit(rc)
-
View
13 eeagent/util.py
@@ -84,15 +84,10 @@ def validate_config(CFG):
def determine_path():
"""find path of current file,
Borrowed from wxglade.py"""
- try:
- root = __file__
- if os.path.islink(root):
- root = os.path.realpath(root)
- return os.path.dirname(os.path.abspath(root))
- except:
- print "I'm sorry, but something is wrong."
- print "There is no __file__ variable. Please contact the author."
- raise
+ root = __file__
+ if os.path.islink(root):
+ root = os.path.realpath(root)
+ return os.path.dirname(os.path.abspath(root))
def build_cfg(args):
config_files = []
View
65 example/console_client.py
@@ -0,0 +1,65 @@
+class TalkConsole(object):
+
+ def __init__(self):
+ self._prompt = ">> "
+
+ def write(self, msg):
+ sys.stdout.write("\r%s" % (msg))
+ sys.stdout.write("\n" + self._prompt)
+ sys.stdout.flush()
+
+ def input(self):
+ line = raw_input(self._prompt)
+ return line.strip()
+
+
+class EEAgentClientMain(object):
+
+ def __init__(self, args):
+ self._args = args
+
+ def start(self):
+ self.CFG = build_cfg(self._args)
+ self.log = get_logging(self.CFG)
+ self._done = False
+ self.console = TalkConsole()
+ self.talker = EEAgentClient(self.console.write, self.CFG, self.log)
+ self.client_thread = EEAgentCLIMessageReaderThread(self.talker)
+
+ def wait(self):
+ self.client_thread.start()
+ self._done = False
+ while not self._done:
+ line = self.console.input()
+ line = line.strip()
+ if not line:
+ continue
+ if line == "quit":
+ self._done = True
+ else:
+ line_a = line.split()
+ cmd = line_a[0].strip()
+ try:
+ func = g_command_table[cmd]
+ func(self.talker, line_a[1:])
+ except Exception, ex:
+ self.console.write(str(ex))
+ self.client_thread.end()
+ return 0
+
+ def death_handler(self, signum, frame):
+ self.end()
+
+ def end(self):
+ self._done = True
+
+
+def main(args=sys.argv):
+ client = EEAgentClientMain(args)
+ client.start()
+ return client.wait()
+
+if __name__ == '__main__':
+ rc = main()
+ sys.exit(rc)
+
Please sign in to comment.
Something went wrong with that request. Please try again.