def searchupwards(start, files=[], dirs=[]):
 start = os.path.abspath(start)
 parents = start.split(os.sep)
 exists = os.path.exists
 join = os.sep.join
 isdir = os.path.isdir
 while len(parents):
  candidate = (join(parents) + os.sep)
  allpresent = 1
  for f in files:
   if (not exists(('%s%s' % (candidate, f)))):
    allpresent = 0
    break
  if allpresent:
   for d in dirs:
    if (not isdir(('%s%s' % (candidate, d)))):
     allpresent = 0
     break
  if allpresent:
   return candidate
  parents.pop((-1))
 return None

def searchupwards ( start , files = [ ] , dirs = [ ] ) : start = os . path . abspath ( start ) parents = start . split ( os . sep ) exists = os . path . exists join = os . sep . join isdir = os . path . isdir while len ( parents ) : candidate = ( join ( parents ) + os . sep ) allpresent = 1 for f in files : if ( not exists ( ( '%s%s' % ( candidate , f ) ) ) ) : allpresent = 0 break if allpresent : for d in dirs : if ( not isdir ( ( '%s%s' % ( candidate , d ) ) ) ) : allpresent = 0 break if allpresent : return candidate parents . pop ( ( - 1 ) ) return None
walk upwards from start .