Skip to content

Commit df8fa28

Browse files
Make locker-support work with python3
1 parent ba61c53 commit df8fa28

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

athdir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import absolute_import, division, print_function, unicode_literals
34
import athdir
45
import sys
56
import logging
@@ -64,7 +65,7 @@ if len(sys.argv) <= 3 and not any(x.startswith('-') for x in sys.argv):
6465
a = athdir.Athdir(sys.argv[1], sys.argv[2] if len(sys.argv) == 3 else 'bin')
6566
paths = a.get_paths()
6667
if len(paths) > 0:
67-
print ''.join(paths)
68+
print(''.join(paths))
6869
sys.exit(0 if len(paths) > 0 else 1)
6970

7071
(options, args) = parser.parse_args()
@@ -89,5 +90,5 @@ for p in options.lockerpath:
8990
options.forceDependent, options.forceIndependent,
9091
options.listAll)
9192
if len(paths) > 0:
92-
print options.recsep.join(paths)
93+
print(options.recsep.join(paths))
9394
sys.exit(0 if len(paths) > 0 else 1)

attach

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import absolute_import, division, print_function, unicode_literals
34
import sys
45
import subprocess
56
import logging
@@ -53,14 +54,12 @@ class Environment(dict):
5354
assert len(paths) < 2
5455
if subdir == 'bin' and options.warn:
5556
if len(paths) == 0:
56-
print >>sys.stderr, \
57-
"%s: warning: %s has no binary directory" % \
58-
(sys.argv[0], mountpoint)
57+
print("%s: warning: %s has no binary directory" % \
58+
(sys.argv[0], mountpoint), file=sys.stderr)
5959
else:
6060
if False in [adir.is_native(p) for p in paths]:
61-
print >>sys.stderr, \
62-
"%s: warning: using compatibility for %s" % \
63-
(sys.argv[0], mountpoint)
61+
print("%s: warning: using compatibility for %s" % \
62+
(sys.argv[0], mountpoint), file=sys.stderr)
6463
for p in paths:
6564
self[varmap[subdir]].remove(p)
6665
if options.front:
@@ -97,13 +96,13 @@ def attach_filesys(filesys, options):
9796
if options.lookup:
9897
try:
9998
results = locker.resolve(filesys)
100-
print "%s resolves to:" % (filesys)
99+
print("%s resolves to:" % (filesys))
101100
for r in results:
102-
print "%s %s%s" % \
101+
print("%s %s%s" % \
103102
(r['type'], r['data'],
104-
' ' + str(r['priority']) if r['priority'] > 0 else '')
103+
' ' + str(r['priority']) if r['priority'] > 0 else ''))
105104
except (locker.LockerNotFoundError, locker.LockerError) as e:
106-
print >>sys.stderr, e
105+
print(e, file=sys.stderr)
107106
else:
108107
# Multiple entries will only be returned for FSGROUPs
109108
# which we want to try in order. Once successful, we're done
@@ -114,29 +113,29 @@ def attach_filesys(filesys, options):
114113
try:
115114
filesystems = locker.lookup(filesys)
116115
except locker.LockerError as e:
117-
print >>sys.stderr, e
116+
print(e, file=sys.stderr)
118117
for entry in filesystems:
119118
logger.debug("Attempting to attach %s", entry)
120119
if (options.map or options.remap) and \
121120
(entry.authRequired or entry.authDesired):
122121
try:
123122
subprocess.check_call(entry.getAuthCommandline())
124123
except subprocess.CalledProcessError as e:
125-
print >>sys.stderr, "Error while authenticating:", e
124+
print("Error while authenticating:", e, file=sys.stderr)
126125
if entry.authRequired:
127126
return None
128127
if options.mountpoint is not None:
129128
entry.mountpoint = options.mountpoint
130129
try:
131130
entry.attach(force=options.force)
132131
except locker.LockerError as e:
133-
print >>sys.stderr, e
132+
print(e, file=sys.stderr)
134133
continue
135134
if options.printpath:
136-
print entry.mountpoint
135+
print(entry.mountpoint)
137136
elif options.verbose:
138-
print "%s: %s attached to %s for filesystem %s" % \
139-
(sys.argv[0], entry.path, entry.mountpoint, entry.name)
137+
print("%s: %s attached to %s for filesystem %s" % \
138+
(sys.argv[0], entry.path, entry.mountpoint, entry.name))
140139
return entry.mountpoint
141140
return None
142141

