Skip to content

Commit 210525e

Browse files
committed
cleanup and enable py39 tests
1 parent 71f5c0f commit 210525e

17 files changed

+111
-119
lines changed

bin/zkinitree.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: latin-1 -*-
32
#
43
# Copyright 2013-2023 Ghent University
54
#
@@ -64,9 +63,9 @@ def main():
6463
# Iterate paths
6564
for path, attrs in znodes.iteritems():
6665
logger.debug("path %s attribs %s", path, attrs)
67-
acls = dict((arg, attrs[arg]) for arg in attrs if arg not in ('value', 'ephemeral', 'sequence', 'makepath'))
66+
acls = {arg: attrs[arg] for arg in attrs if arg not in ('value', 'ephemeral', 'sequence', 'makepath')}
6867
acl_list = parse_acls(acls, users, root_acl)
69-
kwargs = dict((arg, attrs[arg]) for arg in attrs if arg in ('ephemeral', 'sequence', 'makepath'))
68+
kwargs = {arg: attrs[arg] for arg in attrs if arg in ('ephemeral', 'sequence', 'makepath')}
7069
if not zkclient.exists_znode(path):
7170
zkclient.make_znode(path, value=attrs.get('value', ''), acl=acl_list, **kwargs)
7271
else:

bin/zkrsync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: latin-1 -*-
32
#
43
# Copyright 2013-2023 Ghent University
54
#
@@ -239,7 +238,7 @@ def main():
239238
# Pathbuilding (Source clients and pathsonly ) specific options:
240239
'rsubpaths' : ('rsync subpaths, specified as <depth>_<path>, with deepest paths last',
241240
'strlist', 'store', None),
242-
'excludere' : ('Exclude from pathbuilding', None, 'regex', re.compile('/\.snapshots(/.*|$)')),
241+
'excludere' : ('Exclude from pathbuilding', None, 'regex', re.compile(r'/\.snapshots(/.*|$)')),
243242
'excl_usr' : ('If set, exclude paths for this user only when using excludere', None, 'store', 'root'),
244243
'depth' : ('queue depth', "int", 'store', 3),
245244
# Source clients options; should be the same on all clients of the session!:

lib/vsc/zk/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2009-2023 Ghent University
43
#

lib/vsc/zk/base.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2013-2023 Ghent University
43
#
@@ -48,7 +47,7 @@ class RunWatchLoopLog(RunAsyncLoopLog):
4847
def __init__(self, cmd, **kwargs):
4948

5049
self.watchclient = kwargs.pop('watchclient', None)
51-
super(RunWatchLoopLog, self).__init__(cmd, **kwargs)
50+
super().__init__(cmd, **kwargs)
5251
self.log.debug("watchclient %s registered", self.watchclient)
5352

5453

