Beispiel #1
0
    def GetConfigs(self, config_file):
        """Process config parameters.

    Args:
      config_file: File with parameters in "param = value" format.
    Returns:
      A dictionary with config parameters and values as key/value pairs.
    """
        # Get default values for the config parameters.
        defaults = geconstants.Constants().defaults

        # Create a ConfigParser() object and read the config file.
        config_parser = ConfigParser.ConfigParser()
        config_parser.read(config_file)

        # create a dict of config parameters and values.
        configs_from_file = self._ParseConfigfile(config_parser)

        # If configs_from_file has parameters without any value specified,
        # then pick it from the defaults.
        for param, value in configs_from_file.iteritems():
            if not value:
                configs_from_file[param] = (defaults[param] if
                                            defaults.has_key(param) else None)
        return configs_from_file
    def __init__(self):
        """Inits ExampleSearch.

    Initializes the logger "ge_search".
    Initializes templates for kml, json, placemark templates
    for the KML/JSONP output.
    Initializes parameters for establishing a connection to the database.
    """

        self.utils = utils.SearchUtils()
        constants = geconstants.Constants()

        configs = self.utils.GetConfigs(
            os.path.join(geconstants.SEARCH_CONFIGS_DIR, "ExampleSearch.conf"))

        style_template = self.utils.style_template
        self._jsonp_call = self.utils.jsonp_functioncall
        self._geom = """
            <name>%s</name>
            <styleUrl>%s</styleUrl>
            <Snippet>%s</Snippet>
            <description>%s</description>
            %s\
    """
        self._json_geom = """
         {
            "name": "%s",
            "Snippet": "%s",
            "description": "%s",
            %s
         }\
    """

        self._placemark_template = self.utils.placemark_template
        self._kml_template = self.utils.kml_template

        self._json_template = self.utils.json_template
        self._json_placemark_template = self.utils.json_placemark_template

        self._example_query_template = (Template(constants.example_query))

        self.logger = self.utils.logger

        self._user = configs.get("user")
        self._hostname = configs.get("host")
        self._port = configs.get("port")

        self._database = configs.get("databasename")
        if not self._database:
            self._database = constants.defaults.get("example.database")

        self._pool = ThreadedConnectionPool(
            int(configs.get("minimumconnectionpoolsize")),
            int(configs.get("maximumconnectionpoolsize")),
            database=self._database,
            user=self._user,
            host=self._hostname,
            port=int(self._port))

        self._style = style_template.substitute(
            balloonBgColor=configs.get("balloonstyle.bgcolor"),
            balloonTextColor=configs.get("balloonstyle.textcolor"),
            balloonText=configs.get("balloonstyle.text"),
            iconStyleScale=configs.get("iconstyle.scale"),
            iconStyleHref=configs.get("iconstyle.href"),
            lineStyleColor=configs.get("linestyle.color"),
            lineStyleWidth=configs.get("linestyle.width"),
            polyStyleColor=configs.get("polystyle.color"),
            polyStyleColorMode=configs.get("polystyle.colormode"),
            polyStyleFill=configs.get("polystyle.fill"),
            polyStyleOutline=configs.get("polystyle.outline"),
            listStyleHref=configs.get("iconstyle.href"))
Beispiel #3
0
  def __init__(self):
    """Inits POISearch.

    Initializes the logger "ge_search".
    Initializes templates for kml, placemark templates for the KML output.
    Initializes parameters for establishing a connection to the database.
    """

    self.utils = utils.SearchUtils()
    constants = geconstants.Constants()

    configs = self.utils.GetConfigs(
        os.path.join(geconstants.SEARCH_CONFIGS_DIR, "PoiSearch.conf"))

    style_template = self.utils.style_template
    self._jsonp_call = self.utils.jsonp_functioncall

    self._geom = """
            <name>%s</name>,
            <styleUrl>%s</styleUrl>
            <description>%s</description>,
            %s\
    """
    self._json_geom = """
          {
            "name" : "%s",
            "description" : "%s",
            %s
          }
    """

    self._placemark_template = self.utils.placemark_template
    self._kml_template = self.utils.kml_template

    self._json_template = self.utils.json_template
    self._json_placemark_template = self.utils.json_placemark_template

    self._host_db_name_by_target_query = constants.host_db_name_by_target_query
    self._poi_info_by_host_db_name_query = (
        constants.poi_info_by_host_db_name_query)

    self.logger = logging.getLogger("ge_search")

    poisearch_database = configs.get("searchdatabasename")
    if not poisearch_database:
      poisearch_database = constants.defaults.get("poisearch.database")

    gestream_database = configs.get("streamdatabasename")
    if not gestream_database:
      gestream_database = constants.defaults.get("gestream.database")

    poiquery_database = configs.get("poidatabasename")
    if not poiquery_database:
      poiquery_database = constants.defaults.get("poiquery.database")

    self._search_pool = ThreadedConnectionPool(
        int(configs.get("minimumconnectionpoolsize")),
        int(configs.get("maximumconnectionpoolsize")),
        database=poisearch_database,
        user=configs.get("user"),
        host=configs.get("host"),
        port=int(configs.get("port")))

    self._poi_pool = ThreadedConnectionPool(
        int(configs.get("minimumconnectionpoolsize")),
        int(configs.get("maximumconnectionpoolsize")),
        database=poiquery_database,
        user=configs.get("user"),
        host=configs.get("host"),
        port=int(configs.get("port")))

    self._stream_pool = ThreadedConnectionPool(
        int(configs.get("minimumconnectionpoolsize")),
        int(configs.get("maximumconnectionpoolsize")),
        database=gestream_database,
        user=configs.get("user"),
        host=configs.get("host"),
        port=int(configs.get("port")))

    self._style = style_template.substitute(
        balloonBgColor=configs.get("balloonstyle.bgcolor"),
        balloonTextColor=configs.get("balloonstyle.textcolor"),
        balloonText=configs.get("balloonstyle.text"),
        iconStyleScale=configs.get("iconstyle.scale"),
        iconStyleHref=configs.get("iconstyle.href"),
        lineStyleColor=configs.get("linestyle.color"),
        lineStyleWidth=configs.get("linestyle.width"),
        polyStyleColor=configs.get("polystyle.color"),
        polyStyleColorMode=configs.get("polystyle.colormode"),
        polyStyleFill=configs.get("polystyle.fill"),
        polyStyleOutline=configs.get("polystyle.outline"),
        listStyleHref=configs.get("iconstyle.href"))

    # Parameters for calculating the bounding box.
    self.latitude_center = constants.latitude_center
    self.longitude_center = constants.longitude_center
    self.latitude_span = constants.latitude_span
    self.longitude_span = constants.longitude_span
    self.srid = constants.srid
    self.usebbox = configs.get("usebbox").lower() == "true"
    self.expandbbox = configs.get("expandbbox").lower() == "true"

    # Calculate default bounding box with latitude span = 180(degrees) and
    # longitude span = 360(degrees).

    self.world_bounds = self.__CreateBboxFromParameters(
        self.latitude_center, self.longitude_center,
        self.latitude_span, self.longitude_span)

    # Create federated search handler object for
    # performing super federated search.
    try:
      self._fed_search = federated_search_handler.FederatedSearch()
    except Exception as e:
      self.logger.warning("Federated search is not available due to an "
                          "unexpected error, %s.", e)
      self._fed_search = None