def handle(self, source_spec, target_spec, *args, **options): # Set up logger logger = logging.getLogger('relax.couchdb.replicate') handler = logging.StreamHandler() handler.setFormatter(DEFAULT_FORMATTER) logger.addHandler(handler) if settings._('DEBUG', True): logger.setLevel(logging.DEBUG) logger.propagate = False # Replicate the databases logger.info('Beginning replication.') try: replicate.replicate(source_spec, target_spec) except replicate.ReplicationFailure, exc: # If there was an error, write the error output from CouchDB to a # rotated replication log file. log_filename = logrotate('replication.log') logger.error('Dumping JSON error information to "%s"' % ( log_filename,)) fp = open(log_filename, 'w') try: fp.write('response_headers = %s' % ( json.dumps(exc.response_headers),)) fp.write(os.linesep * 2) fp.write('result = %s' % ( json.dumps(exc.response_headers),)) fp.write(os.linesep) finally: fp.close()
def get_server(server_url='http://127.0.0.1:5984/'): """Return a CouchDB server instance based on Django project settings.""" return couchdb.client.Server( server_url if server_url else settings._('COUCHDB_SERVER'))