@@ -151,7 +150,7 @@ def deprecated_callback(option, opt_str, value, parser):
151150
"""
152151
An OptionParser callback for deprecated options
153152
"""
154-
print >>sys.stderr, "WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str)
153+
print("WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str), file=sys.stderr)
155154

156155
def attachopts_callback(option, opt_str, value, parser):
157156
# Consume all remaining values on the list
@@ -275,7 +274,7 @@ if (len(argv) > 0) and (argv[0] == "-Padd"):
275274
if options.printpath or len(lockers + paths) < 1:
276275
# See NOTES[5]
277276
pathsep=':' if options.bourne else ' '
278-
print >>sys.stderr, pathsep.join([shorten_path(p) for p in env['PATH']])
277+
print(pathsep.join([shorten_path(p) for p in env['PATH']]), file=sys.stderr)
279278
sys.exit(0)
280279
if options.remove:
281280
for p in paths:
@@ -285,7 +284,7 @@ if (len(argv) > 0) and (argv[0] == "-Padd"):
285284
if at is None:
286285
at = locker.read_attachtab()
287286
if filesys not in at:
288-
print >>sys.stderr, "%s: Not attached." % (filesys,)
287+
print("%s: Not attached." % (filesys,), file=sys.stderr)
289288
continue
290289
env.removeLocker(at[filesys].mountpoint)
291290
else:
@@ -298,14 +297,14 @@ if (len(argv) > 0) and (argv[0] == "-Padd"):
298297
env['PATH'].insert(0, p)
299298
else:
300299
env['PATH'].append(p)
301-
print env.toShell(options.bourne)
300+
print(env.toShell(options.bourne))
302301
else:
303302
(options, args) = attachParser.parse_args(argv)
304303
if options.debug:
305304
logging.basicConfig()
306305
logger.setLevel(logging.DEBUG)
307306
if len(args) < 1:
308-
print locker.read_attachtab()._legacyFormat()
307+
print(locker.read_attachtab()._legacyFormat())
309308
if not options.map:
310309
options.remap = False
311310
if options.explicit and not options.mountpoint:

detach

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import absolute_import, division, print_function, unicode_literals
34
import sys, os
45
import socket
56
import logging
@@ -22,8 +23,7 @@ def deprecated_callback(option, opt_str, value, parser):
2223
"""
2324
An OptionParser callback for deprecated options
2425
"""
25-
print >>sys.stderr, "WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str)
26-
26+
print("WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str), file=sys.stderr)
2727
parser = OptionParser(usage=usage, add_help_option=False)
2828
parser.set_defaults(zephyr=False, unmap=True, verbose=True,
2929
all_filesys=False, explicit=False, fstype=[])
@@ -111,19 +111,19 @@ if options.all_filesys or options.host:
111111
try:
112112
attachtab[l].detach()
113113
if options.verbose:
114-
print >>sys.stderr, "%s: %s detached" % (sys.argv[0], attachtab[l].name)
114+
print("%s: %s detached" % (sys.argv[0], attachtab[l].name), file=sys.stderr)
115115
except locker.LockerError as e:
116-
print >>sys.stderr, "%s: Unable to detach: %s" % (l, e)
116+
print("%s: Unable to detach: %s" % (l, e), file=sys.stderr)
117117
sys.exit(0)
118118

119119
for a in args:
120120
if a in attachtab:
121121
try:
122122
attachtab[a].detach()
123123
if options.verbose:
124-
print >>sys.stderr, "%s: %s detached" % (sys.argv[0], attachtab[a].name)
124+
print("%s: %s detached" % (sys.argv[0], attachtab[a].name), file=sys.stderr)
125125
except locker.LockerError as e:
126-
print >>sys.stderr, "%s: Unable to detach: %s" % (l, e)
126+
print("%s: Unable to detach: %s" % (l, e), file=sys.stderr)
127127
else:
128-
print >>sys.stderr, "%s: Not attached." % (a,)
128+
print("%s: Not attached." % (a,), file=sys.stderr)
129129
sys.exit(0)

fsid

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import absolute_import, division, print_function, unicode_literals
34
import sys, os
45
import logging
56
from optparse import OptionParser
@@ -13,28 +14,31 @@ def do_map(l, options):
1314
if not options.map:
1415
cmdline = l.getDeauthCommandline()
1516
if cmdline is None:
16-
print >>sys.stderr, "%s: %s: %smapping not supported" % (sys.argv[0],
17+
print("%s: %s: %smapping not supported" % (sys.argv[0],
1718
l.name,
18-
'' if options.map else 'un')
19+
'' if options.map else 'un'), file=sys.stderr)
1920
else:
2021
try:
2122
subprocess.check_call(cmdline)
2223
if options.verbose:
23-
print >>sys.stderr, "%s: %s mapped" % (sys.argv[0],
24-
l.name)
24+
print("%s: %s mapped" % (sys.argv[0],
25+
l.name), file=sys.stderr)
26+
2527
except subprocess.CalledProcessError as e:
26-
print >>sys.stderr, "%s: Unable to map %s" % (sys.argv[0],
27-
l.name)
28+
print("%s: Unable to map %s" % (sys.argv[0],
29+
l.name), file=sys.stderr)
30+
2831
except locker.LockerError as e:
29-
print >>sys.stderr, "%s: %s: %s" % (sys.argv[0],
32+
print("%s: %s: %s" % (sys.argv[0],
3033
l.name,
31-
e)
34+
e), file=sys.stderr)
35+
3236

3337
def deprecated_callback(option, opt_str, value, parser):
3438
"""
3539
An OptionParser callback for deprecated options
3640
"""
37-
print >>sys.stderr, "WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str)
41+
print("WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str), file=sys.stderr)
3842

3943
usage = """%prog [options] [-f] filesystem ...
4044
%prog [options] -c cell ...
@@ -111,6 +115,6 @@ for f in options.filesystems + args:
111115
if f in attachtab:
112116
do_map(attachtab[f], options)
113117
else:
114-
print >>sys.stderr, "%s: %s not attached" % (sys.argv[0], f)
118+
print("%s: %s not attached" % (sys.argv[0], f), file=sys.stderr)
115119

116120
sys.exit(0)

quota.debathena

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
from __future__ import absolute_import, division, print_function, unicode_literals
34
import sys
45
import locker
56
import os
@@ -15,7 +16,7 @@ def deprecated_callback(option, opt_str, value, parser):
1516
"""
1617
An OptionParser callback for deprecated options
1718
"""
18-
print >>sys.stderr, "WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str)
19+
print("WARNING: '%s' is obsolete and will be removed in future versions." % (opt_str), file=sys.stderr)
1920

2021
parser = OptionParser(usage=usage)
2122
parser.set_defaults(verbose=False, all_filesys=False, parsable=False,
@@ -72,8 +73,8 @@ for x in set(options.filesys):
7273
continue
7374
if x not in at:
7475
# See NOTES[6]
75-
print >>sys.stderr, "%s: Not attached." % (x,)
76-
print >>sys.stderr, "%s: Unknown filesystem %s." % (sys.argv[0], x)
76+
print("%s: Not attached." % (x,), file=sys.stderr)
77+
print("%s: Unknown filesystem %s." % (sys.argv[0], x), file=sys.stderr)
7778
sys.exit(1)
7879
filesystems.append(at[x].mountpoint)
7980

@@ -118,23 +119,23 @@ for l in at:
118119

119120
if options.verbose:
120121
if options.parsable:
121-
print "\n".join(output['parsable'])
122+
print("\n".join(output['parsable']))
122123
sys.exit(0)
123124
uid = os.getuid()
124125
try:
125126
username = pwd.getpwuid(uid).pw_name
126127
except Exception as e:
127128
logger.debug("Exception while getting username: %s", e)
128129
username = "unknown user"
129-
print "Disk quotas for %s (uid %d)" % (username, uid)
130-
print "%-16s %8s %8s %8s %8s %8s %8s" % ("Filesystem",
130+
print("Disk quotas for %s (uid %d)" % (username, uid))
131+
print("%-16s %8s %8s %8s %8s %8s %8s" % ("Filesystem",
131132
"usage", "quota",
132133
"limit", "files",
133-
"quota", "limit")
134-
print "\n".join(output['quotas'])
134+
"quota", "limit"))
135+
print("\n".join(output['quotas']))
135136
# We always print a blank line.
136-
print ''
137+
print('')
137138
if len(output['overage']) > 0:
138-
print "\n".join(output['overage'])
139+
print("\n".join(output['overage']))
139140

140141
sys.exit(0)

0 commit comments

Comments
 (0)