def get_mapping(config_path): if config_path: cfg = File(config_path) if cfg.exists(): with open(cfg.path, 'r') as f: cfg_dict = json.load(f) assert isinstance(cfg_dict, dict) return [FileSystem(k, v) for k, v in cfg_dict.items()] return [FileSystem('/', './')]
class FileBrowser: def __init__(self, device, path): self.f = File(path) self.device = device def changeDir(self, device, val): if val == "..": self.f = self.f.parent() else: for d in self.f.dirs: if d.basename == val: self.f = d break self.makeFileBrowser() def nothing(self, device, val): pass def makeFileBrowser(self): directoryList = [("..", self.changeDir)] directoryList.extend( [ (x.basename, self.changeDir) for x in self.f.dirs if not x.basename.startswith(".") ] ) directoryList.extend([(x.basename, self.nothing) for x in self.f.files]) fileMenu = Menu(self.f.path, directoryList) self.device.dispMenu(fileMenu)
def archive_and_set_wp(): F = File(root) pics = sorted(F.images, lambda x, y: cmp(x.ctime, y.ctime)) if len(pics) > 1: for x in pics[:-1]: print x x.move_to(os.path.join(root, to)) set_wallpaper(pics[-1].path)
def main(): prefixs = sys.argv[1] if len(sys.argv) >= 2 else '' result = find_path( File(os.path.expanduser(os.path.expandvars(os.getenv('ROOT', '.')))), prefixs, [], len(prefixs), 0, ) print_result(result)
def __init__(self, device, path): self.f = File(path) self.device = device
File Name : cleanpics.py Description : My downloaded picture archive tool. """ import os import shutil from filetree import File dirs = [ 'io', ] cwd = os.path.expanduser('~/Downloads') os.chdir(cwd) F = File(cwd) def twitter_large(F): for f in F.files: if f.basename.lower().endswith('-large'): print f.basename shutil.move(f.path, f.path[:-6]) def archive(path, prefix=None, suffix=None): archive_dir = os.path.abspath(path) if not os.path.isdir(archive_dir): os.makedirs(archive_dir) for f in F.files:
def file(self, url_path: str): if not url_path.startswith(self.url_root): return None return File(self.url2fs(url_path))