summaryrefslogtreecommitdiffstats
path: root/xlators/features
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features')
-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 fc1b42e7f..1e4f1dac5 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 b0aa93f42..cda7da7eb 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 d8166baea..9d0b00095 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 efd136075..f002f0eb1 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 000000000..52dad8c5f
--- /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)