summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-03-10 00:40:05 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-10 07:39:17 -0800
commit50492481a2b1e5a1425598fb44d802ec047f6c2f (patch)
tree1c0ef7ab1a13e31fa707b76ba484f1c0e8471802
parentcbdf22d79ada40e483583a4277aba2faaa769892 (diff)
syncdaemon: add support from dumping urls in canonical and escaped canonical form
Signed-off-by: Kaushik BV <kaushikbv@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1570 (geosync related changes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
-rw-r--r--xlators/features/marker/utils/syncdaemon/Makefile.am2
-rw-r--r--xlators/features/marker/utils/syncdaemon/configinterface.py11
-rw-r--r--xlators/features/marker/utils/syncdaemon/gsyncd.py21
-rw-r--r--xlators/features/marker/utils/syncdaemon/resource.py8
-rw-r--r--xlators/features/marker/utils/syncdaemon/syncdutils.py11
5 files changed, 38 insertions, 15 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/Makefile.am b/xlators/features/marker/utils/syncdaemon/Makefile.am
index fc1b42e7f3f..1e4f1dac52e 100644
--- a/xlators/features/marker/utils/syncdaemon/Makefile.am
+++ b/xlators/features/marker/utils/syncdaemon/Makefile.am
@@ -1,5 +1,5 @@
syncdaemondir = $(libexecdir)/python/syncdaemon
-syncdaemon_PYTHON = gconf.py gsyncd.py __init__.py master.py README.md repce.py resource.py configinterface.py
+syncdaemon_PYTHON = gconf.py gsyncd.py __init__.py master.py README.md repce.py resource.py configinterface.py syncdutils.py
CLEANFILES =
diff --git a/xlators/features/marker/utils/syncdaemon/configinterface.py b/xlators/features/marker/utils/syncdaemon/configinterface.py
index b0aa93f4258..cda7da7ebf3 100644
--- a/xlators/features/marker/utils/syncdaemon/configinterface.py
+++ b/xlators/features/marker/utils/syncdaemon/configinterface.py
@@ -4,11 +4,8 @@ except ImportError:
# py 3
import configparser as ConfigParser
import re
-try:
- # py 3
- from urllib import parse as urllib
-except ImportError:
- import urllib
+
+import syncdutils
SECT_ORD = '__section_order__'
SECT_META = '__meta__'
@@ -33,13 +30,13 @@ class GConffile(object):
st = 'peersrx'
else:
st = 'peers'
- return ' '.join([st] + [urllib.quote_plus(u) for u in peers])
+ return ' '.join([st] + [syncdutils.escape(u) for u in peers])
@staticmethod
def parse_section(section):
sl = section.split()
st = sl.pop(0)
- sl = [urllib.unquote_plus(u) for u in sl]
+ sl = [syncdutils.unescape(u) for u in sl]
if st == 'peersrx':
sl = [re.compile(u) for u in sl]
return sl
diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py
index d8166baea53..9d0b00095d0 100644
--- a/xlators/features/marker/utils/syncdaemon/gsyncd.py
+++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py
@@ -207,6 +207,8 @@ def main_i():
store_local(o, oo, (vx, False, False), p))
op.add_option('--config-del-rx', metavar='OPT', type=str, dest='config', action='callback', callback=lambda o, oo, vx, p:
store_local(o, oo, (vx, False, True), p))
+ op.add_option('--canonicalize-url', dest='do_canon', action='callback', callback=store_local_curry('raw'))
+ op.add_option('--canonicalize-escape-url', dest='do_canon', action='callback', callback=store_local_curry('escaped'))
# precedence for sources of values: 1) commandline, 2) cfg file, 3) defaults
# -- for this to work out we need to tell apart defaults from explicitly set
@@ -215,7 +217,10 @@ def main_i():
defaults = op.get_default_values()
opts, args = op.parse_args(values=optparse.Values())
confdata = rconf.get('config')
- if not (len(args) == 2 or (len(args) == 1 and rconf.get('listen')) or (len(args) <= 2 and confdata)):
+ if not (len(args) == 2 or \
+ (len(args) == 1 and rconf.get('listen')) or \
+ (len(args) <= 2 and confdata) or \
+ rconf.get('do_canon')):
sys.stderr.write("error: incorrect number of arguments\n\n")
sys.stderr.write(op.get_usage() + "\n")
sys.exit(1)
@@ -224,11 +229,17 @@ def main_i():
# peers are regexen, don't try to parse them
canon_peers = args
else:
+ rscs = [resource.parse_url(u) for u in args]
+ dc = rconf.get('do_canon')
+ if dc:
+ for r in rscs:
+ print(r.get_url(canonical=True, escaped=(dc=='escaped')))
+ return
local = remote = None
- if args:
- local = resource.parse_url(args[0])
- if len(args) > 1:
- remote = resource.parse_url(args[1])
+ if rscs:
+ local = rscs[0]
+ if len(rscs) > 1:
+ remote = rscs[1]
if not local.can_connect_to(remote):
raise RuntimeError("%s cannot work with %s" % (local.path, remote and remote.path))
pa = ([], [])
diff --git a/xlators/features/marker/utils/syncdaemon/resource.py b/xlators/features/marker/utils/syncdaemon/resource.py
index efd1360758f..f002f0eb1c4 100644
--- a/xlators/features/marker/utils/syncdaemon/resource.py
+++ b/xlators/features/marker/utils/syncdaemon/resource.py
@@ -18,6 +18,7 @@ from gconf import gconf
import repce
from repce import RepceServer, RepceClient
from master import GMaster
+import syncdutils
UrlRX = re.compile('\A(\w+)://(.*)')
HostRX = re.compile('[a-z\d](?:[a-z\d.-]*[a-z\d])?', re.I)
@@ -287,12 +288,15 @@ class AbstractUrl(object):
def canonical_path(self):
return self.path
- def get_url(self, canonical=False):
+ def get_url(self, canonical=False, escaped=False):
if canonical:
pa = self.canonical_path()
else:
pa = self.path
- return "://".join((self.scheme(), pa))
+ u = "://".join((self.scheme(), pa))
+ if escaped:
+ u = syncdutils.escape(u)
+ return u
@property
def url(self):
diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py
new file mode 100644
index 00000000000..52dad8c5ff3
--- /dev/null
+++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py
@@ -0,0 +1,11 @@
+try:
+ # py 3
+ from urllib import parse as urllib
+except ImportError:
+ import urllib
+
+def escape(s):
+ return urllib.quote_plus(s)
+
+def unescape(s):
+ return urllib.unquote_plus(s)