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()
def add_file(self, path): """Adds file to the list of files. The path will be normalized by using :func:`os.path.abspath`. :param path: A string that represents file path. :returns: A normalized string path. :raises: TypeError """ if typecheck.is_string(path): if not path_utils.exists(path): caller_frame = inspect.getouterframes(inspect.currentframe(), 2) filename = inspect.getsourcefile(caller_frame[2][0]) possible_dir = path_utils.dirname(filename) alternative_path = path_utils.join(possible_dir, path) if path_utils.exists(alternative_path): return self.add_file(alternative_path) path = path_utils.abspath(path) if not path_utils.exists(path): raise Exception("Path doesn't exist: %s" % path) if not path in self._files: self._files.append(path) return path elif typecheck.is_callable(path): result = path() if not result: return elif typecheck.is_list(result): self.add_files(result) else: self.add_file(result) elif not path: return None else: raise TypeError("Unknown path type '%s' of '%s'" % (type(path), path))