ATLAS Offline Software
Loading...
Searching...
No Matches
python.rfio Namespace Reference

Classes

class  RFIOError
class  StatResult

Functions

 _remove_prefix (filename, prefix)
 rfstat (filename)
 rfdir (dirname)
 rfstat_dict (filename)
 rfstat_item (filename, item)
 listdir (dirname)
 exists (filename)
 getsize (filename)
 getmtime (filename)
 _stat_time (time_string)
 lstat (filename)
 access (filename, mode)

Variables

str __doc__ = """Module with utilities for rfio files"""
 stat = lstat

Function Documentation

◆ _remove_prefix()

python.rfio._remove_prefix ( filename,
prefix )
protected

Definition at line 14 of file rfio.py.

14def _remove_prefix(filename,prefix):
15 if filename.startswith(prefix): filename = filename[len(prefix):]
16 return filename
17
18

◆ _stat_time()

python.rfio._stat_time ( time_string)
protected

Definition at line 141 of file rfio.py.

141def _stat_time(time_string):
142 t = time.mktime(time.strptime(time_string))
143 if os.stat_float_times():
144 return float(t)
145 else:
146 return int(t)
147
148
149

◆ access()

python.rfio.access ( filename,
mode )

Definition at line 186 of file rfio.py.

186def access(filename,mode):
187 if mode == os.F_OK: return exists(filename)
188
189 st = stat(filename)
190 filemode = st.st_mode
191 uid = st.st_uid
192 gid = st.st_gid
193 if mode & os.R_OK:
194 rOK = ( filemode & statconsts.S_IROTH ) or \
195 ( filemode & statconsts.S_IRGRP and os.getgid() == gid ) or \
196 ( filemode & statconsts.S_IRUSR and os.getuid() == uid ) or \
197 ( filemode & statconsts.S_ISGID and os.getegid() == gid ) or \
198 ( filemode & statconsts.S_ISUID and os.geteuid() == uid )
199 else:
200 rOK = True
201
202 if mode & os.W_OK:
203 wOK = ( filemode & statconsts.S_IWOTH ) or \
204 ( filemode & statconsts.S_IWGRP and os.getgid() == gid ) or \
205 ( filemode & statconsts.S_IWUSR and os.getuid() == uid ) or \
206 ( filemode & statconsts.S_ISGID and os.getegid() == gid ) or \
207 ( filemode & statconsts.S_ISUID and os.geteuid() == uid )
208 else:
209 wOK = True
210
211 if mode & os.X_OK:
212 xOK = ( filemode & statconsts.S_IXOTH ) or \
213 ( filemode & statconsts.S_IXGRP and os.getgid() == gid ) or \
214 ( filemode & statconsts.S_IXUSR and os.getuid() == uid ) or \
215 ( filemode & statconsts.S_ISGID and os.getegid() == gid ) or \
216 ( filemode & statconsts.S_ISUID and os.geteuid() == uid )
217 else:
218 xOK = True
219
220 return rOK and wOK and xOK
221
222
bool exists(const std::string &filename)
does a file exist

◆ exists()

python.rfio.exists ( filename)

Definition at line 90 of file rfio.py.

90def exists(filename):
91 status,output = rfstat(filename)
92 return status == 0
93
94

◆ getmtime()

python.rfio.getmtime ( filename)

Definition at line 100 of file rfio.py.

100def getmtime(filename):
101 return lstat(filename).st_mtime
102
103

◆ getsize()

python.rfio.getsize ( filename)
Return size of file <filename> in bytes

Definition at line 95 of file rfio.py.

95def getsize(filename):
96 """Return size of file <filename> in bytes"""
97 return int(rfstat_item(filename,'Size'))
98
99

◆ listdir()

python.rfio.listdir ( dirname)
Return the contents of directory <dirname> in a python list a-la os.listdir(),
i.e. only the filenames, and not including the current dir (.) and parent dir (..)

Definition at line 76 of file rfio.py.

76def listdir(dirname):
77 """Return the contents of directory <dirname> in a python list a-la os.listdir(),
78 i.e. only the filenames, and not including the current dir (.) and parent dir (..)"""
79 status,ls_la = rfdir(dirname)
80 if status: raise RFIOError('Directory %s not found' % dirname)
81 dir = [ ]
82 for d in ls_la:
83 dd = d.split()[-1]
84 if dd != os.curdir and dd != os.pardir:
85 dir.append( dd )
86
87 return dir
88
89

◆ lstat()

python.rfio.lstat ( filename)

