Skip to content

Commit

Permalink
add remove containers
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed May 21, 2024
1 parent f810a37 commit b707eee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
9 changes: 9 additions & 0 deletions xrpld_netgen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
remove_directory,
bcolors,
check_deps,
remove_containers,
run_start,
run_stop,
)
Expand All @@ -71,6 +72,14 @@ def main():

check_deps([f"{basedir}/deploykit/prerequisites.sh"])

print(f"{bcolors.BLUE}Removing existing containers: {bcolors.RED}")
remove_containers("docker stop xahau")
remove_containers("docker rm xahau")
remove_containers("docker stop explorer")
remove_containers("docker rm explorer")
remove_containers("docker stop xrpl")
remove_containers("docker rm xrpl")

parser = argparse.ArgumentParser(
description="A python cli to build xrpld networks and standalone ledgers."
)
Expand Down
2 changes: 1 addition & 1 deletion xrpld_netgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def start_local(
["./start.sh"],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL,
)
if result.returncode == 0:
print(
Expand Down
25 changes: 23 additions & 2 deletions xrpld_netgen/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run_start(cmd: List[str], protocol: str, version: str, type: str):
cmd,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL,
)
if result.returncode == 0:
print(
Expand Down Expand Up @@ -77,7 +77,7 @@ def run_stop(cmd: List[str]):
cmd,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL,
)
if result.returncode == 0:
print(f"{bcolors.CYAN}shut down docker container {bcolors.END}")
Expand Down Expand Up @@ -117,6 +117,27 @@ def check_deps(cmd: List[str]) -> None:
sys.exit(1)


def remove_containers(cmd: str) -> None:
try:
args = shlex.split(cmd)
result = subprocess.run(
args,
check=True,
stdout=subprocess.STDOUT,
)
if result.returncode == 0:
print(f"{bcolors.GREEN}Docker Ready{bcolors.END}")
else:
print(f"{bcolors.RED}Docker ERROR{bcolors.END}")
return
except subprocess.CalledProcessError as e:
return
except FileNotFoundError:
return
except OSError as e:
return


def run_command(dir: str, command: str) -> None:
try:
# Split the command into a list of arguments
Expand Down

0 comments on commit b707eee

Please sign in to comment.