Skip to content

Commit

Permalink
hide some skipped items from bw apply output
Browse files Browse the repository at this point in the history
closes #378
  • Loading branch information
trehn committed Dec 31, 2017
1 parent 6b0ce58 commit f767277
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 54 deletions.
57 changes: 36 additions & 21 deletions bundlewrap/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bundlewrap.utils.text import blue, bold, italic, wrap_question
from bundlewrap.utils.ui import io


BUILTIN_ITEM_ATTRIBUTES = {
'cascade_skip': None,
'comment': None,
Expand Down Expand Up @@ -87,6 +88,24 @@ class Item(object):
ITEM_ATTRIBUTES = {}
ITEM_TYPE_NAME = None
REQUIRED_ATTRIBUTES = []
SKIP_REASON_CMDLINE = 1
SKIP_REASON_DEP_FAILED = 2
SKIP_REASON_FAULT_UNAVAILABLE = 3
SKIP_REASON_INTERACTIVE = 4
SKIP_REASON_INTERACTIVE_ONLY = 5
SKIP_REASON_NO_TRIGGER = 6
SKIP_REASON_SOFTLOCK = 7
SKIP_REASON_UNLESS = 8
SKIP_REASON_DESC = {
SKIP_REASON_CMDLINE: _("cmdline"),
SKIP_REASON_DEP_FAILED: _("dependency failed"),
SKIP_REASON_FAULT_UNAVAILABLE: _("Fault unavailable"),
SKIP_REASON_INTERACTIVE: _("declined interactively"),
SKIP_REASON_INTERACTIVE_ONLY: _("interactive only"),
SKIP_REASON_NO_TRIGGER: _("not triggered"),
SKIP_REASON_SOFTLOCK: _("soft locked"),
SKIP_REASON_UNLESS: _("unless"),
}
STATUS_OK = 1
STATUS_FIXED = 2
STATUS_FAILED = 3
Expand Down Expand Up @@ -407,7 +426,6 @@ def apply(
self.node,
self,
)
keys_to_fix = None
status_code = None
status_before = None
status_after = None
Expand All @@ -418,11 +436,11 @@ def apply(
"autoskip matches {item} on {node}"
).format(item=self.id, node=self.node.name))
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("cmdline")]
skip_reason = self.SKIP_REASON_CMDLINE

if self._skip_with_soft_locks(my_soft_locks, other_peoples_soft_locks):
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("soft locked")]
skip_reason = self.SKIP_REASON_SOFTLOCK

for item in self._precedes_items:
if item._triggers_preceding_items(interactive=interactive):
Expand All @@ -441,14 +459,14 @@ def apply(
"skipping {item} on {node} because it wasn't triggered"
).format(item=self.id, node=self.node.name))
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("not triggered")]
skip_reason = self.SKIP_REASON_NO_TRIGGER

if status_code is None and self.cached_unless_result and status_code is None:
io.debug(_(
"'unless' for {item} on {node} succeeded, not fixing"
).format(item=self.id, node=self.node.name))
status_code = self.STATUS_SKIPPED
keys_to_fix = ["unless"]
skip_reason = self.SKIP_REASON_UNLESS

if self._faults_missing_for_attributes and status_code is None:
if self.error_on_missing_fault:
Expand All @@ -465,7 +483,7 @@ def apply(
node=self.node.name,
))
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("Fault unavailable")]
skip_reason = self.SKIP_REASON_FAULT_UNAVAILABLE

if status_code is None:
try:
Expand All @@ -483,13 +501,12 @@ def apply(
node=self.node.name,
))
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("Fault unavailable")]
skip_reason = self.SKIP_REASON_FAULT_UNAVAILABLE
else:
if status_before.correct:
status_code = self.STATUS_OK

