cleaned comments/logging
This commit is contained in:
parent
e91905d63b
commit
842d656bd9
12
main.py
12
main.py
@ -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:
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
"""
|
"""
|
||||||
Serve index and messages
|
Serve index and messages
|
||||||
"""
|
"""
|
||||||
def do_GET(self):
|
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
|
|
||||||
|
def do_POST(self):
|
||||||
"""
|
"""
|
||||||
Allow clients to post messages
|
Allow clients to post messages
|
||||||
"""
|
"""
|
||||||
def do_POST(self):
|
|
||||||
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
|
||||||
|
@ -28,10 +28,10 @@ class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|||||||
|
|
||||||
messageDir = "/msg"
|
messageDir = "/msg"
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
"""
|
"""
|
||||||
Serve index and messages
|
Serve index and messages
|
||||||
"""
|
"""
|
||||||
def do_GET(self):
|
|
||||||
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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user