Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-4527: Change delete step and init --masterfiles behavior #159

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading