Skip to content

Commit

Permalink
Added the possibility to append (concatenate) files during build
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 a554946 commit 8feae09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
write_json,
read_json,
merge_json,
read_file,
mkdir,
touch,
rm,
cp,
sh,
Expand Down Expand Up @@ -233,6 +235,16 @@ def build_step(module, step, max_length):
else:
merged = extras
write_json(dst, merged)
elif operation == "append":
src, dst = args
if dst in [".", "./"]:
dst = ""
print(f"{prefix} append '{src}' 'masterfiles/{dst}'")
src, dst = os.path.join(source, src), os.path.join(destination, dst)
if not os.path.exists(dst):
touch(dst)
assert os.path.isfile(dst)
sh(f"cat '{src}' >> '{dst}'")
else:
user_error(f"Unknown build step operation: {operation}")

Expand Down
13 changes: 11 additions & 2 deletions cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@
import requests


def _sh(cmd: str):
# print(cmd)
os.system(cmd)


def sh(cmd: str, directory=None):
if directory:
os.system(f"( cd {directory} && {cmd} 1>/dev/null 2>/dev/null )")
_sh(f"( cd {directory} && {cmd} ) 1>/dev/null 2>/dev/null")
return
os.system(f"{cmd} 1>/dev/null 2>/dev/null")
_sh(f"( {cmd} ) 1>/dev/null 2>/dev/null")


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


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


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

Expand Down

0 comments on commit 8feae09

Please sign in to comment.