|
@ -21,9 +21,6 @@ class Meshenger: |
|
|
os.mkdir(self.msg_dir) |
|
|
os.mkdir(self.msg_dir) |
|
|
print 'Making message directory' |
|
|
print 'Making message directory' |
|
|
|
|
|
|
|
|
print 'Building own index for the first time\n' |
|
|
|
|
|
self.build_index() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
d = threading.Thread(target=self.discover) |
|
|
d = threading.Thread(target=self.discover) |
|
|
d.daemon = True |
|
|
d.daemon = True |
|
@ -37,10 +34,16 @@ class Meshenger: |
|
|
s.daemon = True |
|
|
s.daemon = True |
|
|
s.start() |
|
|
s.start() |
|
|
|
|
|
|
|
|
|
|
|
b = threading.Thread(target=self.build_index) |
|
|
|
|
|
b.daemon = True |
|
|
|
|
|
b.start() |
|
|
|
|
|
|
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
except (KeyboardInterrupt, SystemExit): |
|
|
print 'exiting discovery thread' |
|
|
print 'exiting discovery thread' |
|
|
d.join() |
|
|
d.join() |
|
|
a.join() |
|
|
a.join() |
|
|
|
|
|
b.join() |
|
|
|
|
|
s.join() |
|
|
sys.exit() |
|
|
sys.exit() |
|
|
|
|
|
|
|
|
while True: |
|
|
while True: |
|
@ -64,8 +67,8 @@ class Meshenger: |
|
|
self.get_index(device, nodepath) |
|
|
self.get_index(device, nodepath) |
|
|
print 'downloading messages' |
|
|
print 'downloading messages' |
|
|
self.get_messages(device, nodepath) |
|
|
self.get_messages(device, nodepath) |
|
|
print 'updating own index' |
|
|
#print 'updating own index' |
|
|
self.build_index() |
|
|
#self.build_index() |
|
|
|
|
|
|
|
|
time.sleep(5) #free process or ctrl+c |
|
|
time.sleep(5) #free process or ctrl+c |
|
|
|
|
|
|
|
@ -131,14 +134,17 @@ Initialize the server |
|
|
Make an index file of all the messages present on the node. |
|
|
Make an index file of all the messages present on the node. |
|
|
Save the time of the last update. |
|
|
Save the time of the last update. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
print 'Building 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: |
|
|
index.write('') |
|
|
index.write('') |
|
|
|
|
|
|
|
|
previous_index = [] |
|
|
previous_index = [] |
|
|
|
|
|
|
|
|
|
|
|
while not self.exitapp: |
|
|
current_index = os.listdir(self.msg_dir) |
|
|
current_index = os.listdir(self.msg_dir) |
|
|
|
|
|
|
|
|
if current_index != previous_index: |
|
|
if current_index != previous_index: |
|
|
with open('index', 'wb') as index: |
|
|
with open('index', 'wb') as index: |
|
|
for message in os.listdir(self.msg_dir): |
|
|
for message in os.listdir(self.msg_dir): |
|
@ -146,10 +152,13 @@ Save the time of the last update. |
|
|
index.write('\n') |
|
|
index.write('\n') |
|
|
self.index_last_update = str(int(time.time())) |
|
|
self.index_last_update = str(int(time.time())) |
|
|
|
|
|
|
|
|
|
|
|
print 'Index updated:', current_index |
|
|
|
|
|
|
|
|
with open('index_last_update', 'wb') as indexupdate: ### misschien is dit overbodig |
|
|
with open('index_last_update', 'wb') as indexupdate: ### misschien is dit overbodig |
|
|
indexupdate.write(str(int(time.time()))) |
|
|
indexupdate.write(str(int(time.time()))) |
|
|
|
|
|
|
|
|
current_index = previous_index |
|
|
previous_index = current_index |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
|
|
|
def get_index(self,ip, path): |
|
|
def get_index(self,ip, path): |
|
|
""" |
|
|
""" |
|
|