Gaudi Framework, version v25r1

Home   Generated: Mon Mar 24 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | List of all members
GaudiMP.FdsRegistry.FdsDict Class Reference
Inheritance diagram for GaudiMP.FdsRegistry.FdsDict:
Inheritance graph
[legend]
Collaboration diagram for GaudiMP.FdsRegistry.FdsDict:
Collaboration graph
[legend]

Public Member Functions

def __missing__
 
def fname
 
def fds
 
def has_name
 
def add
 
def iomode
 
def get_output_fds
 
def get_input_fds
 
def get_fds_in_dir
 
def create_symlinks
 
def extract_fds
 

Static Public Attributes

string name "fds_dict"
 
 curdir None
 

Detailed Description

Definition at line 10 of file FdsRegistry.py.

Member Function Documentation

def GaudiMP.FdsRegistry.FdsDict.__missing__ (   self,
  key 
)

Definition at line 14 of file FdsRegistry.py.

14 
15  def __missing__(self, key):
16  self[key] = ""
17  return ""
def GaudiMP.FdsRegistry.FdsDict.add (   self,
  i,
  fname,
  iomode,
  flags 
)

Definition at line 35 of file FdsRegistry.py.

35 
36  def add(self, i, fname, iomode, flags):
37  self[i] = (fname, iomode, flags)
38  return
def GaudiMP.FdsRegistry.FdsDict.create_symlinks (   self,
  wkdir = "" 
)
create necessary symlinks in worker's dir if the fd is <INPUT>
otherwise copy <OUTPUT> file 

Definition at line 60 of file FdsRegistry.py.

60 
61  def create_symlinks(self, wkdir=""):
62  """
63  create necessary symlinks in worker's dir if the fd is <INPUT>
64  otherwise copy <OUTPUT> file
65  """
66  import os,shutil
67  msg.info("create_symlinks: %s" % self.get_fds_in_dir())
68  #some files expected to be in curdir
69  for fd in self.get_fds_in_dir():
70  src = self[fd][0]
71  iomode = self[fd][1]
72  dst = os.path.join(wkdir, os.path.basename(src))
73  if iomode == "<INPUT>":
74  if os.path.exists(dst):
75  # update_io_registry took care of this
76  msg.debug("fds_dict.create_symlink:update_io_registry took care of src=%s" % src)
77  pass
78  else:
79  msg.debug("fds_dict.create_symlink:(symlink) src=%s, iomode=%s" % (src,iomode))
80  os.symlink(src, dst)
81  else:
82  msg.debug("fds_dict.create_symlink: (copy) src=%s, dst=%s" % (src, dst))
83  shutil.copy(src, dst)
84  pass
85  return
def GaudiMP.FdsRegistry.FdsDict.extract_fds (   self,
  dir = "" 
)
parse the fds of the processs -> build fds_dict

Definition at line 86 of file FdsRegistry.py.

86 
87  def extract_fds(self, dir=""):
88  """parse the fds of the processs -> build fds_dict
89  """
90  import os, fcntl
91  msg.info("extract_fds: making snapshot of parent process file descriptors")
92  self.curdir = os.path.abspath(os.curdir)
93  iomode = '<INPUT>'
94 
95  procfd = '/proc/self/fd'
96  fds = os.listdir(procfd)
97  for i in fds:
98  fd = int(i) # spurious entries should raise at this point
99  if (fd==1 or fd==2):
100  #leave stdout and stderr to redirect_log
101  continue
102  elif (fd==0):
103  #with only a single controlling terminal, leave stdin alone
104  continue
105 
106  try:
107  realname = os.path.realpath(os.path.join(procfd,i))
108  except (OSError, IOError, TypeError):
109  # can fail because the symlink resolution (why is that needed
110  # anyway?) may follow while a temp file disappears
111  msg.debug( "failed to resolve: %s ... skipping", os.path.join(procfd,i) )
112  continue
113 
114  if os.path.exists(realname):
115  try:
116  flags = fcntl.fcntl(fd, fcntl.F_GETFL)
117  if (flags & _O_ACCMODE) == 0: #read-only --> <INPUT>
118  iomode = "<INPUT>"
119  else:
120  iomode = "<OUTPUT>"
121 
122  self.add(fd, realname, iomode, flags)
123  except (OSError, IOError):
124  # likely saw a temoorary file; for now log a debug
125  # message, but this is fine if silently ignored
126  msg.debug( "failed access to: %s ... skipping", realname )
127  continue
128 
129  # at this point the list of fds may still include temp files
130  # TODO: figure out if they can be identified (seeing /tmp is
131  # not enough as folks like to run with data from /tmp b/c of
132  # space constraints on /afs
133 
134  msg.debug( "extract_fds.fds_dict=%s" % self)
135  return
def GaudiMP.FdsRegistry.FdsDict.fds (   self,
  fname 
)

Definition at line 25 of file FdsRegistry.py.

25 
26  def fds(self, fname):
27  return [i for i, v in self.iteritems() if v[0]==fname]
def GaudiMP.FdsRegistry.FdsDict.fname (   self,
  i 
)

Definition at line 18 of file FdsRegistry.py.

18 
19  def fname(self,i):
20  if i in self:
21  return self[i][0]
22  else:
23  msg.warning ("fds_dict:fname: No Key %s" % i)
24  return ""
def GaudiMP.FdsRegistry.FdsDict.get_fds_in_dir (   self,
  dir = "" 
)

Definition at line 52 of file FdsRegistry.py.

52 
53  def get_fds_in_dir(self, dir=""):
54  import os
55  if dir == "" and self.curdir is not None:
56  dir = self.curdir
57  msg.debug("get_fds_in_dir(%s)" % dir)
58  return [i for i in self.keys()
59  if os.path.samefile(os.path.dirname(self[i][0]), dir) ]
def GaudiMP.FdsRegistry.FdsDict.get_input_fds (   self)

Definition at line 49 of file FdsRegistry.py.

49 
50  def get_input_fds(self):
51  return [i for i in self.keys() if self[i][1]=='<INPUT>']
def GaudiMP.FdsRegistry.FdsDict.get_output_fds (   self)

Definition at line 46 of file FdsRegistry.py.

46 
47  def get_output_fds(self):
48  return [i for i in self.keys() if self[i][1]=='<OUTPUT>']
def GaudiMP.FdsRegistry.FdsDict.has_name (   self,
  fname 
)

Definition at line 28 of file FdsRegistry.py.

28 
29  def has_name(self, fname):
30  for v in self.values():
31  if (v[0] == fname):
32  return True
33  return False
def GaudiMP.FdsRegistry.FdsDict.iomode (   self,
  i 
)

Definition at line 39 of file FdsRegistry.py.

39 
40  def iomode(self,i):
41  if i in self:
42  return self[i][1]
43  else:
44  msg.warning ("fds_dict:iomode: No Key %s" % i)
45  return ""

Member Data Documentation

GaudiMP.FdsRegistry.FdsDict.curdir None
static

Definition at line 12 of file FdsRegistry.py.

string GaudiMP.FdsRegistry.FdsDict.name "fds_dict"
static

Definition at line 11 of file FdsRegistry.py.


The documentation for this class was generated from the following file:
Generated at Mon Mar 24 2014 18:27:53 for Gaudi Framework, version v25r1 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004