From 2c9beb95064c7105bacdbbbf2870f27646a3558d Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@kr.ethz.ch>
Date: Fri, 7 Oct 2011 16:23:33 +0200
Subject: [PATCH 1/4] use list not method

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
---
 lib/cdist/config_install.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py
index 2905df67..ad8a13b9 100644
--- a/lib/cdist/config_install.py
+++ b/lib/cdist/config_install.py
@@ -232,7 +232,8 @@ class ConfigInstall:
     def stage_run(self):
         """The final (and real) step of deployment"""
         log.info("Generating and executing code")
-        for cdist_object in cdist.core.Object.list_objects(self.context.object_base_path):
+        for cdist_object in cdist.core.Object.list_objects(self.context.object_base_path,
+                                                           self.context.type_base_path):
             log.debug("Run object: %s", cdist_object)
             self.object_run(cdist_object)
 
@@ -259,7 +260,8 @@ class ConfigInstall:
         new_objects_created = True
         while new_objects_created:
             new_objects_created = False
-            for cdist_object in cdist.core.Object.list_objects(self.context.object_base_path):
+            for cdist_object in cdist.core.Object.list_objects(self.context.object_base_path,
+                                                               self.context.type_base_path):
                 if cdist_object.prepared:
                     log.debug("Skipping rerun of object %s", cdist_object)
                     continue
@@ -286,16 +288,16 @@ class ConfigInstall:
         self.transfer_path(self.context.global_explorer_path, 
             self.remote_global_explorer_path)
 
-    def transfer_type_explorers(self, type):
+    def transfer_type_explorers(self, cdist_type):
         """Transfer explorers of a type, but only once"""
-        if type.transferred_explorers:
+        if cdist_type.transferred_explorers:
             log.debug("Skipping retransfer for explorers of %s", type)
             return
         else:
             # Do not retransfer
-            type.transferred_explorers = True
+            cdist_type.transferred_explorers = True
 
-        explorers = type.explorers()
+        explorers = cdist_type.explorers
 
         if len(explorers) > 0:
             rel_path = os.path.join(type.explorer_path(), explorer)

From fd2fa235647bbd86e86ad0cd59b741fb44647a43 Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@kr.ethz.ch>
Date: Fri, 7 Oct 2011 16:27:15 +0200
Subject: [PATCH 2/4] fix typeexplorer transfer

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
---
 lib/cdist/config_install.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py
index ad8a13b9..eeb9e4c0 100644
--- a/lib/cdist/config_install.py
+++ b/lib/cdist/config_install.py
@@ -291,7 +291,7 @@ class ConfigInstall:
     def transfer_type_explorers(self, cdist_type):
         """Transfer explorers of a type, but only once"""
         if cdist_type.transferred_explorers:
-            log.debug("Skipping retransfer for explorers of %s", type)
+            log.debug("Skipping retransfer for explorers of %s", cdist_type)
             return
         else:
             # Do not retransfer
@@ -300,10 +300,8 @@ class ConfigInstall:
         explorers = cdist_type.explorers
 
         if len(explorers) > 0:
-            rel_path = os.path.join(type.explorer_path(), explorer)
+            rel_path = cdist_type.explorer_path
             src = os.path.join(self.context.type_base_path, rel_path)
             dst = os.path.join(self.context.remote_type_path, rel_path)
+            self.context.transfer_path(src, dst)
 
-            # Ensure that the path exists
-            self.remote_mkdir(dst)
-            self.transfer_path(src, dst)

From dd8617141e41599182a56cd3a8110d733d772f05 Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@kr.ethz.ch>
Date: Fri, 7 Oct 2011 16:27:50 +0200
Subject: [PATCH 3/4] todo shift

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
---
 doc/dev/todo/niconext | 8 --------
 doc/dev/todo/steven   | 4 ++++
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/doc/dev/todo/niconext b/doc/dev/todo/niconext
index b8fcc5b0..f96da0de 100644
--- a/doc/dev/todo/niconext
+++ b/doc/dev/todo/niconext
@@ -1,14 +1,6 @@
 2.0.3:
 
 - fix emulator
-- introduce tests:
-   - does $require work?
-   - $whatever should fail if there is no global explorer directory
-   - emulator may only be called with __ as prefix - fail otherwise!
-
-- Create GlobalExplorer
-   
-- base_dir passing in config/config_install superseeded by __cdist_base_dir?
 
 --------------------------------------------------------------------------------
 
diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven
index 54b43210..4b374a92 100644
--- a/doc/dev/todo/steven
+++ b/doc/dev/todo/steven
@@ -33,3 +33,7 @@ Tests needed:
    - Fail if cache_dir cannot be created from current out_dir
    - transfer_type_explorers: Explorers are not transferred twice
    - transfer_type_explorers: No transfer tried if there are no type_explorers
+
+   - does $require work?
+   - $whatever should fail if there is no global explorer directory
+   - emulator may only be called with __ as prefix - fail otherwise!

From 03226dc5aa5c379c153153e079d696eb5277ab3a Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@kr.ethz.ch>
Date: Fri, 7 Oct 2011 16:36:05 +0200
Subject: [PATCH 4/4] more fixes for relative path address

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
---
 lib/cdist/config_install.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py
index eeb9e4c0..2f4aa261 100644
--- a/lib/cdist/config_install.py
+++ b/lib/cdist/config_install.py
@@ -174,18 +174,22 @@ class ConfigInstall:
     def run_type_explorer(self, cdist_object):
         """Run type specific explorers for objects"""
 
-        type = cdist_object.type
-        self.transfer_type_explorers(type)
+        cdist_type = cdist_object.type
+        self.transfer_type_explorers(cdist_type)
 
         cmd = []
         cmd.append("__explorer="        + self.context.remote_global_explorer_path)
-        cmd.append("__type_explorer="   + type.explorer_remote_path)
-        cmd.append("__object="          + object.path_remote)
-        cmd.append("__object_id="       + object.object_id)
-        cmd.append("__object_fq="       + cdist_object)
+        cmd.append("__type_explorer="   + os.path.join(
+                                            self.context.remote_type_path,
+                                            cdist_type.explorer_path))
+        cmd.append("__object="          + os.path.join(
+                                            self.context.remote_object_path,
+                                            cdist_object.path))
+        cmd.append("__object_id="       + cdist_object.object_id)
+        cmd.append("__object_fq="       + cdist_object.name)
 
         # Need to transfer at least the parameters for objects to be useful
-        self.path.transfer_object_parameter(cdist_object)
+        self.transfer_object_parameter(cdist_object)
 
         explorers = self.path.list_type_explorers(type)
         for explorer in explorers:
@@ -280,7 +284,7 @@ class ConfigInstall:
             cdist_object.parameter_path)
 
         # Synchronise parameter dir afterwards
-        self.transfer_path(local_path, remote_path)
+        self.context.transfer_path(src, dst)
 
     def transfer_global_explorers(self):
         """Transfer the global explorers"""
@@ -303,5 +307,11 @@ class ConfigInstall:
             rel_path = cdist_type.explorer_path
             src = os.path.join(self.context.type_base_path, rel_path)
             dst = os.path.join(self.context.remote_type_path, rel_path)
+
+            # Ensure full path until type exists:
+            # /var/lib/cdist/conf/type/__directory/explorer
+            # /var/lib/cdist/conf/type/__directory may not exist,
+            # but remote_mkdir uses -p to fix this
+            self.context.remote_mkdir(dst)
             self.context.transfer_path(src, dst)