1 from __future__
import print_function
2 from builtins
import str
14 import distutils.dir_util
16 from BaseMTTUtility
import *
18 from sys
import version_info
19 if version_info[0] == 3:
20 if version_info[1] <= 3:
21 from imp
import reload
23 from importlib
import reload
34 BaseMTTUtility.__init__(self)
36 self.
options[
'src'] = (
None,
"The top directory of the tree to be copied")
37 self.
options[
'preserve_symlinks'] = (
"0",
"Preserve symlinks instead of copying the contents")
38 self.
options[
'preserve_directory'] = (
"0",
"Copies directory instead of contents")
44 lines = testDef.printOptions(self.
options)
50 testDef.logger.verbose_print(
"Copytree Execute")
53 testDef.parseOptions(log, self.
options, keyvals, cmds)
57 if cmds[
'src']
is None:
59 log[
'stderr'] =
"Src directory not specified"
63 log[
'stderr'] =
"Src directory not specified"
66 dst = os.path.join(testDef.options[
'scratchdir'], log[
'section'].replace(
":",
"_"))
71 if cmds[
'asis']
and os.path.exists(dst)
and os.path.isdir(dst):
72 testDef.logger.verbose_print(
"As-Is location " + dst +
" exists and is a directory")
80 if os.path.exists(dst):
83 for srcpath
in cmds[
'src'].split(
','):
84 srcpath = srcpath.strip()
85 reload(distutils.dir_util)
86 if cmds[
'preserve_directory'] !=
"0":
87 subdst = os.path.join(dst,os.path.basename(srcpath))
88 if os.path.exists(subdst):
91 distutils.dir_util.copy_tree(srcpath, subdst, preserve_symlinks=int(cmds[
'preserve_symlinks']))
93 distutils.dir_util.copy_tree(srcpath, dst, preserve_symlinks=int(cmds[
'preserve_symlinks']))
95 except (os.error, shutil.Error, \
96 distutils.errors.DistutilsFileError)
as e:
98 log[
'stderr'] = str(e)