summaryrefslogtreecommitdiffstats
path: root/odl-pipeline/lib/utils/shutil.py
diff options
context:
space:
mode:
authorNikolas Hermanns <nikolas.hermanns@ericsson.com>2016-12-13 10:26:11 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-12-13 10:26:11 +0000
commit2dd53e9153a37a5a9f14a8772224dbdaa091bbfa (patch)
tree7e083f4959878d78f943c07cc32575c66a4ba05d /odl-pipeline/lib/utils/shutil.py
parent2445ba0a0325611e0b927ecc7ed4d361426e5fc4 (diff)
parent416f9cf177801cecfe39f5249d73e3a4a85f0bbd (diff)
Merge "adding odl-pipeline"
Diffstat (limited to 'odl-pipeline/lib/utils/shutil.py')
-rwxr-xr-xodl-pipeline/lib/utils/shutil.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/odl-pipeline/lib/utils/shutil.py b/odl-pipeline/lib/utils/shutil.py
new file mode 100755
index 0000000..40e2aba
--- /dev/null
+++ b/odl-pipeline/lib/utils/shutil.py
@@ -0,0 +1,66 @@
+#
+# Copyright (c) 2015 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+#
+import os
+import glob
+import processutils as putils
+
+
+class shutil():
+ '''
+ classdocs
+ '''
+ @staticmethod
+ def mkdir_if_not_exsist(path):
+ if not path:
+ raise Exception('Path should not be empty.')
+ putils.execute(["mkdir", "-p", path])
+
+ @staticmethod
+ def copy(direction, src, dst, **kwargs):
+ if direction == 'from':
+ dst_tmp = dst
+ dst = src
+ src = dst_tmp
+ if src[-1:] == '*':
+ files = glob.glob(src)
+ for file in files:
+ shutil._copy(file, dst, **kwargs)
+ else:
+ shutil._copy(src, dst, **kwargs)
+
+ @staticmethod
+ def _copy(src, dst, **kwargs):
+ if os.path.isfile(src):
+ if dst[-1:] == '/':
+ shutil.mkdir_if_not_exsist(dst)
+ putils.execute(['cp', src, dst], **kwargs)
+ else:
+ putils.execute(['cp', '-R', src, dst], **kwargs)
+
+ @staticmethod
+ def rm(path, **kwargs):
+ putils.execute(['rm', '-rf', path], **kwargs)
+
+ @staticmethod
+ def mv(src, dst):
+ putils.execute(["mv", src, dst])
+
+ @staticmethod
+ def get_all_files_in_path(path):
+ if os.path.exists(path):
+ return putils.execute(['l', path])
+
+ @staticmethod
+ def replace_string_in_file(file, str, replace):
+ with open(file, 'r') as f:
+ string = f.read()
+ string = string.replace(str, replace)
+ with open(file, 'w+') as f:
+ f.write(string)