if status_code is None:
keys_to_fix = status_before.keys_to_fix
if not interactive:
with io.job(_("{node} {bundle} {item}").format(
bundle=bold(self.bundle.name),
Expand Down Expand Up @@ -536,26 +553,24 @@ def apply(
self.fix(status_before)
else:
status_code = self.STATUS_SKIPPED
keys_to_fix = [_("interactive")]
skip_reason = self.SKIP_REASON_INTERACTIVE

if status_code is None:
status_after = self.get_status(cached=False)
status_code = self.STATUS_FIXED if status_after.correct else self.STATUS_FAILED

if status_code in (self.STATUS_OK, self.STATUS_SKIPPED):
# can't use else for this because status_before is None
changes = keys_to_fix
if status_code == self.STATUS_OK:
details = None
elif status_code == self.STATUS_SKIPPED:
details = skip_reason
elif status_before.must_be_created:
changes = True
details = True
elif status_before.must_be_deleted:
changes = False
details = False
elif status_code == self.STATUS_FAILED:
details = status_after.display_keys_to_fix
else:
changes = self.display_dicts(
self.cached_cdict.copy(),
status_after.sdict.copy(),
status_after.keys_to_fix[:] if status_after.keys_to_fix
else status_before.keys_to_fix,
)[2]
details = status_before.display_keys_to_fix

self.node.repo.hooks.item_apply_end(
self.node.repo,
Expand All @@ -566,7 +581,7 @@ def apply(
status_before=status_before,
status_after=status_after,
)
return (status_code, changes)
return (status_code, details)

def ask(self, status_should, status_actual, relevant_keys):
"""
Expand Down
12 changes: 6 additions & 6 deletions bundlewrap/items/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def _get_result(
item=self.id,
node=self.node.name,
))
return (self.STATUS_SKIPPED, [_("Fault unavailable")])
return (self.STATUS_SKIPPED, self.SKIP_REASON_FAULT_UNAVAILABLE)

if self.covered_by_autoskip_selector(autoskip_selector):
io.debug(_(
"autoskip matches {item} on {node}"
).format(item=self.id, node=self.node.name))
return (self.STATUS_SKIPPED, [_("cmdline")])
return (self.STATUS_SKIPPED, self.SKIP_REASON_CMDLINE)

if self._skip_with_soft_locks(my_soft_locks, other_peoples_soft_locks):
return (self.STATUS_SKIPPED, [_("soft locked")])
return (self.STATUS_SKIPPED, self.SKIP_REASON_SOFTLOCK)

if interactive is False and self.attributes['interactive'] is True:
return (self.STATUS_SKIPPED, [_("interactive only")])
return (self.STATUS_SKIPPED, self.SKIP_REASON_INTERACTIVE_ONLY)

for item in self._precedes_items:
if item._triggers_preceding_items(interactive=interactive):
Expand All @@ -77,7 +77,7 @@ def _get_result(

if self.triggered and not self.has_been_triggered:
io.debug(_("skipping {} because it wasn't triggered").format(self.id))
return (self.STATUS_SKIPPED, [_("not triggered")])
return (self.STATUS_SKIPPED, self.SKIP_REASON_NO_TRIGGER)

if self.unless:
with io.job(_("{node} {bundle} {item} checking 'unless' condition").format(
Expand All @@ -95,7 +95,7 @@ def _get_result(
name=self.name,
node=self.bundle.node.name,
))
return (self.STATUS_SKIPPED, ["unless"])
return (self.STATUS_SKIPPED, self.SKIP_REASON_UNLESS)

question_body = ""
if self.attributes['data_stdin'] is not None:
Expand Down
63 changes: 36 additions & 27 deletions bundlewrap/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,21 @@ def format_node_result(result):
return ", ".join(output)


def handle_apply_result(node, item, status_code, interactive, changes=None):
def handle_apply_result(node, item, status_code, interactive, details=None):
if status_code == Item.STATUS_SKIPPED and details in (
Item.SKIP_REASON_CMDLINE,
Item.SKIP_REASON_NO_TRIGGER,
Item.SKIP_REASON_UNLESS,
):
# skipped for "unless" or "not triggered", don't output those
return
formatted_result = format_item_result(
status_code,
node.name,
item.bundle.name if item.bundle else "", # dummy items don't have bundles
item.id,
interactive=interactive,
changes=changes,
details=details,
)
if formatted_result is not None:
if status_code == Item.STATUS_FAILED:
Expand Down Expand Up @@ -153,7 +160,7 @@ def handle_result(task_id, return_value, duration):
item_id = task_id.split(":", 1)[1]
item = find_item(item_id, item_queue.pending_items)

status_code, changes = return_value
status_code, details = return_value

if status_code == Item.STATUS_FAILED:
for skipped_item in item_queue.item_failed(item):
Expand All @@ -162,7 +169,7 @@ def handle_result(task_id, return_value, duration):
skipped_item,
Item.STATUS_SKIPPED,
interactive,
changes=[_("dep failed")],
details=[_("dep failed")],
)
results.append((skipped_item.id, Item.STATUS_SKIPPED, timedelta(0)))
elif status_code in (Item.STATUS_FIXED, Item.STATUS_ACTION_SUCCEEDED):
Expand All @@ -171,18 +178,18 @@ def handle_result(task_id, return_value, duration):
item_queue.item_ok(item)
elif status_code == Item.STATUS_SKIPPED:
for skipped_item in item_queue.item_skipped(item):
skipped_reason = [_("dep skipped")]
skip_reason = Item.SKIP_REASON_DEP_FAILED
for lock in other_peoples_soft_locks:
for selector in lock['items']:
if skipped_item.covered_by_autoskip_selector(selector):
skipped_reason = [_("soft locked")]
skip_reason = Item.SKIP_REASON_SOFTLOCK
break
handle_apply_result(
node,
skipped_item,
Item.STATUS_SKIPPED,
interactive,
changes=skipped_reason,
details=skip_reason,
)
results.append((skipped_item.id, Item.STATUS_SKIPPED, timedelta(0)))
else:
Expand All @@ -193,7 +200,7 @@ def handle_result(task_id, return_value, duration):
),
))

handle_apply_result(node, item, status_code, interactive, changes=changes)
handle_apply_result(node, item, status_code, interactive, details=details)
io.progress_advance()
if not isinstance(item, DummyItem):
results.append((item.id, status_code, duration))
Expand Down Expand Up @@ -259,19 +266,21 @@ def _flatten_group_hierarchy(groups):
return order


def format_item_result(result, node, bundle, item, interactive=False, changes=None):
if changes is True:
changes_text = "({})".format(_("create"))
elif changes is False:
changes_text = "({})".format(_("remove"))
elif changes is None:
changes_text = ""
def format_item_result(result, node, bundle, item, interactive=False, details=None):
if details is True:
details_text = "({})".format(_("create"))
elif details is False:
details_text = "({})".format(_("remove"))
elif details is None:
details_text = ""
elif result == Item.STATUS_SKIPPED:
details_text = "({})".format(Item.SKIP_REASON_DESC[details])
else:
changes_text = "({})".format(", ".join(sorted(changes)))
details_text = "({})".format(", ".join(sorted(details)))
if result == Item.STATUS_FAILED:
return "{x} {node} {bundle} {item} {status} {changes}".format(
return "{x} {node} {bundle} {item} {status} {details}".format(
bundle=bold(bundle),
changes=changes_text,
details=details_text,
item=item,
node=bold(node),
status=red(_("failed")),
Expand All @@ -286,18 +295,18 @@ def format_item_result(result, node, bundle, item, interactive=False, changes=No
x=bold(green("✓")),
)
elif result == Item.STATUS_SKIPPED:
return "{x} {node} {bundle} {item} {status} {changes}".format(
return "{x} {node} {bundle} {item} {status} {details}".format(
bundle=bold(bundle),
changes=changes_text,
details=details_text,
item=item,
node=bold(node),
x=bold(yellow("»")),
status=yellow(_("skipped")),
)
elif result == Item.STATUS_FIXED:
return "{x} {node} {bundle} {item} {status} {changes}".format(
return "{x} {node} {bundle} {item} {status} {details}".format(
bundle=bold(bundle),
changes=changes_text,
details=details_text,
item=item,
node=bold(node),
x=bold(green("✓")),
Expand Down Expand Up @@ -834,14 +843,14 @@ def handle_result(task_id, return_value, duration):
node_name, bundle_name, item_id = task_id.split(":", 2)
if not unless_result and not item_status.correct:
if item_status.must_be_created:
changes_text = _("create")
details_text = _("create")
elif item_status.must_be_deleted:
changes_text = _("remove")
details_text = _("remove")
else:
changes_text = ", ".join(sorted(item_status.display_keys_to_fix))
io.stderr("{x} {node} {bundle} {item} ({changes})".format(
details_text = ", ".join(sorted(item_status.display_keys_to_fix))
io.stderr("{x} {node} {bundle} {item} ({details})".format(
bundle=bold(bundle_name),
changes=changes_text,
details=details_text,
item=item_id,
node=bold(node_name),
x=red("✘"),
Expand Down

0 comments on commit f767277

Please sign in to comment.