From e139eeeb627368112aa1341d2f0ef6770dd7078e Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Wed, 10 Aug 2011 20:04:20 +0300 Subject: gsyncd: python3 compat fixes Also add __codecheck script which can verify if source is OK at the syntactical level with a given Python interpreter. Change-Id: Ieff34bcd3efd1cdc0e8f9a510c05488f35897bbe BUG: 1570 Reviewed-on: http://review.gluster.com/320 Reviewed-by: Kaushik BV Tested-by: Gluster Build System --- .../marker/utils/syncdaemon/__codecheck.py | 27 ++++++++++++++++++++++ .../marker/utils/syncdaemon/configinterface.py | 2 +- xlators/features/marker/utils/syncdaemon/master.py | 2 +- .../features/marker/utils/syncdaemon/syncdutils.py | 10 +++++--- 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 xlators/features/marker/utils/syncdaemon/__codecheck.py (limited to 'xlators/features') diff --git a/xlators/features/marker/utils/syncdaemon/__codecheck.py b/xlators/features/marker/utils/syncdaemon/__codecheck.py new file mode 100644 index 00000000000..832e75c444b --- /dev/null +++ b/xlators/features/marker/utils/syncdaemon/__codecheck.py @@ -0,0 +1,27 @@ +import os +import os.path +import sys + +fl = os.listdir(os.path.dirname(sys.argv[0]) or '.') +fl.sort() +for f in fl: + if f[-3:] != '.py' or f[0] == '_': + continue + m = f[:-3] + sys.stdout.write('importing %s ...' % m) + __import__(m) + print(' OK.') + +def sys_argv_set(a): + sys.argv = sys.argv[:1] + a + +gsyncd = sys.modules['gsyncd'] +for a in [['--help'], ['--version'], ['--canonicalize-escape-url', '/foo']]: + print('>>> invoking program with args: %s' % ' '.join(a)) + pid = os.fork() + if not pid: + sys_argv_set(a) + gsyncd.main() + _, r = os.waitpid(pid, 0) + if r: + raise RuntimeError('invocation failed') diff --git a/xlators/features/marker/utils/syncdaemon/configinterface.py b/xlators/features/marker/utils/syncdaemon/configinterface.py index fbf96c84336..e55bec519e9 100644 --- a/xlators/features/marker/utils/syncdaemon/configinterface.py +++ b/xlators/features/marker/utils/syncdaemon/configinterface.py @@ -173,7 +173,7 @@ class GConffile(object): opt = norm(opt) v = d.get(opt) if v: - print v + print(v) else: for k, v in d.iteritems(): if k == '__name__': diff --git a/xlators/features/marker/utils/syncdaemon/master.py b/xlators/features/marker/utils/syncdaemon/master.py index 4273bf0c419..de4b324214e 100644 --- a/xlators/features/marker/utils/syncdaemon/master.py +++ b/xlators/features/marker/utils/syncdaemon/master.py @@ -110,7 +110,7 @@ class GMaster(object): self.volinfo_state = (uuid_preset and {'uuid': uuid_preset}, None) # the actual volinfo we make use of self.volinfo = None - self.terminate = False + self.terminate = False def crawl_loop(self): """start the keep-alive thread and iterate .crawl""" diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py index 244e29628e0..6a08fbdaf9a 100644 --- a/xlators/features/marker/utils/syncdaemon/syncdutils.py +++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py @@ -8,7 +8,11 @@ from threading import Lock, Thread as baseThread from errno import EACCES, EAGAIN, EPIPE, ENOTCONN from signal import SIGTERM, SIGKILL from time import sleep -from cPickle import PickleError +try: + from cPickle import PickleError +except ImportError: + # py 3 + from pickle import PickleError from gconf import gconf @@ -184,7 +188,7 @@ class FreeObject(object): """wildcard class for which any attribute can be set""" def __init__(self, **kw): - for k,v in kw.iteritems(): + for k,v in kw.items(): setattr(self, k, v) class Thread(baseThread): @@ -210,5 +214,5 @@ class Thread(baseThread): baseThread.__init__(self, *a, **kw) self.setDaemon(True) -class GsyncdError(StandardError): +class GsyncdError(Exception): pass -- cgit