From 03e2db83cd1234e55ca2b4801f31e3094e3516b8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 17:01:22 +0200 Subject: [PATCH] implement list of objects Signed-off-by: Nico Schottelius --- bin/cdist | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bin/cdist b/bin/cdist index d7e2f697..8655dcad 100755 --- a/bin/cdist +++ b/bin/cdist @@ -160,6 +160,44 @@ class Cdist: """Return list of available explorers""" return os.listdir(GLOBAL_EXPLORER_DIR) + def list_object_paths(self, starting_point = False): + """Return list of paths of existing objects""" + object_paths = [] + + if not starting_point: + starting_point = self.object_dir + + for content in os.listdir(starting_point): + full_path = os.path.join(starting_point, content) + print(full_path) + if os.path.isdir(full_path): + log.debug("Recursing for %s", full_path) + object_paths.extend(self.list_object_paths(starting_point = full_path)) + + # Directory contains .cdist -> is an object + if content == ".cdist": + log.debug("Adding Object Path %s", starting_point) + object_paths.append(starting_point) + + return object_paths + + def list_objects(self, starting_point = False): + """Return list of existing objects""" + + if not starting_point: + starting_point = self.object_dir + + object_paths = self.list_object_paths(starting_point) + objects = [] + log.debug("Paths recieved: %s", object_paths) + log.debug("And te starting point: %s", starting_point) + + for path in object_paths: + objects.append(os.path.relpath(path, starting_point)) + + return objects + + def transfer_global_explorers(self): self.transfer_dir(GLOBAL_EXPLORER_DIR, REMOTE_GLOBAL_EXPLORER_DIR)