Skip to content

Commit 1e34090

Browse files
fstagniweb-flow
authored andcommitted
sweep: DIRACGrid#7977 fix: compatibility with py2 and py3
1 parent 379b7d1 commit 1e34090

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/DIRAC/Resources/Computing/PilotBundle.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,28 @@ def bundleProxy(executableFile, proxy):
2828
try:
2929
workingDirectory = tempfile.mkdtemp(suffix='_wrapper', prefix='TORQUE_')
3030
os.chdir(workingDirectory)
31-
open('proxy', "w").write(bz2.decompress(base64.b64decode("{compressedAndEncodedProxy}")))
32-
open('{executable}', "w").write(bz2.decompress(base64.b64decode("{compressedAndEncodedExecutable}")))
31+
32+
# Decode and decompress the proxy
33+
with open('proxy', "wb") as proxy_file:
34+
proxy_file.write(bz2.decompress(base64.b64decode("{compressedAndEncodedProxy}")))
35+
36+
# Decode and decompress the executable
37+
with open('{executable}', "wb") as executable_file:
38+
executable_file.write(bz2.decompress(base64.b64decode("{compressedAndEncodedExecutable}")))
39+
3340
os.chmod('proxy', stat.S_IRUSR | stat.S_IWUSR)
3441
os.chmod('{executable}', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
3542
os.environ["X509_USER_PROXY"] = os.path.join(workingDirectory, 'proxy')
3643
except Exception as x:
37-
print >> sys.stderr, x
44+
print("Error:", x, file=sys.stderr)
3845
sys.exit(-1)
46+
3947
cmd = "./{executable}"
40-
print 'Executing: ', cmd
48+
print('Executing:', cmd)
4149
sys.stdout.flush()
4250
os.system(cmd)
4351
4452
shutil.rmtree(workingDirectory)
45-
4653
""".format(
4754
compressedAndEncodedProxy=compressedAndEncodedProxy,
4855
compressedAndEncodedExecutable=compressedAndEncodedExecutable,

0 commit comments

Comments
 (0)