Esempio n. 1
0
 def run_space_loader(loader):
     if not os.path.exists("data/aipdata"):
         os.makedirs("data/aipdata")
     report = dict()
     for method in [
             x for x in dir(loader) if not x.startswith("_")
     ]:
         filename = os.path.join("data/aipdata", method + ".pickle")
         result = "Unknown"
         msg = None
         try:
             m = getattr(loader, method)
             d = m()
             temp = open(filename + ".temp", "w")
             pickle.dump(d, temp)
             temp.close()
             os.rename(filename + ".temp", filename)
             result = "Loaded new"
         except Exception, cause:
             msg = traceback.format_exc()
             try:
                 d = pickle.load(open(filename))
                 result = "Used backup"
             except Exception:
                 d = dict()
                 result = "Backup restore failed"
         report[method] = dict(method=method,
                               what=m.__doc__,
                               result=result,
                               msg=msg,
                               date=utcdatetime2stamp_inexact(
                                   datetime.utcnow()))
         now = datetime.utcnow()
         for k, v in d.items():
             for x in v:
                 if not 'date' in x:
                     x['date'] = now
                 else:
                     if x['date'] > now:
                         x['date'] = now
             if k == "airspaces":
                 #print "Method:",method,v
                 #for av in v:
                 #print
                 #print
                 #print av
                 #assert 'type' in av
                 airspaces.extend(v)
             elif k == "airfields":
                 airfields.extend(v)
             elif k == "bad_airfields":
                 bad_airfields.extend(v)
             elif k == "sig_points":
                 sig_points.extend(v)
             elif k == "obstacles":
                 obstacles.extend(v)
             else:
                 raise Exception(
                     "Bad return value from SpaceLoader:%s" %
                     ((k, v), ))
Esempio n. 2
0
 def run_space_loader(loader):
     if not os.path.exists("data/aipdata"):
         os.makedirs("data/aipdata")                
     report=dict()
     for method in [x for x in dir(loader) if not x.startswith("_")]:
         filename=os.path.join("data/aipdata",method+".pickle")
         result="Unknown"
         msg=None
         try:
             m=getattr(loader,method)                        
             d=m()
             temp=open(filename+".temp","w")
             pickle.dump(d,temp)
             temp.close()
             os.rename(
                 filename+".temp",
                 filename)                            
             result="Loaded new"
         except Exception,cause:
             msg=traceback.format_exc()
             try:
                 d=pickle.load(open(filename))
                 result="Used backup"
             except Exception:
                 d=dict()
                 result="Backup restore failed"
         report[method]=dict(method=method,what=m.__doc__,result=result,msg=msg,date=
                             utcdatetime2stamp_inexact(datetime.utcnow()))
         now=datetime.utcnow()
         for k,v in d.items():
             for x in v:
                 if not 'date' in x:
                     x['date']=now
                 else:
                     if x['date']>now:
                         x['date']=now
             if k=="airspaces":
                 #print "Method:",method,v
                 #for av in v:
                     #print
                     #print
                     #print av
                     #assert 'type' in av
                 airspaces.extend(v)
             elif k=="airfields":
                 airfields.extend(v)
             elif k=="bad_airfields":
                 bad_airfields.extend(v)
             elif k=="sig_points":
                 sig_points.extend(v)
             elif k=="obstacles":
                 obstacles.extend(v)
             else:
                 raise Exception("Bad return value from SpaceLoader:%s"%((k,v),))
Esempio n. 3
0
        version = int(request.params["version"])

        charts = []

        print "Client request params", request.params

        if version <= 3:
            prevstamp = int(request.params["stamp"])
            print "getnewadchart, prevstamp:", prevstamp

            #Make any sort of race impossible by substracting 5 minutes from now.
            #A race will now only happen if a file is modified on disk, after this
            #routine started, but ends up with a timestamp 5 minutes earlier in
            #time, but that can't happen.
            nowstamp = utcdatetime2stamp_inexact(datetime.utcnow()) - 60 * 5
            assert version in [1, 2, 3]
            print "Old stamp", prevstamp
            for ad in extracted_cache.get_airfields():
                if ad.get('icao', 'ZZZZ').upper() == 'ZZZZ':
                    continue  #Ignore non-icao airports
                if 'adcharts' in ad:
                    for adc in ad['adcharts'].values():
                        newer = False
                        try:
                            cksum, proj = self.get_sel_cksum(adc['blobname'])
                            if proj and proj.updated > datetime.utcfromtimestamp(
                                    prevstamp):
                                newer = True
                            #print "selected",cksum,"for",adc
                            if version <= 2 and adc['variant'] != '':
Esempio n. 4
0
        
        version=int(request.params["version"])

        charts=[]
        
        print "Client request params",request.params

        if version<=3:
            prevstamp=int(request.params["stamp"])
            print "getnewadchart, prevstamp:",prevstamp
            
            #Make any sort of race impossible by substracting 5 minutes from now.
            #A race will now only happen if a file is modified on disk, after this
            #routine started, but ends up with a timestamp 5 minutes earlier in
            #time, but that can't happen.            
            nowstamp=utcdatetime2stamp_inexact(datetime.utcnow())-60*5
            assert version in [1,2,3]
            print "Old stamp",prevstamp
            for ad in extracted_cache.get_airfields():
                if ad.get('icao','ZZZZ').upper()=='ZZZZ':continue #Ignore non-icao airports 
                if 'adcharts' in ad:
                    for adc in ad['adcharts'].values():
                        newer=False
                        try:
                            cksum,proj=self.get_sel_cksum(adc['blobname'])
                            if proj and proj.updated>datetime.utcfromtimestamp(prevstamp):
                                newer=True 
                            #print "selected",cksum,"for",adc
                            if version<=2 and adc['variant']!='':
                                continue #Don't send all kinds of charts to old clients
                            if cksum==None: continue