@@ -57,7 +56,7 @@ def _loop_process_output(self, output):
5756
send it to the logger. The logger need to be stream-like
5857
When watch is ready, stop
5958
"""
60-
super(RunWatchLoopLog, self)._loop_process_output(output)
59+
super()._loop_process_output(output)
6160
# self.log.debug("watchclient status %s" % self.watchclient.is_ready())
6261
if self.watchclient.is_ready():
6362
self.log.debug("watchclient %s ready", self.watchclient)
@@ -87,7 +86,7 @@ def __init__(self, hosts, session=None, name=None, default_acl=None, auth_data=N
8786
'auth_data' : auth_data,
8887
# 'logger' : self.log
8988
}
90-
super(VscKazooClient, self).__init__(**kwargs)
89+
super().__init__(**kwargs)
9190
self.start()
9291
self.log.debug('Zookeeper client started')
9392

@@ -117,7 +116,7 @@ def join_parties(self, parties=None):
117116
self.log.debug("Joining %s parties: %s", len(parties), ", ".join(parties))
118117
for party in parties:
119118

120-
partypath = '%s/%s/parties/%s' % (self.BASE_ZNODE, self.session, party)
119+
partypath = f'{self.BASE_ZNODE}/{self.session}/parties/{party}'
121120
thisparty = Party(self, partypath, self.whoami)
122121
thisparty.join()
123122
self.parties[party] = thisparty
@@ -133,11 +132,11 @@ def znode_path(self, znode=None):
133132
if isinstance(znode, str):
134133
if not znode.startswith(base_znode_string):
135134
if not znode.startswith('/'):
136-
znode = '%s/%s' % (self.BASE_ZNODE, znode)
135+
znode = f'{self.BASE_ZNODE}/{znode}'
137136
else:
138-
self.log.raiseException('path %s not subpath of %s ' % (znode, base_znode_string))
137+
self.log.raiseException(f'path {znode} not subpath of {base_znode_string} ')
139138
else:
140-
self.log.raiseException('Unsupported znode type %s (znode %s)' % (znode, type(znode)))
139+
self.log.raiseException(f'Unsupported znode type {znode} (znode {type(znode)})')
141140
self.log.debug("znode %s", znode)
142141
return znode
143142

@@ -148,9 +147,9 @@ def make_znode(self, znode=None, value="", acl=None, **kwargs):
148147
try:
149148
znode = self.create(znode_path, value=value.encode(), acl=acl, **kwargs)
150149
except NodeExistsError:
151-
self.log.raiseException('znode %s already exists' % znode_path)
150+
self.log.raiseException(f'znode {znode_path} already exists')
152151
except NoNodeError:
153-
self.log.raiseException('parent node(s) of znode %s missing' % znode_path)
152+
self.log.raiseException(f'parent node(s) of znode {znode_path} missing')
154153

155154
self.log.debug("znode %s created in zookeeper", znode)
156155
return znode
@@ -177,28 +176,28 @@ def znode_acls(self, znode=None, acl=None):
177176
try:
178177
self.set_acls(znode_path, acl)
179178
except NoAuthError:
180-
self.log.raiseException('No valid authentication for (%s) on path %s!' % (self.auth_data, znode_path))
179+
self.log.raiseException(f'No valid authentication for ({self.auth_data}) on path {znode_path}!')
181180
except NoNodeError:
182-
self.log.raiseException('node %s doesn\'t exists' % znode_path)
181+
self.log.raiseException(f'node {znode_path} doesn\'t exists')
183182

184183
self.log.debug("added ACL for znode %s in zookeeper", znode_path)
185184

186185
def set_watch_value(self, watch, value):
187186
"""Sets the value of an existing watch"""
188-
watchpath = '%s/%s' % (self.watchpath, watch)
187+
watchpath = f'{self.watchpath}/{watch}'
189188
self.set(watchpath, value.encode())
190189

191190
def new_watch(self, watch, value):
192191
""" Start a watch other clients can register to """
193-
watchpath = '%s/%s' % (self.watchpath, watch)
192+
watchpath = f'{self.watchpath}/{watch}'
194193
if self.exists(watchpath):
195194
self.log.error('watchnode %s already exists!', watchpath)
196195
return False
197196
return self.make_znode(watchpath, value, makepath=True)
198197

199198
def remove_watch(self, watch):
200199
""" Removes a wath """
201-
watchpath = '%s/%s' % (self.watchpath, watch)
200+
watchpath = f'{self.watchpath}/{watch}'
202201
self.delete(watchpath)
203202

204203
def set_ready(self):
@@ -228,7 +227,7 @@ def exit(self):
228227

229228
def ready_with_stop_watch(self):
230229
"""Register to watch and set to ready when watch is set to 'stop' """
231-
watchpath = '%s/%s' % (self.watchpath, 'ready')
230+
watchpath = f'{self.watchpath}/ready'
232231
@self.DataWatch(watchpath)
233232
# pylint: disable=unused-variable,unused-argument
234233
def ready_watcher(data, stat):

lib/vsc/zk/depthwalk.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2013-2023 Ghent University
43
#
@@ -125,9 +124,9 @@ def get_pathlist(path, depth, exclude_re=None, exclude_usr=None, rsubpaths=None)
125124
subdepth, subpath = encsubpath.split('_', 1)
126125
subpath = subpath.rstrip(os.path.sep)
127126
if not subpath.startswith(path):
128-
subpath = '%s/%s' % (path, subpath)
127+
subpath = f'{path}/{subpath}'
129128
if subpath not in pathdict:
130-
logger.raiseException('%s is not in the pathlist of %s with depth %d!' % (subpath, path, depth))
129+
logger.raiseException(f'{subpath} is not in the pathlist of {path} with depth {int(depth)}!')
131130

132131
subpathdepth = subpath.count(os.path.sep)
133132
newdepth = subpathdepth + int(subdepth)
@@ -147,7 +146,7 @@ def get_pathlist(path, depth, exclude_re=None, exclude_usr=None, rsubpaths=None)
147146
def encode_paths(pathlist):
148147
enclist = []
149148
for (path, rec) in pathlist:
150-
enclist.append("%i_%s" % (rec, path))
149+
enclist.append(f"{int(rec)}_{path}")
151150
logger.debug("encoded list is %s", enclist)
152151
return enclist
153152

lib/vsc/zk/rsync/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2009-2023 Ghent University
43
#

lib/vsc/zk/rsync/controller.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2013-2023 Ghent University
43
#
@@ -63,16 +62,16 @@ def __init__(self, hosts, session=None, name=None, default_acl=None,
6362
}
6463
self.netcat = netcat
6564

66-
super(RsyncController, self).__init__(**kwargs)
65+
super().__init__(**kwargs)
6766

6867
self.rsyncpath = rsyncpath.rstrip(os.path.sep)
6968

7069
if not netcat:
7170
if verifypath and not self.basepath_ok():
72-
self.log.raiseException('Path does not exists in filesystem: %s' % rsyncpath)
71+
self.log.raiseException(f'Path does not exists in filesystem: {rsyncpath}')
7372
if not os.path.isdir(self.RSDIR):
7473
os.mkdir(self.RSDIR, 0o700)
75-
self.module = 'zkrs-%s' % self.session
74+
self.module = f'zkrs-{self.session}'
7675

7776
self.dest_queue = LockingQueue(self, self.znode_path(self.session + '/destQueue'))
7877
self.verifypath = verifypath
@@ -90,10 +89,10 @@ def basepath_ok(self):
9089

9190
def dest_state(self, dest, state):
9291
""" Set the destination to a different state """
93-
destdir = '%s/dests' % self.session
92+
destdir = f'{self.session}/dests'
9493
self.ensure_path(self.znode_path(destdir))
9594
lock = self.Lock(self.znode_path(self.session + '/destslock'), dest)
96-
destpath = '%s/%s' % (destdir, dest)
95+
destpath = f'{destdir}/{dest}'
9796
with lock:
9897
if not self.exists_znode(destpath):
9998
self.make_znode(destpath, ephemeral=True)
@@ -110,4 +109,3 @@ def dest_state(self, dest, state):
110109
else:
111110
self.log.error('No valid state: %s ', state)
112111
return None
113-

lib/vsc/zk/rsync/destination.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: latin-1 -*-
21
#
32
# Copyright 2013-2023 Ghent University
43
#
@@ -46,7 +45,7 @@ class RunDestination(RunWatchLoopLog):
4645

4746
def __init__(self, cmd, **kwargs):
4847

49-
super(RunDestination, self).__init__(cmd, **kwargs)
48+
super().__init__(cmd, **kwargs)
5049
self.registered = False
5150
self.paused = False
5251

@@ -56,7 +55,7 @@ def _loop_process_output(self, output):
5655
Register destination after 2 loops.
5756
When watch is ready, stop
5857
"""
59-
super(RunDestination, self)._loop_process_output(output)
58+
super()._loop_process_output(output)
6059

