def _open_file(self, path): filename = Path(path) if filename.isdir(): print 'BUG: filename is a dir' return try: file_ = open(filename, "w") except IOError: newdir, fn = filename.splitpath() if not Path(newdir).isdir(): newdir.makedirs() file_ = open(filename, "w") return file_
def arrange_path(path, path_class=Path): """ Return a Path, FilePath or DirPath dependings on path nature. Path is used for special path like device "files" or path not existing on disk. If path is empty, returns None. If path do not exists on disk or is not file nor directory (like /dev/xyz on linux),it return a path_class. """ if not path: return None path = Path(str(path)) if path.isfile(): return FilePath(path) elif path.isdir(): return DirPath(path) else: return path_class(path)
def arrange_path(path, path_class=Path): u""" Return a Path, FilePath or DirPath dependings on path nature. Path is used for special path like device "files" or path not existing on disk. If path is empty, returns None. If path do not exists on disk or is not file nor directory (like /dev/xyz on linux),it return a path_class. """ if not path: return None path = Path(unicode(path)) if path.isfile(): return FilePath(path) elif path.isdir(): return DirPath(path) else: return path_class(path)
def search_path(): """ Return a list of all path containing projects """ repositories = set() # 1. Add default user project dir repositories.add(Path(settings.get_project_dir())) # 2. Add project repositories defined by packages for plugin in plugins( 'oalab.plugin', criteria=dict(implement="ProjectRepositoryList")): for repository in plugin(): repositories.add(repository) # 3. Read repositories defined by users and saved in config config = settings.Settings() lst = list(repositories) try: s = config.get("ProjectManager", "Path") lst = eval(s, {"path": Path}) except NoSectionError: config.add_section("ProjectManager") config.add_option("ProjectManager", "Path", str([str(path) for path in lst])) except NoOptionError: config.add_option("ProjectManager", "Path", str([str(path) for path in lst])) for repo in lst: repositories.add(repo) # Remove all paths to directories that don't exist final_list = set() for p in repositories: p = Path(p).abspath() if not p.isdir(): continue final_list.add(p) return list(final_list)
def search_path(): """ Return a list of all path containing projects """ repositories = set() # 1. Add default user project dir repositories.add(Path(settings.get_project_dir())) # 2. Add project repositories defined by packages for plugin in plugins('oalab.plugin', criteria=dict(implement="ProjectRepositoryList")): for repository in plugin(): repositories.add(repository) # 3. Read repositories defined by users and saved in config config = settings.Settings() lst = list(repositories) try: s = config.get("ProjectManager", "Path") lst = eval(s, {"path": Path}) except NoSectionError: config.add_section("ProjectManager") config.add_option("ProjectManager", "Path", str([str(path) for path in lst])) except NoOptionError: config.add_option("ProjectManager", "Path", str([str(path) for path in lst])) for repo in lst: repositories.add(repo) # Remove all paths to directories that don't exist final_list = set() for p in repositories: p = Path(p).abspath() if not p.isdir(): continue final_list.add(p) return list(final_list)