Exemple #1
0
    def __init__(self, server="dds.cr.usgs.gov",
                 directory="/srtm/version2_1/SRTM3/",
                 cachedir=None,
                 offline=0):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                cachedir = os.path.join(tempfile.gettempdir(), 'MAVProxySRTM')

        self.offline = offline
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
	'''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
                r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.childFileListDownload = None
        self.childTileDownload = None
Exemple #2
0
def save_graph(graphdef):
    '''save a graph as XML'''
    if graphdef.filename is None:
        if 'HOME' in os.environ:
            dname = os.path.join(os.environ['HOME'], '.mavproxy')
            mp_util.mkdir_p(dname)
            graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        else:
            graphdef.filename = 'mavgraphs.xml'
    if graphdef.filename is None:
        mestate.console.writeln("No file to save graph to", fg='red')
        return
    graphs = load_graph_xml(open(graphdef.filename).read(), graphdef.filename, load_all=True)
    found_name = False
    for i in range(len(graphs)):
        if graphs[i].name == graphdef.name:
            graphs[i] = graphdef
            found_name = True
            break
    if not found_name:
        graphs.append(graphdef)
    mestate.console.writeln("Saving %u graphs to %s" % (len(graphs), graphdef.filename))
    f = open(graphdef.filename, "w")
    f.write("<graphs>\n\n")
    for g in graphs:
        f.write(" <graph name='%s'>\n" % g.name.strip())
        if g.description is None:
            g.description = ''
        f.write("  <description>%s</description>\n" % g.description.strip())
        for e in g.expressions:
            f.write("  <expression>%s</expression>\n" % e.strip())
        f.write(" </graph>\n\n")
    f.write("</graphs>\n")
    f.close()
Exemple #3
0
    def __init__(self,
                 server="firmware.ardupilot.org",
                 directory="/SRTM/",
                 cachedir=None,
                 offline=0,
                 debug=False):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                cachedir = os.path.join(tempfile.gettempdir(), 'MAVProxySRTM')

        self.debug = debug
        self.offline = offline
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
        '''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
            r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.min_filelist_len = 14500
Exemple #4
0
    def __init__(self, server="firmware.ardupilot.org",
                 directory="/SRTM/",
                 cachedir=None,
                 offline=0,
                 debug=False):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                cachedir = os.path.join(tempfile.gettempdir(), 'MAVProxySRTM')

        self.debug = debug
        self.offline = offline
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
	'''print "SRTMDownloader - server= %s, directory=%s." % \
              (self.server, self.directory)'''
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
                r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.min_filelist_len = 14500
Exemple #5
0
	def __init__(self, cache_path=None, download=True, cache_size=500,
		     service="MicrosoftSat", tile_delay=0.3, debug=False,
		     max_zoom=19, refresh_age=30*24*60*60):
		
		if cache_path is None:
			try:
				cache_path = os.path.join(os.environ['HOME'], '.tilecache')
			except Exception:
				import tempfile
				cache_path = os.path.join(tempfile.gettempdir(), 'MAVtilecache')

		if not os.path.exists(cache_path):
			mp_util.mkdir_p(cache_path)

		self.cache_path = cache_path
		self.max_zoom = max_zoom
		self.min_zoom = 1
		self.download = download
		self.cache_size = cache_size
		self.tile_delay = tile_delay
		self.service = service
		self.debug = debug
                self.refresh_age = refresh_age

		if service not in TILE_SERVICES:
			raise TileException('unknown tile service %s' % service)

		# _download_pending is a dictionary of TileInfo objects
		self._download_pending = {}
		self._download_thread = None
                self._loading = mp_icon('loading.jpg')
		self._unavailable = mp_icon('unavailable.jpg')
		self._tile_cache = collections.OrderedDict()
def save_graph(graphdef):
    '''save a graph as XML'''
    if graphdef.filename is None:
        if 'HOME' in os.environ:
            dname = os.path.join(os.environ['HOME'], '.mavproxy')
            mp_util.mkdir_p(dname)
            graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        else:
            graphdef.filename = 'mavgraphs.xml'
    if graphdef.filename is None:
        mestate.console.writeln("No file to save graph to", fg='red')
        return
    graphs = load_graph_xml(open(graphdef.filename).read(), graphdef.filename, load_all=True)
    found_name = False
    for i in range(len(graphs)):
        if graphs[i].name == graphdef.name:
            graphs[i] = graphdef
            found_name = True
            break
    if not found_name:
        graphs.append(graphdef)
    mestate.console.writeln("Saving %u graphs to %s" % (len(graphs), graphdef.filename))
    f = open(graphdef.filename, "w")
    f.write("<graphs>\n\n")
    for g in graphs:
        f.write(" <graph name='%s'>\n" % g.name.strip())
        if g.description is None:
            g.description = ''
        f.write("  <description>%s</description>\n" % g.description.strip())
        for e in g.expressions:
            f.write("  <expression>%s</expression>\n" % e.strip())
        f.write(" </graph>\n\n")
    f.write("</graphs>\n")
    f.close()
