cleaned comments/logging

This commit is contained in:
jngrt 2014-11-06 21:52:50 +01:00
parent e91905d63b
commit 842d656bd9
3 changed files with 17 additions and 22 deletions

12
main.py
View File

@ -46,12 +46,6 @@ class Meshenger:
c.daemon = True c.daemon = True
c.start() c.start()
#b = threading.Thread(target=self.build_index)
#b.daemon = True
#b.start()
#os.system("python meshenger_clientserve.py")
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
logger.info('exiting discovery thread') logger.info('exiting discovery thread')
d.join() d.join()
@ -61,7 +55,6 @@ class Meshenger:
c.join() c.join()
sys.exit() sys.exit()
except Exception as e: except Exception as e:
#catch all other exceptions
logger.warning( 'Main __init__ thread exception: %s', repr(e) ) logger.warning( 'Main __init__ thread exception: %s', repr(e) )
except: except:
logger.warning( 'Main __init__ unknown thread exception') logger.warning( 'Main __init__ unknown thread exception')
@ -168,7 +161,10 @@ Initialize the clientserver
# meshenger_clientserve.build_index_callback = self.build_index # meshenger_clientserve.build_index_callback = self.build_index
def init_index(self): def init_index(self):
logger.info('Building own index for the first time\n') """
Initialize the index. Read from disk or create new.
"""
logger.info('Checking own index for the first time\n')
if not os.path.exists('index'): if not os.path.exists('index'):
with open('index','wb') as index: with open('index','wb') as index:

View File

@ -13,18 +13,14 @@ import logging, logging.config
logging.config.fileConfig('pylog.conf') logging.config.fileConfig('pylog.conf')
logger = logging.getLogger('meshenger'+'.clientserve') logger = logging.getLogger('meshenger'+'.clientserve')
# this variable is set from main, to be called when new messages available
# build_index_callback = None
class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
messageDir = "msg" messageDir = "msg"
"""
Serve index and messages
"""
def do_GET(self): def do_GET(self):
"""
Serve index and messages
"""
if self.path == '/index' or self.path.startswith( "/"+self.messageDir ): if self.path == '/index' or self.path.startswith( "/"+self.messageDir ):
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
@ -44,10 +40,10 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.wfile.write(the_file.read()) self.wfile.write(the_file.read())
"""
Allow clients to post messages
"""
def do_POST(self): def do_POST(self):
"""
Allow clients to post messages
"""
if self.path == '/send': if self.path == '/send':
logger.info('incoming message from client!') logger.info('incoming message from client!')
length = int(self.headers['Content-Length']) length = int(self.headers['Content-Length'])
@ -69,7 +65,9 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
pass pass
def writeMessage(self, time, message): def writeMessage(self, time, message):
"""
Write message to disk
"""
f = os.path.join( self.messageDir, time) f = os.path.join( self.messageDir, time)
if os.path.isfile( f ): if os.path.isfile( f ):
return return

View File

@ -28,10 +28,10 @@ class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
messageDir = "/msg" messageDir = "/msg"
"""
Serve index and messages
"""
def do_GET(self): def do_GET(self):
"""
Serve index and messages
"""
if self.path == '/': if self.path == '/':
self.path = "/index" self.path = "/index"
@ -49,6 +49,7 @@ class HTTPServerV6(BaseHTTPServer.HTTPServer):
class NodeServe(): class NodeServe():
def __init__(self, port): def __init__(self, port):
logger.info('NodeServe.__init__')
server = HTTPServerV6(('::', port), NodeServeHandler) server = HTTPServerV6(('::', port), NodeServeHandler)
server.serve_forever() server.serve_forever()