def find_toplevel_job_dir(start_dir):
 job_dir = start_dir
 while (not os.path.exists(os.path.join(job_dir, '.autoserv_execute'))):
  if (job_dir == '/'):
   return None
  job_dir = os.path.dirname(job_dir)
 return job_dir

def find_toplevel_job_dir ( start_dir ) : job_dir = start_dir while ( not os . path . exists ( os . path . join ( job_dir , '.autoserv_execute' ) ) ) : if ( job_dir == '/' ) : return None job_dir = os . path . dirname ( job_dir ) return job_dir
starting from start_dir and moving upwards .