Skip to content

Commit

Permalink
Merge pull request #159 from craigcomstock/CFE-4257
Browse files Browse the repository at this point in the history
CFE-4527: Change delete step and init --masterfiles behavior
  • Loading branch information
olehermanse authored Sep 21, 2023
2 parents 110ed25 + 8b910a2 commit f6f8cbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
6 changes: 5 additions & 1 deletion cfbs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def _perform_build_step(module, step, max_length):
as_string = " ".join(["'%s'" % f for f in files])
print("%s delete %s" % (prefix, as_string))
for file in files:
rm(os.path.join(source, file))
if not rm(os.path.join(source, file), True):
print(
"Warning: tried to delete '%s' but path did not exist."
% os.path.join(source, file)
)
elif operation == "json":
src, dst = args
if dst in [".", "./"]:
Expand Down
24 changes: 10 additions & 14 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, message):

_commands = OrderedDict()


# Decorator to specify that a function is a command (verb in the CLI)
# Adds the name + function pair to the global dict of commands
# Does not modify/wrap the function it decorates.
Expand Down Expand Up @@ -286,30 +287,25 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int:
branch = masterfiles
to_add = "masterfiles"

if to_add:
ret = add_command([to_add])
if ret != 0:
return ret

if branch is not None:
config = CFBSConfig.get_instance()
module = config.get_module_from_build("masterfiles")
remote = module["repo"]
remote = "https://github.com/cfengine/masterfiles"
commit = ls_remote(remote, branch)
if commit is None:
user_error("Failed to add masterfiles from branch %s" % branch)
user_error(
"Failed to find branch or tag %s at remote %s" % (branch, remote)
)
log.debug("Current commit for masterfiles branch %s is %s" % (branch, commit))
module["url"] = remote
del module["repo"]
module["commit"] = commit
config.save()
to_add = "%s@%s" % (remote, commit)
if to_add:
ret = add_command([to_add])
if ret != 0:
return ret

return 0


@cfbs_command("status")
def status_command() -> int:

config = CFBSConfig.get_instance()
print("Name: %s" % config["name"])
print("Description: %s" % config["description"])
Expand Down
8 changes: 6 additions & 2 deletions cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import subprocess
import hashlib
import logging as log
import urllib
import urllib.request # needed on some platforms
from collections import OrderedDict
Expand Down Expand Up @@ -56,10 +57,13 @@ def touch(path: str):
def rm(path: str, missing_ok=False):
if not missing_ok:
assert os.path.exists(path)
if missing_ok and not os.path.exists(path):
return False
if os.path.isdir(path):
rmtree(path)
if os.path.isfile(path):
os.remove(path)
else: # Assume path is a file
os.remove(path) # Will raise exception if missing
return True


def cp(src, dst):
Expand Down

0 comments on commit f6f8cbf

Please sign in to comment.