Пример #1
0
 def create_db_and_user(self, password):
     call_process_as(
         'postgres',
         ['/usr/bin/createuser', '-DRS', '--login',
          self.get_db_user()],
         logger=database_logger)
     call_process_as('postgres', [
         '/usr/bin/createdb', '-O',
         self.get_db_user(), '-T', 'template0', '-E', 'UTF8',
         self.get_db_name()
     ],
                     logger=database_logger)
     self.execute('ALTER ROLE "%s" WITH ENCRYPTED PASSWORD \'%s\'' %
                  (self.get_db_user(), password))
Пример #2
0
	def execute(self, query):
		logger = LogCatcher()
		process = call_process_as('postgres', ['/usr/bin/psql', '-tc', query], logger=logger)
		if process.returncode:
			for level, msg in logger.logs:
				if level == 'OUT':
					database_logger.info(msg)
				elif level == 'ERR':
					database_logger.warn(msg)
			raise DatabaseError('Returncode %s for query' % process.returncode)
		return list(logger.stdout())