Exemple #7
0
    def downloader(self):
        '''the download thread'''
        while self.tiles_pending() > 0:
            time.sleep(self.tile_delay)

            keys = self._download_pending.keys()[:]

            # work out which one to download next, choosing by request_time
            tile_info = self._download_pending[keys[0]]
            for key in keys:
                if self._download_pending[
                        key].request_time > tile_info.request_time:
                    tile_info = self._download_pending[key]

            url = tile_info.url(self.service)
            path = self.tile_to_path(tile_info)
            key = tile_info.key()

            try:
                if self.debug:
                    print("Downloading %s [%u left]" % (url, len(keys)))
                resp = urllib2.urlopen(url)
                headers = resp.info()
            except urllib2.URLError as e:
                #print('Error loading %s' % url)
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                if self.debug:
                    print("Failed %s: %s" % (url, str(e)))
                continue
            if 'content-type' not in headers or headers['content-type'].find(
                    'image') == -1:
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                if self.debug:
                    print("non-image response %s" % url)
                continue
            else:
                img = resp.read()

            # see if its a blank/unavailable tile
            md5 = hashlib.md5(img).hexdigest()
            if md5 in BLANK_TILES:
                if self.debug:
                    print("blank tile %s" % url)
                self._tile_cache[key] = self._unavailable
                self._download_pending.pop(key)
                continue

            mp_util.mkdir_p(os.path.dirname(path))
            h = open(path + '.tmp', 'wb')
            h.write(img)
            h.close()
            try:
                os.unlink(path)
            except Exception:
                pass
            os.rename(path + '.tmp', path)
            self._download_pending.pop(key)
        self._download_thread = None
	def downloader(self):
		'''the download thread'''
		while self.tiles_pending() > 0:
			time.sleep(self.tile_delay)

			keys = self._download_pending.keys()[:]

			# work out which one to download next, choosing by request_time
			tile_info = self._download_pending[keys[0]]
			for key in keys:
				if self._download_pending[key].request_time > tile_info.request_time:
					tile_info = self._download_pending[key]

			url = tile_info.url(self.service)
			path = self.tile_to_path(tile_info)
			key = tile_info.key()

			try:
				if self.debug:
					print("Downloading %s [%u left]" % (url, len(keys)))
				resp = urllib2.urlopen(url)
				headers = resp.info()
			except urllib2.URLError as e:
				#print('Error loading %s' % url)
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				if self.debug:
					print("Failed %s: %s" % (url, str(e)))
				continue
			if 'content-type' not in headers or headers['content-type'].find('image') == -1:
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				if self.debug:
					print("non-image response %s" % url)
				continue
			else:
				img = resp.read()

			# see if its a blank/unavailable tile
			md5 = hashlib.md5(img).hexdigest()
			if md5 in BLANK_TILES:
				if self.debug:
					print("blank tile %s" % url)
				self._tile_cache[key] = self._unavailable
				self._download_pending.pop(key)
				continue

			mp_util.mkdir_p(os.path.dirname(path))
			h = open(path+'.tmp','wb')
			h.write(img)
			h.close()
                        try:
                                os.unlink(path)
                        except Exception:
                                pass
                        os.rename(path+'.tmp', path)
			self._download_pending.pop(key)
		self._download_thread = None
Exemple #9
0
def save_graph(graphdef):
    '''save a graph as XML'''
    if graphdef.filename is None:
        if 'HOME' in os.environ:
            dname = os.path.join(os.environ['HOME'], '.mavproxy')
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        elif 'LOCALAPPDATA' in os.environ:
            dname = os.path.join(os.environ['LOCALAPPDATA'], 'MAVProxy')
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        else:
            graphdef.filename = 'mavgraphs.xml'
    if graphdef.filename is None:
        print("No file to save graph to")
        return
    contents = None
    try:
        contents = open(graphdef.filename).read()
        graphs = load_graph_xml(contents, graphdef.filename, load_all=True)
    except Exception as ex:
        graphs = []
    if contents is not None and len(graphs) == 0:
        print("Unable to parse %s" % graphdef.filename)
        return
    if contents is not None:
        try:
            open(graphdef.filename + ".bak", 'w').write(contents)
        except Exception:
            pass
    found_name = False
    for i in range(len(graphs)):
        if graphs[i].name == graphdef.name:
            graphs[i] = graphdef
            found_name = True
            break
    if not found_name:
        graphs.append(graphdef)
    pipe_console_input.send("Saving %u graphs to %s" %
                            (len(graphs), graphdef.filename))
    f = open(graphdef.filename, "w")
    f.write("<graphs>\n\n")
    for g in graphs:
        f.write(" <graph name='%s'>\n" % g.name.strip())
        if g.description is None:
            g.description = ''
        f.write("  <description>%s</description>\n" % g.description.strip())
        for e in g.expressions:
            f.write("  <expression>%s</expression>\n" % e.strip())
        f.write(" </graph>\n\n")
    f.write("</graphs>\n")
    f.close()
