def gettree(lp: LocalPath): assert lp.check() if lp.isdir(): return {df.basename: gettree(df) for df in lp.listdir()} elif lp.isfile(): return lp.read_text("utf8") else: raise Exception("not directory or file: {}".format(lp))
def pgdir(self): """Retrieve the set playground directory""" for parent in search_parent_directories(): pgdir = Path(parent).join(self.pgconf['pgdir'], abs=1) if pgdir.check(dir=True): return pgdir raise NoPlayground("could not find any directory named '%s'" % self.pgconf['pgdir'])
def pgdir(self): """Retrieve the set playground directory""" for parent in search_parent_directories(): pgdir = Path(parent).join(self.pgconf['pgdir'], abs=1) if pgdir.check(dir=True): return pgdir raise NoPlayground( "could not find any directory named '%s'" % self.pgconf['pgdir'] )
def gettree(lp: LocalPath, max_len=120): """ Get a dict representing the file tree for a directory """ assert lp.check() if lp.isdir(): return {df.basename: gettree(df, max_len=max_len) for df in lp.listdir()} else: assert lp.isfile() content = lp.read_text('utf8') if max_len and len(content) > max_len: content = content[:max_len - 3] + '...' return content
def it_removes_down_file(): path = Path(os.getcwd()).join('playground/slow-startup/down') path.ensure() assert path.check() it_can_succeed() assert not path.check()