def handle(self, *args, **options): try: parsed_ip = options['ip'] patternIp = re.compile( "^([m01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]" + "\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$") patternIpAddr = re.compile( "^([m01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?" + "|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5]):(\d{1,5})$") if patternIp.match(parsed_ip) or patternIpAddr.match(parsed_ip): write_ip(parsed_ip) if not options['addrport']: ip_server = get_server_ip() app_ip = str(ip_server)[0:(len(ip_server) - 1)] + ":8000" else: app_ip = options['addrport'] self.stdout.write(self.style.SUCCESS( 'Successfully changed the ip to "%s"' % parsed_ip)) path = BASE_DIR + "/faed_management/static/kml/" # Erasing the files and Databases with KMl and # other dynamic information created during the FAED run. self.create_system_files() os.system("rm -r " + path + "*") self.clear_databases() # Creating the KMl files with the information of the Database self.create_base_kml(app_ip, path) os.system("python manage.py runserver {ip}".format(ip=app_ip)) else: self.stdout.write( self.style.error( 'Ip "%s" have an incorrect format' % parsed_ip)) except: raise CommandError('FAED cannot be raised')
def create_emergency_marker(incidence, filename, resolved=False): if not resolved: description = "Emergency" url_image = "http://maps.google.com/mapfiles/kml/shapes/caution.png" else: description = "Resolved" ip_server = get_server_ip() url_image = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/img/green_cross.png" with open(filename, "w") as kml_file: kml_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Placemark>\n" + "\t\t<name>FAED</name>\n" + "\t\t<visibility>1</visibility>\n" + "\t\t<description>" + description + "</description>\n" + "\t\t<Style>\n" + "\t\t\t<IconStyle>\n" + "\t\t\t\t<Icon>\n" + "\t\t\t\t\t<href>" + url_image + "</href>\n" + "\t\t\t\t\t<scale>100</scale>\n" + "\t\t\t\t</Icon>\n" + "\t\t\t</IconStyle>\n" + "\t\t\t<LineStyle>\n" + "\t\t\t\t<width>2</width>\n" + "\t\t\t</LineStyle>\n" + "\t\t</Style>\n" + "\t\t<Point>\n" + "\t\t\t<extrude>1</extrude>\n" + "\t\t\t<altitudeMode>relativeToGround" + "</altitudeMode>\n" + "\t\t\t<coordinates>" + str(incidence.long) + "," + str(incidence.lat) + "," + str(200) + "</coordinates>\n" + "\t\t</Point>\n" + "\t</Placemark>\n" + "</kml>")
def placemark_kml(drone, geo_point, filename): ip_server = get_server_ip() pic_url = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/img/ICON_LG_FAED.png" with open(filename, "w") as kml_file: kml_file.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Document>\n" + "\t\t<Style id=\"drone\">\n" + "\t\t\t<IconStyle>\n" + "\t\t\t\t<Icon>\n" + "\t\t\t\t\t<href>" + pic_url + "</href>\n" + "\t\t\t\t\t<scale>1.0</scale>\n" + "\t\t\t\t</Icon>\n" + "\t\t\t</IconStyle>\n" + "\t\t</Style>\n" + "\t\t<Placemark>\n" + "\t\t\t<name>" + drone.name + "</name>\n" + "\t\t\t<description>Drone covering emergency</description>\n" + "\t\t\t<styleUrl>#drone</styleUrl>\n" + "\t\t\t<Point>\n" + "\t\t\t\t<altitudeMode>relativeToGround</altitudeMode>\n" + "\t\t\t\t<coordinates>" + str(geo_point[1]) + "," + str(geo_point[0]) + "," + str(geo_point[2]) + "</coordinates>\n" + "\t\t\t</Point>\n" + "\t\t</Placemark>\n" + "\t</Document>\n" + "</kml>")
def create_drone_manage_route(path_name, id_incidence): ip_server = get_server_ip() url_file = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/kml/" + "in" + str(id_incidence) + \ "drone.kml" + "\n" manage_kml(path_name + "manage" + str(id_incidence), url_file, 0.5) Kml(name="manage" + str(id_incidence) + ".kml", url="static/kml/manage" + str(id_incidence) + ".kml").save() sync_kml_galaxy() time.sleep(2)
def create_general(filename, droppoints): ip_server = get_server_ip() url = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/kml/" with open(filename, "w") as kml_file: kml_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Document>\n") for dp in droppoints: kml_file.write("\t\t<NetworkLink>\n" + "\t\t\t<Name>" + dp + "</Name>\n" "\t\t<Link>\n" "\t\t<href>" + url + dp + "</href>\n" "\t\t</Link>\n" "\t\t</NetworkLink>\n") kml_file.write("\t</Document>\n" + "</kml>")
def create_general(filename, droppoints): ip_server = get_server_ip() url = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/kml/" with open(filename, "w") as kml_file: kml_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Document>\n") for dp in droppoints: kml_file.write("\t\t<NetworkLink>\n" + "\t\t\t<Name>" + dp + "</Name>\n" "\t\t<Link>\n" "\t\t<href>" + url + dp + "</href>\n" "\t\t</Link>\n" "\t\t</NetworkLink>\n") kml_file.write("\t</Document>\n" + "</kml>" )
def create_emergency_marker(incidence, filename, resolved=False): if not resolved: description = "Emergency" url_image = "http://maps.google.com/mapfiles/kml/shapes/caution.png" else: description = "Resolved" ip_server = get_server_ip() url_image = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \ ":8000/static/img/green_cross.png" with open(filename, "w") as kml_file: kml_file.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Placemark>\n" + "\t\t<name>FAED</name>\n" + "\t\t<visibility>1</visibility>\n" + "\t\t<description>" + description + "</description>\n" + "\t\t<Style>\n" + "\t\t\t<IconStyle>\n" + "\t\t\t\t<Icon>\n" + "\t\t\t\t\t<href>" + url_image + "</href>\n" + "\t\t\t\t\t<scale>100</scale>\n" + "\t\t\t\t</Icon>\n" + "\t\t\t</IconStyle>\n" + "\t\t\t<LineStyle>\n" + "\t\t\t\t<width>2</width>\n" + "\t\t\t</LineStyle>\n" + "\t\t</Style>\n" + "\t\t<Point>\n" + "\t\t\t<extrude>1</extrude>\n" + "\t\t\t<altitudeMode>relativeToGround" + "</altitudeMode>\n" + "\t\t\t<coordinates>" + str(incidence.long) + "," + str(incidence.lat) + "," + str(200) + "</coordinates>\n" + "\t\t</Point>\n" + "\t</Placemark>\n" + "</kml>")
def handle(self, *args, **options): try: parsed_ip = options['ip'] patternIp = re.compile( "^([m01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]" + "\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$") patternIpAddr = re.compile( "^([m01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?" + "|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])" + "\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5]):(\d{1,5})$") if patternIp.match(parsed_ip) or patternIpAddr.match(parsed_ip): write_ip(parsed_ip) if not options['addrport']: ip_server = get_server_ip() app_ip = str(ip_server)[0:(len(ip_server) - 1)] + ":8000" else: app_ip = options['addrport'] self.stdout.write( self.style.SUCCESS('Successfully changed the ip to "%s"' % parsed_ip)) path = BASE_DIR + "/faed_management/static/kml/" # Erasing the files and Databases with KMl and # other dynamic information created during the FAED run. self.create_system_files() os.system("rm -r " + path + "*") self.clear_databases() # Creating the KMl files with the information of the Database self.create_base_kml(app_ip, path) os.system("python manage.py runserver {ip}".format(ip=app_ip)) else: self.stdout.write( self.style.error('Ip "%s" have an incorrect format' % parsed_ip)) except: raise CommandError('FAED cannot be raised')