Exemple #10
0
    def __init__(self,
                 cache_path=None,
                 download=True,
                 cache_size=500,
                 service="MicrosoftSat",
                 tile_delay=0.3,
                 debug=False,
                 max_zoom=19,
                 refresh_age=30 * 24 * 60 * 60):

        if cache_path is None:
            try:
                cache_path = os.path.join(os.environ['HOME'], '.tilecache')
            except Exception:
                if 'LOCALAPPDATA' in os.environ:
                    cache_path = os.path.join(os.environ['LOCALAPPDATA'],
                                              '.tilecache')
                else:
                    import tempfile
                    cache_path = os.path.join(tempfile.gettempdir(),
                                              '.tilecache')

        if not os.path.exists(cache_path):
            mp_util.mkdir_p(cache_path)

        self.cache_path = cache_path
        self.max_zoom = max_zoom
        self.min_zoom = 4
        self.download = download
        self.cache_size = cache_size
        self.tile_delay = tile_delay
        self.service = service
        self.debug = debug
        self.refresh_age = refresh_age

        if service not in TILE_SERVICES:
            raise TileException('unknown tile service %s' % service)

        # _download_pending is a dictionary of TileInfo objects
        self._download_pending = {}
        self._download_thread = None
        self._loading = mp_icon('loading.jpg')
        self._unavailable = mp_icon('unavailable.jpg')
        try:
            self._tile_cache = collections.OrderedDict()
        except AttributeError:
            # OrderedDicts in python 2.6 come from the ordereddict module
            # which is a 3rd party package, not in python2.6 distribution
            import ordereddict
            self._tile_cache = ordereddict.OrderedDict()
Exemple #11
0
    def __init__(
        self,
        cache_path=None,
        download=True,
        cache_size=500,
        service="MicrosoftSat",
        tile_delay=0.3,
        debug=False,
        max_zoom=19,
        refresh_age=30 * 24 * 60 * 60,
    ):

        if cache_path is None:
            try:
                cache_path = os.path.join(os.environ["HOME"], ".tilecache")
            except Exception:
                import tempfile

                cache_path = os.path.join(tempfile.gettempdir(), "MAVtilecache")

        if not os.path.exists(cache_path):
            mp_util.mkdir_p(cache_path)

        self.cache_path = cache_path
        self.max_zoom = max_zoom
        self.min_zoom = 1
        self.download = download
        self.cache_size = cache_size
        self.tile_delay = tile_delay
        self.service = service
        self.debug = debug
        self.refresh_age = refresh_age

        if service not in TILE_SERVICES:
            raise TileException("unknown tile service %s" % service)

            # _download_pending is a dictionary of TileInfo objects
        self._download_pending = {}
        self._download_thread = None
        self._loading = mp_icon("loading.jpg")
        self._unavailable = mp_icon("unavailable.jpg")
        try:
            self._tile_cache = collections.OrderedDict()
        except AttributeError:
            # OrderedDicts in python 2.6 come from the ordereddict module
            # which is a 3rd party package, not in python2.6 distribution
            import ordereddict

            self._tile_cache = ordereddict.OrderedDict()
Exemple #12
0
def save_graph(graphdef):
    '''save a graph as XML'''
    if graphdef.filename is None:
        if 'HOME' in os.environ:
            dname = os.path.join(os.environ['HOME'], '.mavproxy')
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        elif 'LOCALAPPDATA' in os.environ:
            dname = os.path.join(os.environ['LOCALAPPDATA'], 'MAVProxy')
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
        else:
            graphdef.filename = 'mavgraphs.xml'
    if graphdef.filename is None:
        print("No file to save graph to")
        return
    try:
        graphs = load_graph_xml(open(graphdef.filename).read(), graphdef.filename, load_all=True)
    except Exception:
        graphs = []
    found_name = False
    for i in range(len(graphs)):
        if graphs[i].name == graphdef.name:
            graphs[i] = graphdef
            found_name = True
            break
    if not found_name:
        graphs.append(graphdef)
    pipe_console_input.send("Saving %u graphs to %s" % (len(graphs), graphdef.filename))
    f = open(graphdef.filename, "w")
    f.write("<graphs>\n\n")
    for g in graphs:
        f.write(" <graph name='%s'>\n" % g.name.strip())
        if g.description is None:
            g.description = ''
        f.write("  <description>%s</description>\n" % g.description.strip())
        for e in g.expressions:
            f.write("  <expression>%s</expression>\n" % e.strip())
        f.write(" </graph>\n\n")
    f.write("</graphs>\n")
    f.close()
