Skip to content
Browse files

* python/mushin/command/replicate.py:

	  Use rewrite functions; now allows replicating with
	  username/password.
  • Loading branch information...
1 parent 69a73c4 commit c1b053af5fa9f28c5c3da25e4c3e794a56af6224 Thomas Vander Stichele committed Sep 11, 2012
Showing with 19 additions and 21 deletions.
  1. +6 −0 ChangeLog
  2. +13 −21 python/mushin/command/replicate.py
View
6 ChangeLog
@@ -1,5 +1,11 @@
2012-09-11 Thomas Vander Stichele <thomas at apestaart dot org>
+ * python/mushin/command/replicate.py:
+ Use rewrite functions; now allows replicating with
+ username/password.
+
+2012-09-11 Thomas Vander Stichele <thomas at apestaart dot org>
+
* python/mushin/test/test_common_urlrewrite.py (added):
* python/mushin/common/urlrewrite.py (added):
Add module and tests to rewrite URL's using default options,
View
34 python/mushin/command/replicate.py
@@ -1,14 +1,16 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
+import urlparse
+
from twisted.internet import defer
from twisted.web import error as twerror
from paisley import pjson as json
from mushin.extern.log import log
-from mushin.common import logcommand, tcommand
+from mushin.common import logcommand, tcommand, urlrewrite
HOST = 'localhost'
PORT = 5984
@@ -23,30 +25,17 @@ def doLater(self, args):
c = self.getRootCommand()
- # FIXME: parse with a proper library, could also include auth
try:
- jane = args[0]
+ url = args[0]
except IndexError:
self.stdout.write('Please give a database to replicate with.\n')
return
- db = DB
- slash = jane.find('/')
- if slash > -1:
- db = jane[slash + 1:]
- jane = jane[:slash]
- self.debug('replicating to database %s', db)
-
- port = PORT
- colon = jane.find(':')
- if colon > -1:
- port = int(jane[colon + 1:])
- jane = jane[:colon]
- self.debug('replicating to port %d', port)
+ jane = urlrewrite.rewrite(url, hostname=HOST, port=PORT, path='/' + DB)
dbs = [
c.dbName,
- "http://%s:%d/%s" % (jane, port, db),
+ jane,
]
server = c.getNewServer()
@@ -58,8 +47,9 @@ def doLater(self, args):
"source": source,
"target": target,
"continuous": True})
- self.info('replicating from %s to %s', source, target)
- self.debug('json string: %s', s)
+ self.info('replicating from %s to %s',
+ urlrewrite.rewrite_safe(source),
+ urlrewrite.rewrite_safe(target))
try:
d = client.post('/_replicate', s)
except Exception, e:
@@ -91,15 +81,17 @@ def doLater(self, args):
try:
if r['ok']:
self.stdout.write('+ Replicating %s to %s\n' % (
- source.encode('utf-8'), target.encode('utf-8')))
+ 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' % (
- source.encode('utf-8'), target.encode('utf-8')))
+ urlrewrite.rewrite_safe(source.encode('utf-8')),
+ urlrewrite.rewrite_safe(target.encode('utf-8'))))
self.stdout.write(' %s\n' % error)
class Replicate(logcommand.LogCommand):

0 comments on commit c1b053a

Please sign in to comment.
Something went wrong with that request. Please try again.