Add the option to copy tree in addition to making a symlink tree from elsewhere.
[htsworkflow.git] / htsworkflow / submission / results.py
index 36c2c78e7b2b0aac0613217ec2171f84a3c727ba..5633745687c70cc9954685fa582b66c6d62a730f 100644 (file)
@@ -2,6 +2,7 @@
 """
 from collections import MutableMapping
 import os
+import shutil
 import logging
 
 from collections import namedtuple
@@ -45,7 +46,7 @@ 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:
@@ -75,8 +76,11 @@ class ResultMap(MutableMapping):
                 if not os.path.exists(source_pathname):
                     raise IOError(
                         "{0} does not exist".format(source_pathname))
-                if not os.path.exists(target_pathname):
-                    os.symlink(source_pathname, target_pathname)
+                if not (os.path.exists(target_pathname) or os.path.isdir(source_pathname)):
+                    if link:
+                        os.symlink(source_pathname, target_pathname)
+                    else:
+                        shutil.copy(source_pathname, target_pathname)
                     LOGGER.info(
                         'LINK {0} to {1}'.format(source_pathname,
                                                  target_pathname))