Skip to content

Commit

Permalink
SafePopen now resides in GRID_LRT
Browse files Browse the repository at this point in the history
  • Loading branch information
apmechev committed Oct 24, 2019
1 parent 39e3c1b commit 4ef4d61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions GRID_LRT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from subprocess import call, Popen, PIPE, STDOUT
if sys.version_info[0:2] != (2, 6):
from subprocess import check_output
from subprocess import Popen

class SafePopen(Popen):
def __init__(self, *args, **kwargs):
if sys.version_info.major == 3 :
kwargs['encoding'] = 'utf8'
return super(SafePopen, self).__init__(*args, **kwargs)


__all__ = ["storage", 'auth', "application", "Staging", 'token']
Expand Down
10 changes: 4 additions & 6 deletions GRID_LRT/auth/grid_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"""
import subprocess
from functools import wraps

from GRID_LRT import SafePopen

def check_uberftp():
"""Checks if the gfal-ls executable
exists on the system. Returns True if it exists
:returns: bool"""
process = subprocess.Popen(['which', 'gfal-ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf8')
process = SafePopen(['which', 'gfal-ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = process.communicate()
if output[0] == '' and output[1] == '':
return False
Expand All @@ -26,11 +25,10 @@ def grid_credentials_enabled():
This requires gfal-ls!"""
if not check_uberftp():
return False
process = subprocess.Popen([
process = SafePopen([
'gfal-ls', '-l',
'gsiftp://gridftp.grid.sara.nl:2811/pnfs/grid.sara.nl/data/lofar/user/sksp/diskonly'
], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf8')
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
res = process.communicate()
if type(res[1])==bytes:
error = res[1].decode('utf8')
Expand Down

0 comments on commit 4ef4d61

Please sign in to comment.