def parseInstCostFile(self, netFName, fName):
     """ Read the network file that contains locations and prices"""
     try:
         f = open(netFName)
     except IOError:
         print >> sys.stderr, "Unable to open network_model file", \
             netFName,"defined in JSON",fName
         sys.exit()
     self.nodes = []
     while True:
         origline = f.readline()
         if origline == '':
             break
         #Skip blank lines and comments
         if origline[0] == '\n' or origline[0] == '#' or origline[0] == '%':
             continue
         l = origline.split('%')[0].split('#')[0]  # strip comments
         parts = l.split(",")
         if len(parts) != 5 and len(parts) != 6:
             print >> sys.stderr,"Lines in instanceCostNetwork file", \
                 netFName,' are expected to be 5 tuple floats or ', \
                 ' 6 tuple with zone string as third arg', \
                 'specified in JSON',fName
             print >> sys.stderr, 'Line', origline
             raise ValueError
         try:
             loc = (float(parts[0]), float(parts[1]))
             if len(parts) == 6:
                 zone = parts[2]
                 incost = float(parts[3])
                 outcost = float(parts[4])
                 instcost = float(parts[5])
             else:
                 zone = None
                 incost = float(parts[2])
                 outcost = float(parts[3])
                 instcost = float(parts[4])
         except:
             print >> sys.stderr,"Lines in instanceCostNetwork file", \
                 netFName,' are expect to have loc then in, out and ',\
                 'instcost in ',fName
             print >> sys.stderr, 'Line', origline
             raise ValueError
         if loc[0] < -90 or loc[0] > 90 or loc[1] < -180 or \
             loc[1] > 180:
             print >> sys.stderr,"Lat, long must be in ranges", \
                 '[-90,90],[-180,180] respectively in',netFName, \
                 'referenced from JSON',fName
             raise ValueError
         if incost < 0 or outcost < 0 or instcost < 0:
             print >> sys.stderr,'Specified costs must be +ve'\
                  'in',netFName, 'referenced from JSON',fName
             print >> sys.stderr, 'line', origline
             print >> sys.stderr, 'parts', parts
             raise ValueError
         self.nodes.append(datacentre.datacentre( \
             location.location(loc[0],loc[1],zone), \
             incost,outcost,instcost))
     f.close()
 def parseInstCostFile(self,netFName,fName):
     """ Read the network file that contains locations and prices"""
     try:
         f= open(netFName)
     except IOError:
         print >> sys.stderr, "Unable to open network_model file", \
             netFName,"defined in JSON",fName
         sys.exit()
     self.nodes=[]
     while True:
         origline= f.readline()
         if origline == '':
             break
         #Skip blank lines and comments
         if origline[0] == '\n' or origline[0] == '#' or origline[0] == '%':
             continue
         l=origline.split('%')[0].split('#')[0] # strip comments
         parts= l.split(",")
         if len(parts) != 5 and len(parts) != 6:
             print >> sys.stderr,"Lines in instanceCostNetwork file", \
                 netFName,' are expected to be 5 tuple floats or ', \
                 ' 6 tuple with zone string as third arg', \
                 'specified in JSON',fName
             print >> sys.stderr,'Line',origline
             raise ValueError
         try:
             loc= (float(parts[0]),float(parts[1]))
             if len(parts) == 6:
                 zone= parts[2]
                 incost= float(parts[3])
                 outcost= float(parts[4])
                 instcost= float(parts[5])
             else:
                 zone=None
                 incost= float(parts[2])
                 outcost= float(parts[3])
                 instcost= float(parts[4])
         except:
             print >> sys.stderr,"Lines in instanceCostNetwork file", \
                 netFName,' are expect to have loc then in, out and ',\
                 'instcost in ',fName
             print >> sys.stderr,'Line',origline
             raise ValueError
         if loc[0] < -90 or loc[0] > 90 or loc[1] < -180 or \
             loc[1] > 180:
             print >> sys.stderr,"Lat, long must be in ranges", \
                 '[-90,90],[-180,180] respectively in',netFName, \
                 'referenced from JSON',fName
             raise ValueError
         if incost < 0 or outcost < 0 or instcost < 0:
             print >> sys.stderr,'Specified costs must be +ve'\
                  'in',netFName, 'referenced from JSON',fName
             print >> sys.stderr,'line',origline
             print >> sys.stderr,'parts',parts
             raise ValueError
         self.nodes.append(datacentre.datacentre( \
             location.location(loc[0],loc[1],zone), \
             incost,outcost,instcost))
     f.close()
