Commit 7a623727 authored by Andrea Manzi's avatar Andrea Manzi

DMC-1105: adapt syntax to python3

parent 0cdaacbd
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : bring online a file with gfal 2.0
......@@ -9,7 +9,7 @@ import sys
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: %s [surl]" % sys.argv[0]
print("Usage: %s [surl]" % sys.argv[0])
sys.exit(1)
surl = sys.argv[1]
......@@ -18,23 +18,23 @@ if __name__ == '__main__':
try:
# bring_online(surl, pintime, timeout, async)
(status, token) = ctx.bring_online(surl, 60, 60, False)
print "Got token %s" % token
print("Got token %s" % token)
while status == 0:
status = ctx.bring_online_poll(surl, token)
print "File brought online!"
except gfal2.GError, e:
print "Could not bring the file online:"
print "\t", e.message
print "\t Code", e.code
print("File brought online!")
except gfal2.GError as e:
print("Could not bring the file online:")
print("\t", e.message)
print("\t Code", e.code)
sys.exit(2)
try:
ctx.release(surl, token)
print "File released!"
except gfal2.GError, e:
print "Could not release the file:"
print "\t", e.message
print "\t Code", e.code
print("File released!")
except gfal2.GError as e:
print("Could not release the file:")
print("\t", e.message)
print("\t Code", e.code)
sys.exit(3)
sys.exit(0)
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : bring online a set of files with gfal2
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : copy a set of files in one go
......@@ -9,11 +9,11 @@ import shlex
import sys
def event_callback(event):
print "[%s] %s %s %s" % (event.timestamp, event.domain, event.stage, event.description)
print("[%s] %s %s %s" % (event.timestamp, event.domain, event.stage, event.description))
def monitor_callback(src, dst, average, instant, transferred, elapsed):
print "[%4d] %.2fMB (%.2fKB/s)\r" % (elapsed, transferred / 1048576, average / 1024),
print("[%4d] %.2fMB (%.2fKB/s)\r" % (elapsed, transferred / 1048576, average / 1024)),
sys.stdout.flush()
......@@ -38,7 +38,7 @@ if __name__ == '__main__':
sources.append(l[0])
destinations.append(l[1])
print "Found %d pairs" % len(sources)
print("Found %d pairs" % len(sources))
# Instantiate gfal2
ctx = gfal2.creat_context()
......@@ -50,11 +50,11 @@ if __name__ == '__main__':
if options.overwrite:
params.overwrite = True
print "Enabled overwrite"
print("Enabled overwrite")
if options.validate:
params.checksum_check = True
print "Enabled checksum check"
print("Enabled checksum check")
# Copy!
# In this case, an exception will be thrown if the whole process fails
......@@ -63,17 +63,17 @@ if __name__ == '__main__':
try:
errors = ctx.filecopy(params, sources, destinations)
if not errors:
print "Copy succeeded!"
print("Copy succeeded!")
else:
for i in range(len(errors)):
e = errors[i]
src = sources[i]
dst = destinations[i]
if e:
print "%s => %s failed [%d] %s" % (src, dst, e.code, e.message)
print("%s => %s failed [%d] %s" % (src, dst, e.code, e.message))
else:
print "%s => %s succeeded!" % (src, dst)
except Exception, e:
print "Copy failed: %s" % str(e)
print("%s => %s succeeded!" % (src, dst))
except Exception as e:
print("Copy failed: %s" % str(e))
sys.exit(1)
......@@ -7,10 +7,10 @@ import sys
def event_callback(event):
#print event
print "[%s] %s %s %s" % (event.timestamp, event.domain, event.stage, event.description)
print("[%s] %s %s %s" % (event.timestamp, event.domain, event.stage, event.description))
def monitor_callback(src, dst, average, instant, transferred, elapsed):
print "[%4d] %.2fMB (%.2fKB/s)\r" % (elapsed, transferred / 1048576, average / 1024),
print("[%4d] %.2fMB (%.2fKB/s)\r" % (elapsed, transferred / 1048576, average / 1024)),
sys.stdout.flush()
if __name__ == '__main__':
......@@ -27,9 +27,9 @@ if __name__ == '__main__':
help = 'Checksum (i.e. ADLER32:1234)')
parser.add_option('-o', '--overwrite', dest = 'overwrite', action = 'store_true',
help = 'Overwrite destination')
parser.add_option('--source_cred', dest = 'source_cred', help = 'Credentials for the source storage')
parser.add_option('--source_cred', dest = 'source_cred', help = 'Credentials for the source storage')
parser.add_option('--dest_cred', dest = 'dest_cred', help = 'Credentials for the destination storage')
parser.add_option('--dest_cred', dest = 'dest_cred', help = 'Credentials for the destination storage')
(options, args) = parser.parse_args()
if len(args) != 2:
......@@ -38,12 +38,12 @@ if __name__ == '__main__':
source = args[0]
dest = args[1]
print "Source: %s" % source
print "Destination: %s" % dest
print("Source: %s" % source)
print("Destination: %s" % dest)
# Instantiate gfal2
ctx = gfal2.creat_context()
gfal2.set_verbose(gfal2.verbose_level.debug)
gfal2.set_verbose(gfal2.verbose_level.debug)
# Set transfer parameters
params = ctx.transfer_parameters()
params.event_callback = event_callback
......@@ -51,32 +51,32 @@ if __name__ == '__main__':
if options.overwrite:
params.overwrite = True
print "Enabled overwrite"
print("Enabled overwrite")
if options.validate or options.checksum:
params.checksum_check = True
print "Enabled checksum check"
print("Enabled checksum check")
if options.checksum:
(alg, val) = options.checksum.split(':')
params.set_user_defined_checksum(alg, val)
print "User defined checksum: %s:%s" % params.get_user_defined_checksum()
print("User defined checksum: %s:%s" % params.get_user_defined_checksum())
if options.source_space_token:
params.src_spacetoken = options.source_space_token
print "Source space token: %s" % params.src_spacetoken
print("Source space token: %s" % params.src_spacetoken)
if options.dest_space_token:
params.dst_spacetoken = options.dest_space_token
print "Destination space token: %s" % params.dst_spacetoken
print("Destination space token: %s" % params.dst_spacetoken)
if options.source_cred:
if options.source_cred:
s_cred = gfal2.cred_new("X509_CERT",options.source_cred)
gfal2.cred_set(ctx,source,s_cred)
print "Source credentials: %s" % options.source_cred
if options.dest_cred:
gfal2.cred_set(ctx,source,s_cred)
print("Source credentials: %s" % options.source_cred)
if options.dest_cred:
d_cred = gfal2.cred_new("X509_CERT",options.dest_cred)
gfal2.cred_set(ctx,dest,d_cred)
print "Destination credentials: %s" % options.dest_cred
print("Destination credentials: %s" % options.dest_cred)
# Five minutes timeout
params.timeout = 300
......@@ -86,8 +86,8 @@ if __name__ == '__main__':
# (i.e. source can be file:/// and destination gsiftp://)
try:
r = ctx.filecopy(params, source, dest)
print "Copy succeeded!"
except Exception, e:
print "Copy failed: %s" % str(e)
print("Copy succeeded!")
except Exception as e:
print("Copy failed: %s" % str(e))
sys.exit(1)
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : get list of turls/replicas with gfal 2.0
......@@ -9,19 +9,19 @@ import sys
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: %s [surl]" % sys.argv[0]
print("Usage: %s [surl]" % sys.argv[0])
sys.exit(1)
surl = sys.argv[1]
ctx = gfal2.creat_context()
try:
replicas = ctx.getxattr(surl, 'user.replicas')
print replicas
except gfal2.GError, e:
print "Could not get the replicas:"
print "\t", e.message
print "\t Code", e.code
replicas = ctx.getxattr(surl, 'user.replicas')
print(replicas)
except gfal2.GError as e:
print("Could not get the replicas:")
print("\t", e.message)
print("\t Code", e.code)
sys.exit(2)
sys.exit(0)
......
#!/usr/bin/python
#!/usr/bin/env python
import sys
import gfal2
......
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : list the content of a directory with gfal 2.0
......@@ -13,14 +13,14 @@ import gfal2
if __name__ == '__main__':
# comment for usage
if(len(sys.argv) < 2):
print "\nUsage\t %s [gfal_folder] \n"%(sys.argv[0])
print " Example: %s lfn:/grid/dteam/ "%(sys.argv[0])
print " %s srm://myserver.com/myhome/ \n"%(sys.argv[0])
print("\nUsage\t %s [gfal_folder] \n"%(sys.argv[0]))
print(" Example: %s lfn:/grid/dteam/ "%(sys.argv[0]))
print(" %s srm://myserver.com/myhome/ \n"%(sys.argv[0]))
os._exit(1)
ctx = gfal2.creat_context()
my_dir = ctx.listdir(sys.argv[1])
for d in my_dir:
print d
print(d)
# no closedir needed, done automatically
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
# Example : open/read/close a file with gfal 2.0
......@@ -13,9 +13,9 @@ from string import printable
if __name__ == '__main__':
# comment for usage
if(len(sys.argv) < 2):
print "\nUsage\t %s [gfal_url] \n"%(sys.argv[0])
print " Example: %s lfn:/grid/dteam/myfile "%(sys.argv[0])
print " %s srm://myserver.com/myhome/myfile \n"%(sys.argv[0])
print("\nUsage\t %s [gfal_url] \n"%(sys.argv[0]))
print(" Example: %s lfn:/grid/dteam/myfile "%(sys.argv[0]))
print(" %s srm://myserver.com/myhome/myfile \n"%(sys.argv[0]))
os._exit(1)
ctx = gfal2.creat_context()
......@@ -26,11 +26,11 @@ if __name__ == '__main__':
# Hex dump
str = []
for byte in content:
print "%2X " % ord(byte),
print("%2X " % ord(byte)),
if byte in printable:
str.append(byte)
else:
str.append('.')
print '\t', ' '.join(str)
print('\t', ' '.join(str))
# no close needed, done automatically with the destruction of the file handle
......@@ -54,7 +54,7 @@ class Crawler:
entries = [f for f in self.context.listdir(url)
if f != '.' and f != '..']
except gfal2.GError:
print >>out, tabbing, '!'
out.write(tabbing, '!')
return
for f in entries:
......@@ -68,9 +68,9 @@ class Crawler:
# Print entry
if self.long:
print >>out, tabbing, self._long_format(f, fstat)
out.write(tabbing, self._long_format(f, fstat))
else:
print >>out, tabbing, self._short_format(f)
out.write(tabbing, self._short_format(f))
# Descend
if self.recursive and stat.S_ISDIR(fstat.st_mode):
......
#!/usr/bin/python
#!/usr/bin/env python
import sys
import gfal2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment