def GetGlobeInfoJson(self, globe_path):
   """Prepare json containing info about a map."""
   globe_info_obj = ""
   file_globe = portable_globe.Globe()
   try:
     globe_name = globe_path[
         len(tornado.web.globe_.GlobeBaseDirectory()) + 1:]
     file_globe.ServeLocalGlobeFiles(globe_path)
     globe_info = self.GlobeDescriptionAndTimestamp(file_globe)
     description = globe_info["description"]
     timestamp = globe_info["timestamp"]
     is_2d = self.JsBooleanString(file_globe.Is2d())
     is_3d = self.JsBooleanString(file_globe.Is3d())
     has_polygon = self.JsBooleanString(
         file_globe.FileExists("earth/polygon.kml"))
     is_mercator = self.JsBooleanString(self.IsMercator(file_globe))
     is_being_served = self.JsBooleanString(
         globe_path == tornado.web.globe_.GlobePath())
     globe_info_obj = (GLOBE_INFO_OBJ_TEMPLATE % (
         globe_name, timestamp, FileSizeAsString(globe_path),
         description, PosixPath(globe_path), is_2d,
         is_3d, has_polygon, is_mercator, is_being_served))
   except Exception as e:
     print "Bad globe: ", globe_name
     print e
   return globe_info_obj
Exemplo n.º 2
0
    def __init__(self, directory, is_readable_globe=False):
        """Initializes data for each globe in the given directory."""
        self.directory_ = directory
        self.globes_ = {}

        # Create dictionary for each globe indexed by the globe's name.
        for globe in self._GetNameList():
            path = os.path.join(directory, globe)
            globe_info = {
                "short_name": globe[:-4],
                "name": "%s" % globe,
                "message": "",
                "path": path,
                "info_loaded": is_readable_globe,
                "size_in_bytes": os.path.getsize(path),
                "size": utils.FileSizeAsString(path),
                "is_gee": False
            }
            if globe_info["size_in_bytes"] > GLOBE_SIZE_THRESHOLD:
                # Add access to globe internals if requested.
                if is_readable_globe:
                    try:
                        globe_info["globe"] = portable_globe.Globe(
                            globe_info["path"])
                        if globe_info["globe"].IsGee():
                            globe_info["is_gee"] = True
                            if globe_info["globe"].Is2d():
                                globe_info["is_2d"] = True
                                globe_info["is_mercator"] = True
                            else:
                                globe_info["is_2d"] = False
                                globe_info["is_mercator"] = False
                            globe_info["is_3d"] = globe_info["globe"].Is3d()
                            globe_info["description"] = self.EscapeJson(
                                globe_info["globe"].Description())
                            globe_info["timestamp"] = globe_info[
                                "globe"].Timestamp()
                            globe_info["has_polygon"] = (
                                globe_info["globe"].Polygon().find("<kml") >=
                                0)
                            globe_info["is_being_served"] = True
                        else:
                            globe_info["message"] = (
                                "Glx is corrupted or unreadable. "
                                "Check permissions.")
                    except Exception as e:
                        globe_info["message"] = e.__str__()
                else:
                    globe_info["message"] = "Glx read was not requested."
            else:
                globe_info["message"] = ("Glx is too small. "
                                         "May be being built or canceled.")
            self.globes_[globe] = globe_info
Exemplo n.º 3
0
def main():
  """Main for portable server."""
  application = tornado.web.Application([
      # Important to look for local requests first.
      (r"/local/(.*)", portable_server_base.LocalDocsHandler),
      (r"/ext/(.*)", portable_server_base.ExtHandler),
      (r".*/(\d+)/kh/flatfile/lf-(.*)", CompositeIconHandler),
      (r".*/(\d+)/kh/flatfile", CompositeFlatFileHandler),
      (r".*/(\d+)/kh/dbRoot.*", CompositeDbRootHandler),
      (r".*/(\d+)/kmllayer/(.*)", CompositeVectorLayerHandler),
      (r".*/flatfile/lf-(.*)", IconHandler),
      (r".*/flatfile", FlatFileHandler),
      (r".*/dbRoot.*", DbRootHandler),
      (r".*/MapsAdapter", JsonSearchHandler),
      (r".*/ECV4Adapter", KmlSearchHandler),
      (r".*/Portable2dPoiSearch", JsonSearchHandler),
      (r".*/Portable3dPoiSearch", KmlSearchHandler),
      (r".*/icons/(.*)", IconHandler),
      (r"/ping", PingHandler),
      (r"/info", InfoHandler),
      (r".*/(\d+)/query", CompositeQueryHandler),
      (r".*/query", QueryHandler),
      (r".*/(\d+)/(js/.*)", CompositeDocsHandler),
      (r".*/(\d+)/(kml/.*)", CompositeDocsHandler),
      (r".*/(\d+)/(license/.*)", CompositeDocsHandler),
      (r".*/(\d+)/(earth/.*)", CompositeDocsHandler),
      (r".*/(\d+)/(maps/.*)", CompositeDocsHandler),
      (r".*/(js/.*)", DocsHandler),
      (r".*/(kml/.*)", DocsHandler),
      (r".*/(license/.*)", DocsHandler),
      (r".*/(earth/.*)", DocsHandler),
      (r"/maps/gen_204", MapsGen204Handler),
      (r".*/(maps/.*)", DocsHandler),
      (r"/eb_balloon", BalloonHandler),
      (r"/(.*)", portable_web_interface.SetUpHandler),
      ])

  prepare_for_io_loop()

  tornado.web.globe_ = portable_globe.Globe()
  tornado.web.local_server_ = local_server.LocalServer()
  http_server = tornado.httpserver.HTTPServer(application)
  if tornado.web.globe_.config_.DisableBroadcasting():
    http_server.listen(tornado.web.globe_.Port(), address="127.0.0.1")
  else:
    http_server.listen(tornado.web.globe_.Port())
  tornado.ioloop.IOLoop.instance().start()