def ls(name, dtype, tags): if dtype is None: dtype = "*" if name is None: name = "*" files = FreezableAPI.datasets(dtype=dtype, name=name) # Print message if nothing is here if len(files) == 0: # pragma: no cover print("[Nothing here yet]") return None # group by dtype and print datasets = defaultdict(list) for slug in files: dtype, name, tag = FreezableAPI.parse_slug(slug) datasets[dtype].append(name) # Print a formatted table for dtype, names in datasets.items(): print(f"{dtype}") for i, name in enumerate(names, 1): self = FreezableAPI(dtype, name) print(f" └──{self.name}") # Print tag data if tags: thawed_tag = None tags = [] for t in self.tag_data: if t["tag"] == "thawed": # TODO: add thawed info into ls thawed_tag = t assert thawed_tag else: tags.append(t) tags.sort(key=lambda x: x["timestamp"]) # print thawed info first for t in tags: timestamp = datetime.fromtimestamp( t["timestamp"]).strftime("%I:%M%p - %b %d, %Y") csum = t["total"][0:10] print(f" └──{t['tag']} {csum} ({timestamp})") sys.exit(0)
def test_get_fullpath_files(): FreezableAPI.datasets(fullpath=True)
def test_get_datasets(): FreezableAPI.datasets()