From 2653eb5bb2f123d45d0e14e994ccab9ce491ac7e Mon Sep 17 00:00:00 2001 From: jngrt Date: Fri, 23 May 2014 18:11:31 +0200 Subject: [PATCH] trying to get new index to work --- main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index b9fd930..5d27bec 100755 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ class Meshenger: #own_ip = "0.0.0.0" msg_dir = os.path.relpath('msg/') exitapp = False #to kill all threads on - index_last_update = str(int(time.time())) + index_last_update = "0" #str(int(time.time())) def __init__(self): @@ -160,9 +160,16 @@ Save the time of the last update. index_file = os.path.relpath( 'index' ) previous_index = [] - if os.path.exists( index_file ): + if not os.path.exists( index_file ): + with open('index','wb') as index: + index.write('') + else: previous_index = open( index_file ).read().split() + index_last_update_file = os.path.relpath( 'index_last_update' ) + if os.path.exists( index_last_update_file ): + self.index_last_update = open( index_last_update_file ).read() + while not self.exitapp: current_index = [] @@ -218,7 +225,7 @@ Save the time of the last update. """ Download the indices from other nodes. """ - + time.sleep(0) # hack to prevent wget bug os.system('wget http://['+ip+'%adhoc0]:'+self.serve_port+'/index -O '+os.path.join(path,'index')) @@ -236,7 +243,7 @@ Get new messages from other node based on it's index file messagepath = os.path.join( self.msg_dir, message ) if not os.path.exists(messagepath): print 'downloading', message, 'to', messagepath - os.system('wget http://['+ip+'%adhoc0]:'+self.serve_port+'/msg/'+message+' -O '+messagepath) + os.system('wget http://['+ip+'%adhoc0]:' + self.serve_port + '/' + message+' -O ' + messagepath) except: print 'Failed to download messages' pass