def cwd(pid):
 if stem.util.proc.is_available():
  try:
   return stem.util.proc.cwd(pid)
  except IOError:
   pass
 logging_prefix = ('cwd(%s):' % pid)
 if is_available('pwdx'):
  results = call((GET_CWD_PWDX % pid), None)
  if (not results):
   log.debug(("%s pwdx didn't return any results" % logging_prefix))
  elif results[0].endswith('No such process'):
   log.debug(('%s pwdx processes reported for this pid' % logging_prefix))
  elif ((len(results) != 1) or (results[0].count(' ') != 1) or (not results[0].startswith(('%s: ' % pid)))):
   log.debug(('%s we got unexpected output from pwdx: %s' % (logging_prefix, results)))
  else:
   return results[0].split(' ', 1)[1].strip()
 if is_available('lsof'):
  results = call((GET_CWD_LSOF % pid), [])
  if ((len(results) == 2) and results[1].startswith('n/')):
   lsof_result = results[1][1:].strip()
   if (' ' not in lsof_result):
    return lsof_result
  else:
   log.debug(('%s we got unexpected output from lsof: %s' % (logging_prefix, results)))
 return None

def cwd ( pid ) : if stem . util . proc . is_available ( ) : try : return stem . util . proc . cwd ( pid ) except IOError : pass logging_prefix = ( 'cwd(%s):' % pid ) if is_available ( 'pwdx' ) : results = call ( ( GET_CWD_PWDX % pid ) , None ) if ( not results ) : log . debug ( ( "%s pwdx didn't return any results" % logging_prefix ) ) elif results [ 0 ] . endswith ( 'No such process' ) : log . debug ( ( '%s pwdx processes reported for this pid' % logging_prefix ) ) elif ( ( len ( results ) != 1 ) or ( results [ 0 ] . count ( ' ' ) != 1 ) or ( not results [ 0 ] . startswith ( ( '%s: ' % pid ) ) ) ) : log . debug ( ( '%s we got unexpected output from pwdx: %s' % ( logging_prefix , results ) ) ) else : return results [ 0 ] . split ( ' ' , 1 ) [ 1 ] . strip ( ) if is_available ( 'lsof' ) : results = call ( ( GET_CWD_LSOF % pid ) , [ ] ) if ( ( len ( results ) == 2 ) and results [ 1 ] . startswith ( 'n/' ) ) : lsof_result = results [ 1 ] [ 1 : ] . strip ( ) if ( ' ' not in lsof_result ) : return lsof_result else : log . debug ( ( '%s we got unexpected output from lsof: %s' % ( logging_prefix , results ) ) ) return None
provides the current working directory for the given process .