| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

Public Member Functions | Static Public Attributes

# GaudiMP::FdsRegistry::FdsDict Class Reference

Collaboration diagram for GaudiMP::FdsRegistry::FdsDict:
[legend]

List of all members.

## 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.

    00015                               :
    00016         self[key] = ""
    00017         return ""

def GaudiMP::FdsRegistry::FdsDict::add | ( |  | self,
|  |  | i,
|  |  | fname,
|  |  | iomode,
|  |  | flags
| ) |  |

Definition at line 35 of file FdsRegistry.py.

    00036                                           :
    00037         self[i] = (fname, iomode, flags)
    00038         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.

    00061                                        :
    00062         """
    00063         create necessary symlinks in worker's dir if the fd is <INPUT>
    00064         otherwise copy <OUTPUT> file
    00065         """
    00066         import os,shutil
    00067         msg.info("create_symlinks: %s" % self.get_fds_in_dir())
    00068         #some files expected to be in curdir
    00069         for fd in self.get_fds_in_dir():
    00070             src = self[fd][0]
    00071             iomode = self[fd][1]
    00072             dst = os.path.join(wkdir, os.path.basename(src))
    00073             if iomode == "<INPUT>":
    00074                 if os.path.exists(dst):
    00075                     # update_io_registry took care of this
    00076                     msg.debug("fds_dict.create_symlink:update_io_registry took care of src=%s" % src)
    00077                     pass
    00078                 else:
    00079                     msg.debug("fds_dict.create_symlink:(symlink) src=%s, iomode=%s" % (src,iomode))
    00080                     os.symlink(src, dst)
    00081             else:
    00082                 msg.debug("fds_dict.create_symlink: (copy) src=%s, dst=%s" % (src, dst))
    00083                 shutil.copy(src, dst)
    00084                 pass
    00085         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.

    00087                                  :
    00088         """parse the fds of the processs -> build fds_dict
    00089         """
    00090         import os, fcntl
    00091         msg.info("extract_fds: making snapshot of parent process file descriptors")
    00092         self.curdir = os.path.abspath(os.curdir)
    00093         iomode = '<INPUT>'
    00094
    00095         procfd = '/proc/self/fd'
    00096         fds = os.listdir(procfd)
    00097         for i in fds:
    00098             fd = int(i)       # spurious entries should raise at this point
    00099             if (fd==1 or fd==2):
    00100                 #leave stdout and stderr to redirect_log
    00101                 continue
    00102             elif (fd==0):
    00103                 #with only a single controlling terminal, leave stdin alone
    00104                 continue
    00105
    00106             try:
    00107                 realname = os.path.realpath(os.path.join(procfd,i))
    00108             except (OSError, IOError, TypeError):
    00109                 # can fail because the symlink resolution (why is that needed
    00110                 # anyway?) may follow while a temp file disappears
    00111                 msg.debug( "failed to resolve: %s ... skipping", os.path.join(procfd,i) )
    00112                 continue
    00113
    00114             if os.path.exists(realname):
    00115                 try:
    00116                     flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    00117                     if (flags & _O_ACCMODE) == 0: #read-only --> <INPUT>
    00118                         iomode = "<INPUT>"
    00119                     else:
    00120                         iomode = "<OUTPUT>"
    00121
    00122                     self.add(fd, realname, iomode, flags)
    00123                 except (OSError, IOError):
    00124                     # likely saw a temoorary file; for now log a debug
    00125                     # message, but this is fine if silently ignored
    00126                     msg.debug( "failed access to: %s ... skipping", realname )
    00127                     continue
    00128
    00129                 # at this point the list of fds may still include temp files
    00130                 # TODO: figure out if they can be identified (seeing /tmp is
    00131                 # not enough as folks like to run with data from /tmp b/c of
    00132                 # space constraints on /afs
    00133
    00134         msg.debug( "extract_fds.fds_dict=%s" % self)
    00135         return

def GaudiMP::FdsRegistry::FdsDict::fds | ( |  | self,
|  |  | fname
| ) |  |

Definition at line 25 of file FdsRegistry.py.

    00026                         :
    00027         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.

    00019                      :
    00020         if i in self:
    00021             return self[i][0]
    00022         else:
    00023             msg.warning ("fds_dict:fname: No Key %s" % i)
    00024             return ""

def GaudiMP::FdsRegistry::FdsDict::get_fds_in_dir | ( |  | self,
|  |  | dir = `""`
| ) |  |

Definition at line 52 of file FdsRegistry.py.

    00053                                     :
    00054         import os
    00055         if dir == "" and self.curdir is not None:
    00056             dir = self.curdir
    00057         msg.debug("get_fds_in_dir(%s)" % dir)
    00058         return [i for i in self.keys()
    00059                 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.

    00050                            :
    00051         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.

    00047                             :
    00048         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.

    00029                              :
    00030         for v in self.values():
    00031             if (v[0] == fname):
    00032                 return True
    00033         return False

def GaudiMP::FdsRegistry::FdsDict::iomode | ( |  | self,
|  |  | i
| ) |  |

Definition at line 39 of file FdsRegistry.py.

    00040                       :
    00041         if i in self:
    00042             return self[i][1]
    00043         else:
    00044             msg.warning ("fds_dict:iomode: No Key %s" % i)
    00045             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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/GaudiMP/python/GaudiMP/FdsRegistry.py

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines