Esempio n. 1
0
 def identify_home_dir(cls):
   for record in inspect.stack():
     (frame, filename, lineno, code_ctx, _, index) = record
     path = path_utils.dirname(path_utils.abspath(filename))
     home_dir = cls.find_home_dir(path)
     if home_dir:
       return home_dir
   return cls.find_home_dir(path_utils.realpath(os.curdir)) or os.getcwd()
Esempio n. 2
0
  def find_home_dir(cls, path):
    """Finds top directory of an application by a given path and returns home
    path. Returns `None` if home direcotry cannot be identified.

    :param path: Path to directory.

    :returns: Path as string or `None`.
    """
    if not typecheck.is_string(path):
      raise TypeError("'path' must be a string")
    elif not len(path):
      raise TypeError("'path' is empty")
    path = path_utils.realpath(path)
    if path_utils.isfile(path):
      (path, _) = path_utils.split(path)
    while path is not os.sep:
      if os.path.exists(path) and os.path.isdir(path):
        if cls.is_home_dir(path):
          return path
      (path, _) = path_utils.split(path)
    return None