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

[ENTRIES] Implements hide_undetected option to mask missing values #166

Merged
merged 1 commit into from
Mar 2, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
### Added
- Python 3.13 & 3.14 official support
- `entries_color` config option validation
- `hide_undetected` config option to hide undetected entries

### Changed
- `Entry` behavior in boolean contexts ("truthy" when `value` is populated)

## [v4.15.0.0] - 2024-09-30
### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ Below stand further descriptions for each available (default) option :
// Note that the `--logo-style` argument overrides this setting.
"logo_style": "",
//
// Use this option to hide undetected entries, to prevent "Not detected" messages from being displayed.
"hide_undetected": false,
//
// Enable icons for entries.
// A terminal "nerd font" is required to display the icons. Otherwise, these are simply missing and a placeholder will be seen.
// You can also refer to : <https://github.com/ryanoasis/nerd-fonts>.
Expand Down
2 changes: 1 addition & 1 deletion archey/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _entry_instantiator(entry: dict) -> Optional[Entry]:
mapper = executor.map

for entry_instance in mapper(_entry_instantiator, available_entries):
if entry_instance:
if entry_instance is not None:
output.add_entry(entry_instance)

output.output()
Expand Down
3 changes: 3 additions & 0 deletions archey/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, name: Optional[str] = None, value=None, options: Optional[dic
# Provision a logger for each entry.
self._logger = logging.getLogger(self.__module__)

def __bool__(self) -> bool:
return bool(self.value)

def output(self, output) -> None:
"""Output the results to output. Can be overridden by subclasses."""
if self.value:
Expand Down
17 changes: 9 additions & 8 deletions archey/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from archey.logos import get_logo_width, lazy_load_logo_module


class Output:
class Output: # pylint: disable=too-many-instance-attributes
"""
This is the object handling output entries populating.
It also handles the logo choice based on some system detections.
Expand All @@ -27,12 +27,12 @@ class Output:
__logo_right_padding = " "

def __init__(self, **kwargs):
configuration = Configuration()
self.configuration = Configuration()

# Fetches passed arguments.
self._format_to_json = kwargs.get("format_to_json")
preferred_logo_style = (
kwargs.get("preferred_logo_style") or configuration.get("logo_style") or ""
kwargs.get("preferred_logo_style") or self.configuration.get("logo_style") or ""
).upper()

# If logo shouldn't be displayed, don't load any module and reset right padding
Expand All @@ -59,11 +59,11 @@ def __init__(self, **kwargs):

# If `os-release`'s `ANSI_COLOR` option is set, honor it.
ansi_color = Distributions.get_ansi_color()
if ansi_color and configuration.get("honor_ansi_color"):
if ansi_color and self.configuration.get("honor_ansi_color"):
# Replace each Archey integrated colors by `ANSI_COLOR`.
self._colors = len(self._colors) * [Style.escape_code_from_attrs(ansi_color)]

entries_color = configuration.get("entries_color")
entries_color = self.configuration.get("entries_color")
if entries_color:
self._entries_color = Style.escape_code_from_attrs(entries_color)
elif self._colors:
Expand All @@ -76,9 +76,9 @@ def __init__(self, **kwargs):
# Each class output will be added in the list below afterwards
self._results = []

def add_entry(self, module: Entry) -> None:
def add_entry(self, entry: Entry) -> None:
"""Append an entry to the list of entries to output"""
self._entries.append(module)
self._entries.append(entry)

def append(self, key: str, value) -> None:
"""Append a pre-formatted entry to the final output content"""
Expand All @@ -95,7 +95,8 @@ def output(self) -> None:
else:
# Iterate through the entries and run their output method to add their content.
for entry in self._entries:
entry.output(self)
if not self.configuration.get("hide_undetected") or entry:
entry.output(self)
self._output_text()

def _output_json(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion archey/test/test_archey_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_entry_itself(self):
def test_entry_disabling(self):
"""Test `Entry` _disabling_"""
simple_entry = _SimpleEntry()
self.assertTrue(simple_entry)
self.assertIsNotNone(simple_entry)

simple_entry = _SimpleEntry(options={"disabled": True})
self.assertIsNone(simple_entry)
Expand All @@ -44,6 +44,7 @@ def test_entry_usage(self):
simple_entry = _SimpleEntry()
self.assertEqual(simple_entry.name, "Simple Entry")
self.assertIsNone(simple_entry.value)
self.assertFalse(simple_entry)

# No `_PRETTY_NAME` is defined : proper fall-back on entry internal name.
delattr(_SimpleEntry, "_PRETTY_NAME")
Expand All @@ -53,6 +54,7 @@ def test_entry_usage(self):
simple_entry = _SimpleEntry("T", "est")
self.assertEqual(simple_entry.name, "T")
self.assertEqual(simple_entry.value, "est")
self.assertTrue(simple_entry)

def test_entry_output_overriding(self):
"""Check `Entry.output` public method overriding"""
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"entries_color": "",
"honor_ansi_color": true,
"logo_style": "",
"hide_undetected": false,
"entries_icon": false,
"entries": [
{ "type": "User" },
Expand Down
Loading