Definition at line 150 of file rfio.py.

150def lstat(filename):
151 st = StatResult()
152 output = rfstat_dict(filename)
153 if output is None: raise RFIOError('file %s not found' % filename)
154 for name in output:
155 value = output[name]
156 if name == 'Device':
157 st.st_dev = eval('0x' + value)
158 elif name.startswith('Inode'):
159 st.st_ino = int(value)
160 elif name.find('blocks') != -1:
161 st.st_blocks = int(value)
162 elif name == 'Protection':
163 octal = value.split()[-1][1:-1]
164 st.st_mode = eval('0' + octal)
165 elif name == 'Hard Links':
166 st.st_nlink = int(value)
167 elif name == 'Uid':
168 st.st_uid = int(value.split()[0])
169 elif name == 'Gid':
170 st.st_gid = int(value.split()[0])
171 elif name.startswith('Size'):
172 st.st_size = int(value)
173 elif name == 'Last access':
174 st.st_atime = _stat_time(value)
175 elif name == 'Last modify':
176 st.st_mtime = _stat_time(value)
177 elif name == 'Last stat. mod.':
178 st.st_ctime = _stat_time(value)
179
180 return st
181
182# never follow symbolic links, so stat == lstat

◆ rfdir()

python.rfio.rfdir ( dirname)
Return tuple (status,output) of rfdir shell command. Output in a list of strings (one entry per line).
The format is the same as the unix shell command \'ls -la\'
Raises RFIOError if rfdir command is not found

Definition at line 33 of file rfio.py.

33def rfdir(dirname):
34 """Return tuple (status,output) of rfdir shell command. Output in a list of strings (one entry per line).
35 The format is the same as the unix shell command \'ls -la\'
36 Raises RFIOError if rfdir command is not found"""
37 dircmd = 'rfdir'
38 from PyJobTransformsCore import envutil
39 if not envutil.find_executable(dircmd):
40 raise RFIOError( '%s not found in PATH' % dircmd )
41 cmd = '%s %s' % (dircmd,_remove_prefix(dirname,'rfio:'))
42 status,ls_la = subprocess.getstatusoutput( cmd )
43 status >>= 8
44
45 return (status, ls_la.split(os.linesep))
46
47

◆ rfstat()

python.rfio.rfstat ( filename)
Return tuple (status,output) of rfstat shell command. Output is a list of strings
(one entry per line). Raises RFIOError if rfstat command is not found.

Definition at line 19 of file rfio.py.

19def rfstat(filename):
20 """Return tuple (status,output) of rfstat shell command. Output is a list of strings
21 (one entry per line). Raises RFIOError if rfstat command is not found."""
22 statcmd = 'rfstat'
23 from PyJobTransformsCore import envutil
24 if not envutil.find_executable(statcmd):
25 raise RFIOError( '%s not found in PATH' % statcmd )
26 cmd = '%s %s' % (statcmd,_remove_prefix(filename,'rfio:'))
27 status,output = subprocess.getstatusoutput( cmd )
28 status >>= 8
29
30 return (status, output.split(os.linesep))
31
32

◆ rfstat_dict()

python.rfio.rfstat_dict ( filename)
Return dictionary with name:value pairs of the rfstat output. Returns None
if rfstat returns an error code (i.e. file does not exist).

Definition at line 48 of file rfio.py.

48def rfstat_dict(filename):
49 """Return dictionary with name:value pairs of the rfstat output. Returns None
50 if rfstat returns an error code (i.e. file does not exist)."""
51 status,output = rfstat(filename)
52 if status: return None
53 rfdict = { }
54 for line in output:
55 colon = line.index(':')
56 name = line[:colon].strip()
57 value = line[colon+1:].strip()
58 rfdict[name] = value
59
60 return rfdict
61
62

◆ rfstat_item()

python.rfio.rfstat_item ( filename,
item )
Return the contents of <item> in the rfstat output

Definition at line 63 of file rfio.py.

63def rfstat_item(filename,item):
64 """Return the contents of <item> in the rfstat output"""
65 status,output = rfstat(filename)
66 if status: return None
67 for line in output:
68 if line.startswith( item ):
69 colon = line.index(':')
70 return line[colon+1:].strip()
71
72 # nothing found
73 return None
74
75

Variable Documentation

◆ __doc__

str python.rfio.__doc__ = """Module with utilities for rfio files"""
private

Definition at line 8 of file rfio.py.

◆ stat

python.rfio.stat = lstat

Definition at line 183 of file rfio.py.