Skip to content

Commit 4107361

Browse files
python3
1 parent 4eb3ed8 commit 4107361

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

getcluster

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# A rewrite of getcluster(1) in Python
44
#
5-
5+
from __future__ import print_function, absolute_import
66
FALLBACKFILE = "/etc/cluster.fallback"
77
LOCALFILE = "/etc/cluster.local"
88
CLUSTERFILE = "/etc/cluster"
@@ -27,10 +27,10 @@ debugMode = os.getenv('DEBUG_GETCLUSTER', 'no') == 'yes'
2727

2828
def debug(msg, *args):
2929
if debugMode:
30-
print >>sys.stderr, "D:", msg % (args)
30+
print("D:", msg % (args), file=sys.stderr)
3131

3232
def perror(msg, *args):
33-
print >>sys.stderr, ("%s: " + msg) % ((sys.argv[0],) + args)
33+
print(("%s: " + msg) % ((sys.argv[0],) + args), file=sys.stderr)
3434

3535
def merge(list1, list2):
3636
rv = [] + list1
@@ -40,23 +40,34 @@ def merge(list1, list2):
4040
return rv
4141

4242
def cleanup(l):
43-
return filter(lambda x: cluster_re.match(x), map(lambda x: x.rstrip(), l))
43+
return [x for x in [x.rstrip() for x in l] if cluster_re.match(x)]
44+
45+
def cmp(x, y):
46+
"""
47+
Replacement for built-in function cmp that was removed in Python 3
48+
49+
Compare the two objects x and y and return an integer according to
50+
the outcome. The return value is negative if x < y, zero if x == y
51+
and strictly positive if x > y.
52+
"""
53+
54+
return (x > y) - (x < y)
4455

4556
def vercmp(v1, v2):
46-
v1l = map(int, map(lambda x: 0 if x is None else x, version_re.search(v1).groups()))
47-
v2l = map(int, map(lambda x: 0 if x is None else x, version_re.search(v2).groups()))
57+
v1l = list(map(int, [0 if x is None else x for x in version_re.search(v1).groups()]))
58+
v2l = list(map(int, [0 if x is None else x for x in version_re.search(v2).groups()]))
4859
return cmp(v1l, v2l)
4960

5061

5162
def output_var(var, val, bourne=False, plaintext=False):
5263
val = val.replace("'", "'\\''")
5364
var = var.upper()
5465
if bourne:
55-
print "%s='%s' ; export %s" % (var, val, var)
66+
print("%s='%s' ; export %s" % (var, val, var))
5667
elif plaintext:
57-
print "%s %s" % (var, val)
68+
print("%s %s" % (var, val))
5869
else:
59-
print "setenv %s '%s' ;" % (var, val)
70+
print("setenv %s '%s' ;" % (var, val))
6071

6172
def main():
6273
parser = OptionParser(usage='%prog [options] version', add_help_option=False)
@@ -141,7 +152,7 @@ def main():
141152
perror("No cluster information available for %s", options.hostname)
142153
# Sort everything into a hash, with varnames as keys and lists of lists as values
143154
cdata = {}
144-
for i in map(lambda x: x.split(' '), merge(merge(local, data), fallback)):
155+
for i in [x.split(' ') for x in merge(merge(local, data), fallback)]:
145156
var = i.pop(0)
146157
if var not in cdata:
147158
cdata[var] = []

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from distutils.core import setup
44

55
setup(name='getcluster',
6-
version='10.2.2',
6+
version='10.3',
77
author='Debathena Project',
88
author_email='[email protected]',
99
scripts=['getcluster'],

0 commit comments

Comments
 (0)