def replicate_existing(source_db, target_db):
<EOL>server = shortcuts.get_server()<EOL>logger = logging.getLogger('<STR_LIT>')<EOL>logger.debug('<STR_LIT>' + urllib.parse.urljoin(server.resource.uri, '<STR_LIT>'))<EOL>source, target = specifier_to_db(source_db), specifier_to_db(target_db)<EOL>logger.debug('<STR_LIT>' % (source,))<EOL>logger.debug('<STR_LIT>' % (target,))<EOL>try:<EOL><INDENT>resp_headers, resp_body = server.resource.post(path='<STR_LIT>',<EOL>content=json.dumps({'<STR_LIT:source>': source, '<STR_LIT:target>': target}))<EOL><DEDENT>except couchdb.client.ServerError as exc:<EOL><INDENT>logger.error('<STR_LIT>')<EOL>raise ReplicationError(exc.args)<EOL><DEDENT>result = resp_body['<STR_LIT>'][<NUM_LIT:0>]<EOL>if resp_body['<STR_LIT>']:<EOL><INDENT>logger.info('<STR_LIT>' % (<EOL>resp_body['<STR_LIT>'][:<NUM_LIT:6>],))<EOL>logger.info('<STR_LIT>' + result['<STR_LIT>'])<EOL>logger.info('<STR_LIT>' + result['<STR_LIT>'])<EOL>result['<STR_LIT>'] = datetime.datetime.strptime(result['<STR_LIT>'],<EOL>'<STR_LIT>')<EOL>result['<STR_LIT>'] = datetime.datetime.strptime(result['<STR_LIT>'],<EOL>'<STR_LIT>')<EOL>timedelta = result['<STR_LIT>'] - result['<STR_LIT>']<EOL>if timedelta.days:<EOL><INDENT>logger.info('<STR_LIT>' % (<EOL>timedelta.days,<EOL>timedelta.seconds + (timedelta.microseconds * (<NUM_LIT>))))<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>' % (<EOL>timedelta.seconds + (timedelta.microseconds * (<NUM_LIT>))))<EOL><DEDENT>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>if result['<STR_LIT>'] == <NUM_LIT:1>:<EOL><INDENT>docs_read = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>docs_read = '<STR_LIT>' % (result['<STR_LIT>'],)<EOL><DEDENT>if result['<STR_LIT>'] == <NUM_LIT:1>:<EOL><INDENT>docs_written = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>docs_written = '<STR_LIT>' % (result['<STR_LIT>'],)<EOL><DEDENT>if result['<STR_LIT>'] == <NUM_LIT:1>:<EOL><INDENT>missing_checked = '<STR_LIT>' % (<EOL>result['<STR_LIT>'],)<EOL><DEDENT>else:<EOL><INDENT>missing_checked = '<STR_LIT>' % (<EOL>result['<STR_LIT>'], result['<STR_LIT>'],)<EOL><DEDENT>logging.info('<STR_LIT>' % (docs_read, docs_written))<EOL>logging.info(missing_checked)<EOL>return result<EOL><DEDENT>else:<EOL><INDENT>logger.error('<STR_LIT>' % (<EOL>resp_body['<STR_LIT>'][:<NUM_LIT:6>],))<EOL>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>result['<STR_LIT>'] = resp_body['<STR_LIT>']<EOL>raise ReplicationFailure(resp_headers, result)<EOL><DEDENT>
Replicate an existing database to another existing database.