From d302d46701ae43a46db57cfe2731183884fe3eb0 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Mon, 23 Sep 2024 12:00:47 -0700 Subject: [PATCH] feat: Adds e4edm ls --- e4e_data_management/cli.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/e4e_data_management/cli.py b/e4e_data_management/cli.py index c14b805..a2d9b6e 100644 --- a/e4e_data_management/cli.py +++ b/e4e_data_management/cli.py @@ -50,7 +50,8 @@ def __init__(self): 'push', 'zip', 'unzip', - 'prune' + 'prune', + 'ls', ] self.parameters = [ Parameter( @@ -85,6 +86,7 @@ def __init__(self): self.__configure_prune_parser(parsers['prune']) self.__configure_config_parser(parsers['config']) self.__configure_activate_parser(parsers['activate']) + self.__configure_ls_parser(parsers['ls']) # self.__configure_validate_parser(parsers['validate']) # self.__configure_zip_parser(parsers['zip']) # self.__configure_unzip_parser(parsers['unzip']) @@ -219,6 +221,18 @@ def status_cmd(self): """ print(self.app.status()) + def ls_dir(self, path: Path): + local_tz = dt.datetime.now().astimezone().tzinfo + print(path.as_posix()) + dirs = sorted([node for node in path.glob('*') if node.is_dir()]) + files = sorted([node for node in path.glob('*') if node.is_file()]) + dir_times = [dt.datetime.fromtimestamp(node.stat().st_mtime, local_tz) for node in dirs] + file_times = [dt.datetime.fromtimestamp(node.stat().st_mtime, local_tz) for node in files] + for idx, dir in enumerate(dirs): + print(f'{dir_times[idx].isoformat()} {dir.name}') + for idx, file in enumerate(files): + print(f'{file_times[idx].isoformat()} {file.name}') + def main(self): """Main function """ @@ -231,6 +245,10 @@ def main(self): arg_fn(**arg_dict) + def __configure_ls_parser(self, parser: argparse.ArgumentParser): + parser.add_argument('path', type=Path, default=Path('.')) + parser.set_defaults(func=self.ls_dir) + def __configure_config_parser(self, parser: argparse.ArgumentParser): parser.add_argument('parameter', type=str,