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.start()
|
||||
|
||||
#b = threading.Thread(target=self.build_index)
|
||||
#b.daemon = True
|
||||
#b.start()
|
||||
|
||||
#os.system("python meshenger_clientserve.py")
|
||||
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
logger.info('exiting discovery thread')
|
||||
d.join()
|
||||
@ -61,7 +55,6 @@ class Meshenger:
|
||||
c.join()
|
||||
sys.exit()
|
||||
except Exception as e:
|
||||
#catch all other exceptions
|
||||
logger.warning( 'Main __init__ thread exception: %s', repr(e) )
|
||||
except:
|
||||
logger.warning( 'Main __init__ unknown thread exception')
|
||||
@ -168,7 +161,10 @@ Initialize the clientserver
|
||||
# meshenger_clientserve.build_index_callback = self.build_index
|
||||
|
||||
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'):
|
||||
with open('index','wb') as index:
|
||||
|
@ -13,18 +13,14 @@ import logging, logging.config
|
||||
logging.config.fileConfig('pylog.conf')
|
||||
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):
|
||||
|
||||
messageDir = "msg"
|
||||
|
||||
"""
|
||||
Serve index and messages
|
||||
"""
|
||||
def do_GET(self):
|
||||
"""
|
||||
Serve index and messages
|
||||
"""
|
||||
|
||||
if self.path == '/index' or self.path.startswith( "/"+self.messageDir ):
|
||||
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
|
||||
@ -44,10 +40,10 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
self.wfile.write(the_file.read())
|
||||
|
||||
|
||||
"""
|
||||
Allow clients to post messages
|
||||
"""
|
||||
def do_POST(self):
|
||||
"""
|
||||
Allow clients to post messages
|
||||
"""
|
||||
if self.path == '/send':
|
||||
logger.info('incoming message from client!')
|
||||
length = int(self.headers['Content-Length'])
|
||||
@ -69,7 +65,9 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
pass
|
||||
|
||||
def writeMessage(self, time, message):
|
||||
|
||||
"""
|
||||
Write message to disk
|
||||
"""
|
||||
f = os.path.join( self.messageDir, time)
|
||||
if os.path.isfile( f ):
|
||||
return
|
||||
|
@ -28,10 +28,10 @@ class NodeServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
|
||||
messageDir = "/msg"
|
||||
|
||||
"""
|
||||
Serve index and messages
|
||||
"""
|
||||
def do_GET(self):
|
||||
"""
|
||||
Serve index and messages
|
||||
"""
|
||||
if self.path == '/':
|
||||
self.path = "/index"
|
||||
|
||||
@ -49,6 +49,7 @@ class HTTPServerV6(BaseHTTPServer.HTTPServer):
|
||||
|
||||
class NodeServe():
|
||||
def __init__(self, port):
|
||||
logger.info('NodeServe.__init__')
|
||||
server = HTTPServerV6(('::', port), NodeServeHandler)
|
||||
server.serve_forever()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user