From 6e89e9b59b77daa7314d8e70be61c86c434d1fda Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Wed, 6 Apr 2022 20:06:45 +0200 Subject: [PATCH] =?UTF-8?q?[mod]=20#426:=20Drop=20=C4=9E1=20monetary=20lic?= =?UTF-8?q?ense=20display=20in=20a=20browser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It doesn’t makes sense to keep displaying outdated license From the console display of files, there is six languages versus two from websites Less code means less maintenance --- silkaj/cli.py | 9 --------- silkaj/license.py | 33 ++++++--------------------------- tests/test_license.py | 38 -------------------------------------- 3 files changed, 6 insertions(+), 74 deletions(-) diff --git a/silkaj/cli.py b/silkaj/cli.py index e7455f0c..405c063f 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -87,13 +87,6 @@ from silkaj.wot import id_pubkey_correspondence, received_sent_certifications help="By-pass licence, confirmation. \ Do not send the document, but display it instead", ) -@option( - "--g1-license-web", - "-w", - is_flag=True, - help="Display Ğ1 monetary license in a web browser if not running on a headless system. \ -Defaults to terminal display.", -) @pass_context def cli( ctx, @@ -107,7 +100,6 @@ def cli( auth_wif, display, dry_run, - g1_license_web, ): if display and dry_run: sys.exit("ERROR: display and dry-run options can not be used together") @@ -124,7 +116,6 @@ def cli( ctx.obj["AUTH_WIF"] = auth_wif ctx.obj["DISPLAY_DOCUMENT"] = display ctx.obj["DRY_RUN"] = dry_run - ctx.obj["G1_LICENSE_WEB"] = g1_license_web cli.add_command(argos_info) diff --git a/silkaj/license.py b/silkaj/license.py index baee1f8a..00c318d4 100644 --- a/silkaj/license.py +++ b/silkaj/license.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import webbrowser from pathlib import Path from typing import List @@ -22,11 +21,6 @@ import g1_monetary_license as gml languages = ["es", "en", "eo", "it", "fr", "pt"] -licenses_urls = { - "en": "https://duniter.org/en/wiki/g1-license/", - "fr": "https://duniter.fr/wiki/g1/licence-txt/", -} - def license_approval(currency: str) -> None: if currency != "g1": @@ -43,29 +37,14 @@ def license_command() -> None: display_license() -@click.pass_context -def display_license(ctx) -> None: +def display_license() -> None: """ - Display in web browser if flag set and not headless system - Otherwise, display in the terminal + Display license in the terminal """ - if ctx.obj["G1_LICENSE_WEB"] and has_web_browser(): - languages_choices = list(licenses_urls.keys()) - language = language_prompt(languages_choices) - webbrowser.open(licenses_urls[language]) - else: - language = language_prompt(languages) - path = license_path(language) - with open(path) as license: - click.echo_via_pager(license.read()) - - -def has_web_browser() -> bool: - try: - webbrowser.get() - return True - except webbrowser.Error: - return False + language = language_prompt(languages) + path = license_path(language) + with open(path) as license: + click.echo_via_pager(license.read()) def language_prompt(languages_choices: List) -> str: diff --git a/tests/test_license.py b/tests/test_license.py index 91924ea7..b1b72d83 100644 --- a/tests/test_license.py +++ b/tests/test_license.py @@ -13,8 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import webbrowser -from pathlib import Path from unittest.mock import patch import pytest @@ -50,42 +48,6 @@ def test_license_approval_g1(mock_display_license, mock_confirm, display, approv mock_confirm.assert_called() -@pytest.mark.parametrize( - "language, web, license_sample", - [ - ("en", False, "**Currency licensing"), - ("fr", False, "**Licence de la monnaie"), - ("en", True, "**Currency licensing"), - ("fr", True, "**Licence de la monnaie"), - ], -) -@patch("webbrowser.open") -def test_display_license(webbrowser_open, language, web, license_sample): - args = [] - if web: - args += ["--g1-license-web"] - args += ["license"] - - result = CliRunner().invoke(cli.cli, args=args, input=language) - assert "In which language" in result.output - if web and license.has_web_browser(): - webbrowser_open.assert_called_once_with(license.licenses_urls[language]) - else: - assert license_sample in result.output - assert result.exit_code == SUCCESS_EXIT_STATUS - - -def test_has_web_browser(): - """ - https://stackoverflow.com/a/50990039 - """ - with patch("webbrowser.get", side_effect=webbrowser.Error): - assert license.has_web_browser() == False - - with patch("webbrowser.get", side_effect=None): - assert license.has_web_browser() == True - - @pytest.mark.parametrize( "language, license_sample", [ -- GitLab