Skip to content

Commit

Permalink
Ensured copy command creates necessary directories
Browse files Browse the repository at this point in the history
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
  • Loading branch information
olehermanse committed Apr 26, 2021
1 parent 72753e2 commit 6f354a6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

def _sh(cmd: str):
# print(cmd)
os.system(cmd)
r = os.system(cmd)
if r != 0:
user_error(f"Command failed - {cmd}")


def sh(cmd: str, directory=None):
Expand All @@ -20,22 +22,27 @@ def sh(cmd: str, directory=None):


def mkdir(path: str):
os.system(f"mkdir -p {path}")
sh(f"mkdir -p {path}")


def touch(path: str):
os.system(f"touch {path}")
sh(f"touch {path}")


def rm(path: str):
os.system(f'rm -rf "{path}"')
sh(f'rm -rf "{path}"')


def cp(src, dst):
above = os.path.dirname(dst)
if not os.path.exists(above):
mkdir(above)
if dst.endswith("/") and not os.path.exists(dst):
mkdir(dst)
if os.path.isfile(src):
os.system(f"rsync -r {src} {dst}")
sh(f"rsync -r {src} {dst}")
return
os.system(f"rsync -r {src}/ {dst}")
sh(f"rsync -r {src}/ {dst}")


def pad_left(s, n) -> int:
Expand Down

0 comments on commit 6f354a6

Please sign in to comment.