Skip to content

Commit

Permalink
chore: use run_command in Command
Browse files Browse the repository at this point in the history
chore: update command execution logic to fail hard if a command fails
  • Loading branch information
Jean-Louis Fuchs committed Mar 3, 2024
1 parent aa82c4d commit 3bc1200
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyaptly/command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Commands with dependencies."""
import collections
import logging
import subprocess

from frozendict import frozendict

from . import state_reader
from . import state_reader, util

lg = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,9 +93,18 @@ def execute(self):

if not Command.pretend_mode:
lg.debug("Running command: %s", " ".join(self.cmd))
self._finished = bool(subprocess.check_call(self.cmd))
# It seems the intention of the original code is to a redo a command if it
# scheduled multiple times and fails the first time. But there is also:

# `commands = set([c for c in commands if c is not None])`

# which prevents that. I guess the feature is currently not needed.
# So I decided to change that. For now we fail hard if a `Command` fails.
# I guess we will see in production what happens.
util.run_command(self.cmd, check=True)
else:
lg.info("Pretending to run command: %s", " ".join(self.cmd))
self._finished = True

return self._finished

Expand Down

0 comments on commit 3bc1200

Please sign in to comment.