Add option to copy source files for a submission.
[htsworkflow.git] / htsworkflow / submission / results.py
index c9000e41e79f3c3e2b2962a4465636cdb718c933..50077523aca3970a517973adbd69f119f4f17e3d 100644 (file)
@@ -45,14 +45,21 @@ class ResultMap(MutableMapping):
                 lib_path = os.path.join(basepath, lib_path)
             self[lib_id] = lib_path
 
-    def make_tree_from(self, source_path, destpath = None):
+    def make_tree_from(self, source_path, destpath = None, link=True):
         """Create a tree using data files from source path.
         """
         if destpath is None:
             destpath = os.getcwd()
 
+        LOGGER.debug("Source_path: %s", source_path)
+        LOGGER.debug("Dest_path: %s", destpath)
         for lib_id in self.results_order:
             lib_path = self.results[lib_id]
+            LOGGER.debug("lib_path: %s", lib_path)
+            if os.path.isabs(lib_path):
+                lib_path = os.path.relpath(lib_path, destpath)
+
+            LOGGER.debug('lib_path: %s', lib_path)
             lib_destination = os.path.join(destpath, lib_path)
             if not os.path.exists(lib_destination):
                 LOGGER.info("Making dir {0}".format(lib_destination))
@@ -60,6 +67,7 @@ class ResultMap(MutableMapping):
 
             source_rel_dir = os.path.join(source_path, lib_path)
             source_lib_dir = os.path.abspath(source_rel_dir)
+            LOGGER.debug("source_lib_dir: %s", source_lib_dir)
 
             for filename in os.listdir(source_lib_dir):
                 source_pathname = os.path.join(source_lib_dir, filename)
@@ -68,7 +76,10 @@ class ResultMap(MutableMapping):
                     raise IOError(
                         "{0} does not exist".format(source_pathname))
                 if not os.path.exists(target_pathname):
-                    os.symlink(source_pathname, target_pathname)
+                    if link:
+                        os.symlink(source_pathname, target_pathname)
+                    else:
+                        os.copy(source_pathname, target_pathname)
                     LOGGER.info(
                         'LINK {0} to {1}'.format(source_pathname,
                                                  target_pathname))