From 18f361227c429f482e16f97defdd90014cfdaf9a Mon Sep 17 00:00:00 2001 From: Rodolfo Olivieri Date: Fri, 3 Jan 2025 14:39:55 -0300 Subject: [PATCH 1/3] Generate manpages for CLA and CLAD --- .packit.yaml | 8 +++++++- packaging/command-line-assistant.spec | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.packit.yaml b/.packit.yaml index 045a7a8..97b92a2 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -3,7 +3,11 @@ upstream_package_name: command-line-assistant downstream_package_name: command-line-assistant upstream_project_url: https://github.com/rhel-lightspeed/command-line-assistant -srpm_build_deps: [] +srpm_build_deps: + - python3-pip + - python3-dasbus + - python3-requests + - make jobs: # Build RPMs for each pull request @@ -17,6 +21,8 @@ jobs: - epel-9-aarch64 - epel-10-aarch64 actions: + post-upstream-clone: + - bash -c "cd docs; pip install -r requirements.txt; SPHINXBUILD=/builddir/.local/bin/sphinx-build make man" # do not get the version from a tag (git describe) but from the spec file get-current-version: - grep -oP '^Version:\s+\K\S+' packaging/command-line-assistant.spec diff --git a/packaging/command-line-assistant.spec b/packaging/command-line-assistant.spec index e0f42d7..f5a4afd 100644 --- a/packaging/command-line-assistant.spec +++ b/packaging/command-line-assistant.spec @@ -64,11 +64,27 @@ A simple wrapper to interact with RAG %{__install} -D -m 0644 data/release/xdg/config.toml %{buildroot}/%{_sysconfdir}/xdg/%{python_package_src}/config.toml # History file +<<<<<<< HEAD %{__install} -D -m 0644 data/release/xdg/history.json %{buildroot}/%{_sharedstatedir}/%{name}/history.json # Manpages %{__install} -D -m 0644 data/release/man/%{binary_name}.1 %{buildroot}/%{_mandir}/man1/%{binary_name}.1 %{__install} -D -m 0644 data/release/man/%{daemon_binary_name}.8 %{buildroot}/%{_mandir}/man8/%{daemon_binary_name}.8 +======= +## Create the folder under /var/lib/command-line-assistant +%{__install} -d %{buildroot}/%{_sharedstatedir}/%{name} +## Place the history file there +%{__install} -D -m 0644 data/release/xdg/history.json %{buildroot}/%{_sharedstatedir}/%{name}/history.json + +# Manpages +## Create directories for man1 and man8 +%{__install} -d -m 755 %{buildroot}%{_mandir}/man1 +%{__install} -d -m 755 %{buildroot}%{_mandir}/man8 + +# Install the man1 and man8 for cla(d) +%{__install} -p docs/build/man/%{binary_name}.1 %{buildroot}%{_mandir}/man1/%{binary_name}.1 +%{__install} -p docs/build/man/%{daemon_binary_name}.8 %{buildroot}%{_mandir}/man8/%{daemon_binary_name}.8 +>>>>>>> 119a35b (Generate manpages for CLA and CLAD) %post %systemd_post %{daemon_binary_name}.service From 6550814a9fb42768a64e9dd70e95c448906954cd Mon Sep 17 00:00:00 2001 From: Rodolfo Olivieri Date: Fri, 3 Jan 2025 15:59:41 -0300 Subject: [PATCH 2/3] Add manpages to data/release/man --- .packit.yaml | 8 +------- packaging/command-line-assistant.spec | 10 +++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.packit.yaml b/.packit.yaml index 97b92a2..045a7a8 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -3,11 +3,7 @@ upstream_package_name: command-line-assistant downstream_package_name: command-line-assistant upstream_project_url: https://github.com/rhel-lightspeed/command-line-assistant -srpm_build_deps: - - python3-pip - - python3-dasbus - - python3-requests - - make +srpm_build_deps: [] jobs: # Build RPMs for each pull request @@ -21,8 +17,6 @@ jobs: - epel-9-aarch64 - epel-10-aarch64 actions: - post-upstream-clone: - - bash -c "cd docs; pip install -r requirements.txt; SPHINXBUILD=/builddir/.local/bin/sphinx-build make man" # do not get the version from a tag (git describe) but from the spec file get-current-version: - grep -oP '^Version:\s+\K\S+' packaging/command-line-assistant.spec diff --git a/packaging/command-line-assistant.spec b/packaging/command-line-assistant.spec index f5a4afd..6ccdf59 100644 --- a/packaging/command-line-assistant.spec +++ b/packaging/command-line-assistant.spec @@ -64,27 +64,22 @@ A simple wrapper to interact with RAG %{__install} -D -m 0644 data/release/xdg/config.toml %{buildroot}/%{_sysconfdir}/xdg/%{python_package_src}/config.toml # History file -<<<<<<< HEAD %{__install} -D -m 0644 data/release/xdg/history.json %{buildroot}/%{_sharedstatedir}/%{name}/history.json # Manpages %{__install} -D -m 0644 data/release/man/%{binary_name}.1 %{buildroot}/%{_mandir}/man1/%{binary_name}.1 %{__install} -D -m 0644 data/release/man/%{daemon_binary_name}.8 %{buildroot}/%{_mandir}/man8/%{daemon_binary_name}.8 -======= + ## Create the folder under /var/lib/command-line-assistant %{__install} -d %{buildroot}/%{_sharedstatedir}/%{name} + ## Place the history file there %{__install} -D -m 0644 data/release/xdg/history.json %{buildroot}/%{_sharedstatedir}/%{name}/history.json # Manpages -## Create directories for man1 and man8 -%{__install} -d -m 755 %{buildroot}%{_mandir}/man1 -%{__install} -d -m 755 %{buildroot}%{_mandir}/man8 - # Install the man1 and man8 for cla(d) %{__install} -p docs/build/man/%{binary_name}.1 %{buildroot}%{_mandir}/man1/%{binary_name}.1 %{__install} -p docs/build/man/%{daemon_binary_name}.8 %{buildroot}%{_mandir}/man8/%{daemon_binary_name}.8 ->>>>>>> 119a35b (Generate manpages for CLA and CLAD) %post %systemd_post %{daemon_binary_name}.service @@ -127,4 +122,5 @@ LICENSE %{_mandir}/man1/%{binary_name}.1.gz %{_mandir}/man8/%{daemon_binary_name}.8.gz + %changelog From f7c74ca6700ec3ec13360aa59a83d1f4de1d2a78 Mon Sep 17 00:00:00 2001 From: Rodolfo Olivieri Date: Fri, 3 Jan 2025 17:58:58 -0300 Subject: [PATCH 3/3] Prevent binary files from being sent to the server --- command_line_assistant/initialize.py | 17 ++++++++++++++++- packaging/command-line-assistant.spec | 12 ------------ tests/test_initialize.py | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/command_line_assistant/initialize.py b/command_line_assistant/initialize.py index 7bd6b91..35adce1 100644 --- a/command_line_assistant/initialize.py +++ b/command_line_assistant/initialize.py @@ -4,6 +4,9 @@ from argparse import ArgumentParser, Namespace from command_line_assistant.commands import history, query, record +from command_line_assistant.rendering.decorators.colors import ColorDecorator +from command_line_assistant.rendering.decorators.text import EmojiDecorator +from command_line_assistant.rendering.renders.text import TextRenderer from command_line_assistant.utils.cli import ( add_default_command, create_argument_parser, @@ -37,7 +40,19 @@ def initialize() -> int: """ parser = register_subcommands() - stdin = read_stdin() + stdin = None + try: + stdin = read_stdin() + except UnicodeDecodeError: + # Usually happens when the user try to cat a binary file and redirect that to us. + text_renderer = TextRenderer() + text_renderer.update(ColorDecorator(foreground="red")) + text_renderer.update(EmojiDecorator(emoji="U+1F641")) + text_renderer.render( + "The stdin provided could not be decoded. Please, make sure it is in textual format." + ) + return 1 + args = add_default_command(stdin, sys.argv) # Small workaround to include the stdin in the namespace object in case it exists. diff --git a/packaging/command-line-assistant.spec b/packaging/command-line-assistant.spec index 6ccdf59..e0f42d7 100644 --- a/packaging/command-line-assistant.spec +++ b/packaging/command-line-assistant.spec @@ -70,17 +70,6 @@ A simple wrapper to interact with RAG %{__install} -D -m 0644 data/release/man/%{binary_name}.1 %{buildroot}/%{_mandir}/man1/%{binary_name}.1 %{__install} -D -m 0644 data/release/man/%{daemon_binary_name}.8 %{buildroot}/%{_mandir}/man8/%{daemon_binary_name}.8 -## Create the folder under /var/lib/command-line-assistant -%{__install} -d %{buildroot}/%{_sharedstatedir}/%{name} - -## Place the history file there -%{__install} -D -m 0644 data/release/xdg/history.json %{buildroot}/%{_sharedstatedir}/%{name}/history.json - -# Manpages -# Install the man1 and man8 for cla(d) -%{__install} -p docs/build/man/%{binary_name}.1 %{buildroot}%{_mandir}/man1/%{binary_name}.1 -%{__install} -p docs/build/man/%{daemon_binary_name}.8 %{buildroot}%{_mandir}/man8/%{daemon_binary_name}.8 - %post %systemd_post %{daemon_binary_name}.service @@ -122,5 +111,4 @@ LICENSE %{_mandir}/man1/%{binary_name}.1.gz %{_mandir}/man8/%{daemon_binary_name}.8.gz - %changelog diff --git a/tests/test_initialize.py b/tests/test_initialize.py index 437ec97..781635e 100644 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -116,6 +116,20 @@ def test_initialize_with_help(capsys): assert "usage:" in captured.out +def test_initialize_bad_stdin(capsys): + with patch("command_line_assistant.initialize.read_stdin") as mock_stdin: + mock_stdin.side_effect = UnicodeDecodeError( + "utf-8", b"", 0, 1, "invalid start byte" + ) + initialize() + + captured = capsys.readouterr() + assert ( + "The stdin provided could not be decoded. Please, make sure it is in textual format." + in captured.out + ) + + @pytest.mark.parametrize( ( "argv",