예제 #3
0
    def parseJSON(self, js, fName):
        """ parse the JSON in file fName which
        is generic to any server model"""
        try:
            self.noServers = int(js.pop("number"))
        except KeyError:
            pass
        except ValueError:
            print >> sys.stderr, "Number of servers specified in json for server model must be int in file", fName
            sys.exit()
        try:
            filename = (js.pop("file"))
        except KeyError:
            print >> sys.stderr, "Must specify 'file' in JSON for nStatic server model", fName
            sys.exit()
        try:
            fptr = open(filename, 'r')
        except IOError:
            print >> sys.stderr, "Cannot open", filename, "to read specified in", fName
            sys.exit()
        self.locMap = {}
        while True:
            l = fptr.readline()
            if l == '':
                break
            #Skip comments and blank lines
            if l[0] == '\n' or l[0] == '#' or l[0] == '%':
                continue
            l = l.split('%')[0].split('#')[0]  # strip comments
            parts = l.split(",")
            #Parse line by pairs
            if len(parts) % 2 != 1:
                print >> sys.stderr, "Lines in ", filename, "read from JSON in", fName, "must be comma separated integer pairs begun with timezone"
                sys.exit()
            locs = []
            try:
                tz = int(parts[0])
            except ValueError:
                print >> sys.stderr, "First field in", filename, "read from JSON in", fName,
                "must be integer"
                sys.exit()
            for i in range(1, len(parts), 2):
                try:
                    lat = float(parts[i])
                    lon = float(parts[i + 1])
                except ValueError:
                    print >> sys.stderr, "Lines in ", filename, "read from JSON in", fName, "must be comma separated pairs of floats"
                    print parts
                    sys.exit()
                locs.append(location.location(lat, lon))
            self.locMap[(tz, len(parts) / 2)] = locs

        fptr.close()
예제 #4
0
 def parseJSON(self,js,fName):
     """ parse the JSON in file fName which
     is generic to any server model"""
     try:
         self.noServers= int (js.pop("number"))
     except KeyError:
         pass
     except ValueError:
         print >> sys.stderr, "Number of servers specified in json for server model must be int in file",fName
         sys.exit()
     try:
         filename= (js.pop("file"))
     except KeyError:
         print >> sys.stderr, "Must specify 'file' in JSON for nStatic server model", fName
         sys.exit()
     try:
         fptr= open(filename,'r')
     except IOError:
         print >> sys.stderr, "Cannot open",filename,"to read specified in",fName
         sys.exit()
     self.locMap={}
     while True:
         l= fptr.readline()
         if l == '':
             break
         #Skip comments and blank lines
         if l[0] == '\n' or l[0] == '#' or l[0] == '%':
             continue
         l=l.split('%')[0].split('#')[0] # strip comments
         parts= l.split(",")
         #Parse line by pairs
         if len(parts) %2 != 0:
             print >> sys.stderr, "Lines in ",filename,"read from JSON in",fName,"must be comma separated integer pairs"
             sys.exit()                
         locs=[]
         for i in range(0, len(parts),2):
             try:
                 lat= float(parts[i])
                 lon= float(parts[i+1])
             except ValueError:
                 print >> sys.stderr, "Lines in ",filename,"read from JSON in",fName,"must be comma separated integer pairs"
                 print parts
                 sys.exit()
             locs.append(location.location(lat,lon))
         self.locMap[len(parts)/2]= locs
         
     fptr.close()
예제 #5
0
	def connectionMade(self):
		global DISPLAY, TESTING
		DISPLAY.connecting()
		sleep(1)
		DISPLAY.connected()
		AUDIO.connected()
		sleep(1)
		DISPLAY.gettingLocation()
		log.msg("CONNECTED TO SERVER")
		self.factory.server = self

		if not TESTING:
			startLocation = location()
		else:
			startLocation = 1

		# Request for player_num identification
		self.transport.write(json.dumps({"request": "NEWPLAYER", "location": startLocation}))
		DISPLAY.drawEIVMap(startLocation)
		sleep(3)
예제 #6
0
    def connectionMade(self):
        global DISPLAY, TESTING
        DISPLAY.connecting()
        sleep(1)
        DISPLAY.connected()
        AUDIO.connected()
        sleep(1)
        DISPLAY.gettingLocation()
        log.msg("CONNECTED TO SERVER")
        self.factory.server = self

        if not TESTING:
            startLocation = location()
        else:
            startLocation = 1

        # Request for player_num identification
        self.transport.write(
            json.dumps({
                "request": "NEWPLAYER",
                "location": startLocation
            }))
        DISPLAY.drawEIVMap(startLocation)
        sleep(3)