2 # Copyright (c) 2015 All rights reserved
3 # This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
12 import processutils as putils
20 def mkdir_if_not_exist(path):
22 raise Exception('Path should not be empty.')
23 putils.execute(["mkdir", "-p", path])
26 def copy(direction, src, dst, **kwargs):
27 if direction == 'from':
32 files = glob.glob(src)
34 shutil._copy(file, dst, **kwargs)
36 shutil._copy(src, dst, **kwargs)
39 def _copy(src, dst, **kwargs):
40 if os.path.isfile(src):
42 shutil.mkdir_if_not_exsist(dst)
43 putils.execute(['cp', src, dst], **kwargs)
45 putils.execute(['cp', '-R', src, dst], **kwargs)
48 def rm(path, **kwargs):
49 putils.execute(['rm', '-rf', path], **kwargs)
53 putils.execute(["mv", src, dst])
56 def get_all_files_in_path(path):
57 if os.path.exists(path):
58 return putils.execute(['l', path])
61 def replace_string_in_file(file, str, replace):
62 with open(file, 'r') as f:
64 string = string.replace(str, replace)
65 with open(file, 'w+') as f: