def __init__(self, **arguments): self.arguments = arguments self.dump_only = self.arguments.get('dump_only', None) self.region_key = self.arguments.get('schema', None) self.target_database = database_settings('default') # The config_entity whose feature tables should be imported self.config_entity = self.arguments.get('config_entity', None) if self.config_entity: logger.info( "Importing DbEntity table into ConfigEntity {0}".format( self.config_entity.subclassed)) # The optional db_entity_key whose Feature class table should be imported. Otherwise all DbEntity tables # are imported for the config_entity, including inherited ones from parent ConfigEntities self.db_entity_key = self.arguments.get('db_entity_key', None) self.db_entities = filter( lambda db_entity: not self.db_entity_key or (db_entity.key == self.db_entity_key), self.config_entity.owned_db_entities()) self.test = self.arguments.get('test', None) # The psql connection to the target server, normally the django server self.create_target_db_string() self.command_execution = CommandExecution(logger) self.target_connection_dict = dict( user=self.target_database['USER'], password=self.target_database['PASSWORD'], host=self.target_database.get('HOST', 'localhost'), port=self.target_database.get('PORT', 5432), database=self.target_database['NAME']) # Used to get around password authentication self.connections = [ "{host}:*:*:{user}:{password}".format( **dict(host=self.target_database['HOST'], user=self.target_database['USER'], password=self.target_database['PASSWORD'])) ] for db_entity in self.db_entities: # Create a password file in order to avoid dealing with stdin for passwords # This has been bypassed in favor of passing the password to stdin if not (db_entity.has_db_url or db_entity.has_file_url): raise Exception( "This db_entity, {0}, has no database or file url".format( db_entity.key)) if db_entity.has_db_url: # Setup the connection strings for the db_entity so that we can get around interactive password authentication # TODO This is never distinct per db_entity. We could just use self.target_connection_dict connection_dict = postgres_url_to_connection_dict( db_entity.url) self.connections.append( "{host}:*:*:{user}:{password}".format(**connection_dict))
def __init__(self, **arguments): self.arguments = arguments self.dump_only = self.arguments.get('dump_only', None) self.region_key = self.arguments.get('schema', None) self.target_database = database_settings('default') # The config_entity whose feature tables should be imported self.config_entity = self.arguments.get('config_entity', None) if self.config_entity: logger.info("Importing DbEntity table into ConfigEntity {0}".format(self.config_entity.subclassed)) # The optional db_entity_key whose Feature class table should be imported. Otherwise all DbEntity tables # are imported for the config_entity, including inherited ones from parent ConfigEntities self.db_entity_key = self.arguments.get('db_entity_key', None) self.db_entities = filter(lambda db_entity: not self.db_entity_key or (db_entity.key == self.db_entity_key), self.config_entity.owned_db_entities()) self.test = self.arguments.get('test', None) # The psql connection to the target server, normally the django server self.create_target_db_string() self.command_execution = CommandExecution(logger) self.target_connection_dict = dict( user=self.target_database['USER'], password=self.target_database['PASSWORD'], host=self.target_database.get('HOST', 'localhost'), port=self.target_database.get('PORT', 5432), database=self.target_database['NAME'] ) # Used to get around password authentication self.connections = ["{host}:*:*:{user}:{password}".format(**dict( host=self.target_database['HOST'], user=self.target_database['USER'], password=self.target_database['PASSWORD']))] for db_entity in self.db_entities: # Create a password file in order to avoid dealing with stdin for passwords # This has been bypassed in favor of passing the password to stdin if not (db_entity.has_db_url or db_entity.has_file_url): raise Exception("This db_entity, {0}, has no database or file url".format(db_entity.key)) if db_entity.has_db_url: # Setup the connection strings for the db_entity so that we can get around interactive password authentication # TODO This is never distinct per db_entity. We could just use self.target_connection_dict connection_dict = postgres_url_to_connection_dict(db_entity.url) self.connections.append("{host}:*:*:{user}:{password}".format(**connection_dict))
def make_mml(layer, style_attribute): """ Generates mml string from a layer and a style :param layer: Layer object :param attribute: the attribute of the layer object that is getting styled :return: """ attribute = style_attribute.attribute if style_attribute.attribute is not None else 'wkb_geometry' carto_css_style = cartocss_data(layer, style_attribute) db = database_settings(layer.config_entity.db) query = create_query(attribute, layer.config_entity, layer) db_entity = layer.db_entity_interest.db_entity # Get the base version of the feature class that holds wkb_geometry feature_class = layer.config_entity.db_entity_feature_class(db_entity.key, base_feature_class=True) return build_mml_json(db, query=query, geom_table=feature_class._meta.db_table, layer_id=layer.id, name=style_id(layer, style_attribute), cls=db_entity.key, style=carto_css_style)
def make_mml(layer, style_attribute): """ Generates mml string from a layer and a style :param layer: Layer object :param attribute: the attribute of the layer object that is getting styled :return: """ attribute = style_attribute.attribute if style_attribute.attribute is not None else 'wkb_geometry' carto_css_style = cartocss_data(layer, style_attribute) db = database_settings(layer.config_entity.db) query = create_query(attribute, layer.config_entity, layer) db_entity = layer.db_entity_interest.db_entity # Get the base version of the feature class that holds wkb_geometry feature_class = layer.config_entity.db_entity_feature_class( db_entity.key, base_feature_class=True) return build_mml_json(db, query=query, geom_table=feature_class._meta.db_table, layer_id=layer.id, name=style_id(layer, style_attribute), cls=db_entity.key, style=carto_css_style)
def get_conn_string(db_name): d = database_settings(db_name) return 'dbname=' + d['NAME'] + ' host=' + d['HOST'] + ' user='******'USER'] + ' password='******'PASSWORD']