6160
if self.watchclient.verifypath and (self._loop_count % self.WAITLOOPS == 0):
6261
if self.watchclient.basepath_ok():
@@ -102,13 +101,13 @@ def __init__(self, hosts, session=None, name=None, default_acl=None,
102101
host = socket.getfqdn()
103102
if domain:
104103
hname = host.split('.', 1)
105-
host = '%s.%s' % (hname[0], domain)
104+
host = f'{hname[0]}.{domain}'
106105
self.daemon_host = host
107106
self.daemon_port = rsyncport
108107
self.start_port = startport
109108
self.port = None
110109

111-
super(RsyncDestination, self).__init__(**kwargs)
110+
super().__init__(**kwargs)
112111

113112
def get_whoami(self, name=None): # Override base method
114113
"""Create a unique name for this client"""
@@ -141,25 +140,25 @@ def generate_daemon_config(self):
141140

142141
def reserve_port(self):
143142
""" Search for an available port """
144-
portdir = '%s/usedports/%s' % (self.session, self.daemon_host)
143+
portdir = f'{self.session}/usedports/{self.daemon_host}'
145144
self.ensure_path(self.znode_path(portdir))
146145
lock = self.Lock(self.znode_path(self.session + '/portlock'), self.whoami)
147146
with lock:
148147
if self.daemon_port:
149148
port = self.daemon_port
150-
portpath = '%s/%s' % (portdir, port)
149+
portpath = f'{portdir}/{port}'
151150
if self.exists_znode(portpath):
152151
self.log.raiseException('Port already in use: %s', port)
153152

154153
else:
155154
port = self.start_port
156-
portpath = '%s/%s' % (portdir, port)
157-
while (self.exists_znode(portpath)):
155+
portpath = f'{portdir}/{port}'
156+
while self.exists_znode(portpath):
158157
port += 1
159-
portpath = '%s/%s' % (portdir, port)
158+
portpath = f'{portdir}/{port}'
160159

161160
self.make_znode(portpath, ephemeral=True)
162-
portmap = '%s/portmap/%s' % (self.session, self.whoami)
161+
portmap = f'{self.session}/portmap/{self.whoami}'
163162
if not self.exists_znode(portmap):
164163
self.make_znode(portmap, ephemeral=True, makepath=True)
165164
self.set_znode(portmap, str(port))
@@ -228,7 +227,7 @@ def run(self, attempts=3):
228227

229228
def add_to_queue(self):
230229
"""Add this destination to the destination queue """
231-
destid = '%d:%s' % (self.port, self.whoami)
230+
destid = f'{int(self.port)}:{self.whoami}'
232231
self.dest_queue.put(destid.encode())
233232
self.log.info('Added destination %s to queue with port %s', self.whoami, self.port)
234233

0 commit comments

Comments
 (0)