Пример #1
0
                try:
                    self.debug('CouchDB message: %r', e.message)
                    r = json.loads(e.message)
                    error = 'CouchDB returned error reason: %s' % r['reason']
                except:
                    pass
            except Exception, e:
                error = log.getExceptionMessage(e)

            if not error:
                r = json.loads(result)

                try:
                    if r['ok']:
                        self.stdout.write('+ Replicating %s to %s\n' % (
                            urlrewrite.rewrite_safe(source.encode('utf-8')),
                            urlrewrite.rewrite_safe(target.encode('utf-8'))))
                    else:
                        error = r
                except Exception, e:
                    error = 'Exception: %r\n' % e

            if error:
                self.stdout.write('- Failed to replicate %s to %s:\n' % (
                    urlrewrite.rewrite_safe(source.encode('utf-8')),
                    urlrewrite.rewrite_safe(target.encode('utf-8'))))
                self.stdout.write('  %s\n' % error.encode('utf-8'))

class Replicate(logcommand.LogCommand):
    description = """Manage replication.
"""
Пример #2
0
    def doLater(self, args):

        c = self.getRootCommand()

        try:
            url = args[0]
        except IndexError:
            self.stdout.write('Please give a database to replicate with.\n')
            return

        # urlparse really needs a scheme there
        if not url.startswith('http'):
            url = 'http://' + url

        server = c.getNewServer()
        # FIXME: don't poke privately
        client = server._couch

        # if a username was given, but no password, ask for it
        parsed = urlparse.urlparse(url)
        password = None
        if parsed.username and not parsed.password:
            password = c.getPassword(
                prompt='\nPassword for target database %s: ' % url)

        jane = urlrewrite.rewrite(url, hostname=HOST, port=PORT,
            password=password, path='/' + DB)

        dbs = [
          c.dbName,
          jane,
        ]


        for source, target in [(dbs[0], dbs[1]), (dbs[1], dbs[0])]:
            s = json.dumps({
              "source": source,
              "target": target,
              "continuous": True})
            self.info('replicating from %s to %s',
                urlrewrite.rewrite_safe(source),
                urlrewrite.rewrite_safe(target))

            try:
                d = client.post('/_replicate', s)
            except Exception, e:
                self.stdout.write('Exception %r\n', e)
                self.stdout.write(
                    'FAILED: local server failed for source %s\n' %
                        source.encode('utf-8'))
                self.stdout.write('Is the server running ?\n')
                defer.returnValue(e)
                return

            error = None # set with a non-newline string in case of error

            try:
                result = yield d
            except twerror.Error, e:
                error = 'CouchDB returned error response %r' % e.status
                try:
                    self.debug('CouchDB message: %r', e.message)
                    r = json.loads(e.message)
                    error = 'CouchDB returned error reason: %s' % r['reason']
                except:
                    pass
Пример #3
0
 def testRewriteSafe(self):
     url = urlrewrite.rewrite_safe(
         'http://*****:*****@localhost:5984/mushin')
     self.assertEquals(url, 'http://*****:*****@localhost:5984/mushin')