Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
offlinemark committed Nov 15, 2015
2 parents 7853423 + c248fa3 commit 2d0409b
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 56 deletions.
31 changes: 16 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
COMMON = $(wildcard common/*.py common/modules/*.py)
DIR = poet
COMMON = $(wildcard $(DIR)/*.py $(DIR)/modules/*.py)
COMMON := $(subst py,pyo,$(COMMON))
OUT = bin/ bin/poet-client bin/poet-server

Expand All @@ -11,26 +12,26 @@ PYCC = python2.7 -OO -m py_compile

default: $(OUT)

# for debugging, just place the main files into the common/ directory, then
# for debugging, just place the main files into the $(DIR)/ directory, then
# cd into that directory and execute the client and server. can't debug
# "production" builds because debug info is stripped from them
dbg:
cp client.py common
cp server.py common
ls -1 common/modules |grep -Ev 'py[oc]' |grep -v __init__ > common/modindex.txt
cp client.py $(DIR)
cp server.py $(DIR)
ls -1 $(DIR)/modules |grep -Ev 'py[oc]' |grep -v __init__ > $(DIR)/modindex.txt

bin:
mkdir -p $@

bin/poet-client: client.pyo $(COMMON)
# main file needs to be named __main__.py(c/o) for zip file packaging to work
cp $< common/__main__.pyo
cp $< $(DIR)/__main__.pyo

# create module index file, so client/server know what to load at runtime
ls -1 common/modules |grep -v pyo |grep -v __init__ > common/modindex.txt
ls -1 $(DIR)/modules |grep -v pyo |grep -v __init__ > $(DIR)/modindex.txt

# zip everything up. -r : zip file destination
cd common && $(ZIP) -r ../$@ *.pyo modindex.txt modules/*.pyo
cd $(DIR) && $(ZIP) -r ../$@ *.pyo modindex.txt modules/*.pyo

# get rid of auto-appended .zip extension
mv $@.zip $@
Expand All @@ -45,9 +46,9 @@ bin/poet-client: client.pyo $(COMMON)

bin/poet-server: server.pyo $(COMMON)
# exact same stuff as above
cp $< common/__main__.pyo
ls -1 common/modules |grep -v pyo |grep -v __init__ > common/modindex.txt
cd common && $(ZIP) -r ../$@ *.pyo modindex.txt modules/*.pyo
cp $< $(DIR)/__main__.pyo
ls -1 $(DIR)/modules |grep -v pyo |grep -v __init__ > $(DIR)/modindex.txt
cd $(DIR) && $(ZIP) -r ../$@ *.pyo modindex.txt modules/*.pyo
mv $@.zip $@
mv $@ .tmp
echo "#!/usr/bin/env python2.7" > $@
Expand All @@ -61,10 +62,10 @@ bin/poet-server: server.pyo $(COMMON)
clean:
rm -rf bin
rm -f *.pyo
rm -f common/__main__.py common/modindex.txt
rm -f common/client.py common/server.py
rm -f common/*.pyo common/*.pyc
rm -f common/modules/*.pyo common/modules/*.pyc
rm -f $(DIR)/__main__.py $(DIR)/modindex.txt
rm -f $(DIR)/client.py $(DIR)/server.py
rm -f $(DIR)/*.pyo $(DIR)/*.pyc
rm -f $(DIR)/modules/*.pyo $(DIR)/modules/*.pyc

squeaky:
$(MAKE) clean
Expand Down
4 changes: 2 additions & 2 deletions Testing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ DELAY = 1
PORT = -p 8081
PYTHON = python2.7

CL = common/client.py
SV = common/server.py
CL = poet/client.py
SV = poet/server.py

# debug mode helpers

Expand Down
2 changes: 2 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def is_active(host, port):
f = urllib2.urlopen(req)
if f.code == 200:
return True
# shouldn't get here
return False
except urllib2.URLError:
return False

Expand Down
2 changes: 1 addition & 1 deletion common/config.py → poet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Poet Configurations
#

# client authentication token
# default client authentication token. change this to whatever you want!
AUTH = 'b9c39a336bb97a9c9bda2b82bdaacff3'

# directory to save output files to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 4 additions & 7 deletions common/modules/selfdestruct.py → poet/modules/selfdestruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def server(server, argv):


@module.client_handler(MODNAME)
def client(server, argv):
try:
server.selfdestruct()
server.s.send('boom')
sys.exit()
except Exception as e:
server.s.send(str(e.message))
def client(client, argv):
client.selfdestruct()
client.s.send('boom')
sys.exit()
File renamed without changes.
File renamed without changes.
File renamed without changes.
57 changes: 26 additions & 31 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ class PoetServer(object):
def __init__(self, s):
self.s = s
self.conn = None
self.builtins = ['exit', 'help']
# exists so modules can stop server (used by selfdestruct)
self.builtins = {
'exit': self._builtin_exit,
'help': self._builtin_help
}
# exists so modules can stop server (used by selfdestruct and exit)
self.continue_ = True

def start(self):
Expand All @@ -65,40 +68,23 @@ def start(self):
print 'Running `help\' will give you a list of supported commands.'
while True:
try:
found = False
argv = raw_input(POSH_PROMPT).split()

#
# builtins
#

if argv == []:
if not argv:
continue
if argv[0] == 'exit':
break
elif argv[0] == 'help':
found = True
print 'Commands:\n {}'.format('\n '.join(sorted(self.builtins + module.server_commands.keys())))

#
# modules
#

# try to find command in registered modules
for cmd, func in module.server_commands.iteritems():
if argv[0] == cmd:
found = True
try:
func(self, argv)
except Exception as e:
self.info(str(e.args))

if argv[0] in self.builtins:
self.builtins[argv[0]](argv)
elif argv[0] in module.server_commands:
try:
module.server_commands[argv[0]](self, argv)
except Exception as e:
self.info(str(e.args))
else:
self.info('{}: command not found'.format(argv[0]))

# see comment above for self.continue_ for why this is here
if not self.continue_:
return

if not found:
self.info('{}: command not found'.format(argv[0]))
break
except KeyboardInterrupt:
print
continue
Expand Down Expand Up @@ -194,6 +180,15 @@ def exec_preproc(self, inp):
del tmp[1]
tmp = ' '.join(tmp)
return tmp, write_flag, write_file

def _builtin_exit(self, argv):
self.continue_ = False

def _builtin_help(self, argv):
print 'Builtins:\n {}'.format('\n '.join(sorted(self.builtins.keys())))
print
print 'Commands:\n {}'.format('\n '.join(sorted(module.server_commands.keys())))



def get_args():
Expand Down

0 comments on commit 2d0409b

Please # to comment.