def run(self): """ Imports the data and syncs dependent system components, such as GeoServer to the imported data. """ with tempfile.NamedTemporaryFile(delete=False) as f: self.passwordfile = f.name for connection in uniq(self.connections): f.write("{0}\n".format(connection)) # A pgpass file must have permissions of 0600 (or less permissive): # http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR) # Set the ENV variable to use this file os.environ['PGPASSFILE'] = self.passwordfile logger.info("Created password file at %s" % self.passwordfile) logger.info("Importing data") create_schema_command = "psql {0} -c 'CREATE SCHEMA IF NOT EXISTS {1}; GRANT ALL ON SCHEMA {1} TO public;'".format( self.target_database_connection, settings.IMPORT_SCHEMA ) results = self.command_execution.run(create_schema_command) if results.returncode: raise Exception(results.stderr.text) self.import_data() os.remove(self.passwordfile) del os.environ['PGPASSFILE']
def run(self): """ Imports the data and syncs dependent system components, such as GeoServer to the imported data. """ with tempfile.NamedTemporaryFile(delete=False) as f: self.passwordfile = f.name for connection in uniq(self.connections): f.write("{0}\n".format(connection)) # A pgpass file must have permissions of 0600 (or less permissive): # http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR) # Set the ENV variable to use this file os.environ['PGPASSFILE'] = self.passwordfile logger.info("Created password file at %s" % self.passwordfile) logger.info("Importing data") create_schema_command = "psql {0} -c 'CREATE SCHEMA IF NOT EXISTS {1}; GRANT ALL ON SCHEMA {1} TO public;'".format( self.target_database_connection, settings.IMPORT_SCHEMA) results = self.command_execution.run(create_schema_command) if results.returncode: raise Exception(results.stderr.text) self.import_data() os.remove(self.passwordfile) del os.environ['PGPASSFILE']
def _format_category_index(self, content, item): categories = self._get_categories(item) indexes = uniq(categories + self._get_indexes(item)) if categories: etree.SubElement(content, "Category").text = ",".join(categories) if indexes: etree.SubElement(content, "IndexCode").text = ",".join(indexes) else: etree.SubElement(content, "IndexCode")
def _iterate_keys(self): return uniq(self._iter(lambda d: d.keys()))
def _iterate_keys(self): # type: () -> Iterable return uniq(self._iter(lambda d: d.keys()))