master: allow remote listing of directories

This commit is contained in:
Sebastien Bourdeauducq 2015-12-08 19:24:04 +08:00
parent ed08352f67
commit 7b2580583a
2 changed files with 20 additions and 2 deletions

View File

@ -96,6 +96,10 @@ def get_argparser():
help="use a specific repository revision " help="use a specific repository revision "
"(defaults to head)") "(defaults to head)")
parser_ls = subparsers.add_parser(
"ls", help="list a directory on the master")
parser_ls.add_argument("directory")
return parser return parser
@ -154,6 +158,15 @@ def _action_scan_repository(remote, args):
remote.scan_repository(args.revision) remote.scan_repository(args.revision)
def _action_ls(remote, args):
contents = remote.list_directory(args.directory)
for name, is_dir in sorted(contents, key=lambda x: (-x[1], x[0])):
if is_dir:
print("<DIR> " + name)
else:
print(" " + name)
def _show_schedule(schedule): def _show_schedule(schedule):
clear_screen() clear_screen()
if schedule: if schedule:
@ -285,7 +298,8 @@ def main():
"set_dataset": "master_dataset_db", "set_dataset": "master_dataset_db",
"del_dataset": "master_dataset_db", "del_dataset": "master_dataset_db",
"scan_devices": "master_device_db", "scan_devices": "master_device_db",
"scan_repository": "master_experiment_db" "scan_repository": "master_experiment_db",
"ls": "master_experiment_db"
}[action] }[action]
remote = Client(args.server, port, target_name) remote = Client(args.server, port, target_name)
try: try:

View File

@ -109,7 +109,8 @@ class ExperimentDB:
self._scanning = False self._scanning = False
def scan_repository_async(self, new_cur_rev=None): def scan_repository_async(self, new_cur_rev=None):
asyncio.ensure_future(exc_to_warning(self.scan_repository(new_cur_rev))) asyncio.ensure_future(
exc_to_warning(self.scan_repository(new_cur_rev)))
async def examine(self, filename, use_repository=True): async def examine(self, filename, use_repository=True):
if use_repository: if use_repository:
@ -128,6 +129,9 @@ class ExperimentDB:
self.repo_backend.release_rev(revision) self.repo_backend.release_rev(revision)
return description return description
def list_directory(self, directory):
return [(de.name, de.is_dir()) for de in os.scandir(directory)]
class FilesystemBackend: class FilesystemBackend:
def __init__(self, root): def __init__(self, root):