Exemple #13
0
def save_graph(graphdef, mestate):
    """save a graph as XML"""
    if graphdef.filename is None:
        if "HOME" in os.environ:
            dname = os.path.join(os.environ["HOME"], ".mavproxy")
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, "mavgraphs.xml")
        elif "LOCALAPPDATA" in os.environ:
            dname = os.path.join(os.environ["LOCALAPPDATA"], "MAVProxy")
            if os.path.exists(dname):
                mp_util.mkdir_p(dname)
                graphdef.filename = os.path.join(dname, "mavgraphs.xml")
        else:
            graphdef.filename = "mavgraphs.xml"
    if graphdef.filename is None:
        mestate.console.writeln("No file to save graph to", fg="red")
        return
    try:
        graphs = load_graph_xml(open(graphdef.filename).read(), graphdef.filename, load_all=True)
    except Exception:
        graphs = []
    found_name = False
    for i in range(len(graphs)):
        if graphs[i].name == graphdef.name:
            graphs[i] = graphdef
            found_name = True
            break
    if not found_name:
        graphs.append(graphdef)
    mestate.console.writeln("Saving %u graphs to %s" % (len(graphs), graphdef.filename))
    f = open(graphdef.filename, "w")
    f.write("<graphs>\n\n")
    for g in graphs:
        f.write(" <graph name='%s'>\n" % g.name.strip())
        if g.description is None:
            g.description = ""
        f.write("  <description>%s</description>\n" % g.description.strip())
        for e in g.expressions:
            f.write("  <expression>%s</expression>\n" % e.strip())
        f.write(" </graph>\n\n")
    f.write("</graphs>\n")
    f.close()
Exemple #14
0
    def __init__(self,
                 cache_path=None,
                 download=True,
                 cache_size=500,
                 service="MicrosoftSat",
                 tile_delay=0.3,
                 debug=False,
                 max_zoom=19):

        if cache_path is None:
            try:
                cache_path = os.path.join(os.environ['HOME'], '.tilecache')
            except Exception:
                import tempfile
                cache_path = os.path.join(tempfile.gettempdir(),
                                          'MAVtilecache')

        if not os.path.exists(cache_path):
            mp_util.mkdir_p(cache_path)

        self.cache_path = cache_path
        self.max_zoom = max_zoom
        self.min_zoom = 1
        self.download = download
        self.cache_size = cache_size
        self.tile_delay = tile_delay
        self.service = service
        self.debug = debug

        if service not in TILE_SERVICES:
            raise TileException('unknown tile service %s' % service)

        # _download_pending is a dictionary of TileInfo objects
        self._download_pending = {}
        self._download_thread = None
        self._loading = os.path.join(os.path.dirname(__file__), 'data',
                                     'loading.jpg')
        self._unavailable = os.path.join(os.path.dirname(__file__), 'data',
                                         'unavailable.jpg')
        self._tile_cache = collections.OrderedDict()
Exemple #15
0
    def __init__(self,
                 server="firmware.ardupilot.org",
                 directory="/SRTM/",
                 cachedir=None,
                 offline=0,
                 debug=False,
                 use_http=False):

        if cachedir is None:
            try:
                cachedir = os.path.join(os.environ['HOME'], '.tilecache/SRTM')
            except Exception:
                if 'LOCALAPPDATA' in os.environ:
                    cachedir = os.path.join(os.environ['LOCALAPPDATA'],
                                            '.tilecache/SRTM')
                else:
                    import tempfile
                    cachedir = os.path.join(tempfile.gettempdir(),
                                            'MAVProxySRTM')

        self.debug = debug
        self.offline = offline
        self.offlinemessageshown = 0
        if self.offline == 1 and self.debug:
            print("Map Module in Offline mode")
        self.first_failure = False
        self.server = server
        self.directory = directory
        self.cachedir = cachedir
        if self.debug:
            print("SRTMDownloader - server=%s, directory=%s." %
                  (self.server, self.directory))
        if not os.path.exists(cachedir):
            mp_util.mkdir_p(cachedir)
        self.filelist = {}
        self.filename_regex = re.compile(
            r"([NS])(\d{2})([EW])(\d{3})\.hgt\.zip")
        self.filelist_file = os.path.join(self.cachedir, "filelist_python")
        self.min_filelist_len = 14500
        self.use_http = use_http