From 0b47a987718f092f8c06e605c1f48659340f60e4 Mon Sep 17 00:00:00 2001 From: eliranwong Date: Wed, 6 Nov 2024 16:39:33 +0000 Subject: [PATCH] add api-client --- setup.py | 2 +- uniquebible/__init__.py | 38 +++++++++++++++++++--------------- uniquebible/db/BiblesSqlite.py | 2 +- uniquebible/latest_changes.txt | 10 +++++++++ uniquebible/startup/nonGui.py | 6 +++--- uniquebible/util/ConfigUtil.py | 4 ++++ 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index 3b9fd3ff7..2025f94ae 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ # https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/ setup( name=package, - version="0.1.59", + version="0.1.64", python_requires=">=3.8, <3.13", description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng", long_description=long_description, diff --git a/uniquebible/__init__.py b/uniquebible/__init__.py index 1e4d1c602..df733dbd5 100644 --- a/uniquebible/__init__.py +++ b/uniquebible/__init__.py @@ -89,26 +89,30 @@ def isServerAlive(ip, port): except socket.error: return False -if isServerAlive("8.8.8.8", 53): +if hasattr(config, "checkVersionOnStartup") and config.checkVersionOnStartup: - thisPackage = "uniquebible" + if isServerAlive("8.8.8.8", 53): - print(f"Checking '{thisPackage}' version ...") + thisPackage = "uniquebible" - config.version = installed_version = getPackageInstalledVersion(thisPackage) - if installed_version is None: - print("Installed version information is not accessible!") + content = [] + + content.append(f"# Checked '{thisPackage}' version ...") + + config.version = installed_version = getPackageInstalledVersion(thisPackage) + if installed_version is not None: + content.append(f"Installed version: {installed_version}") + latest_version = getPackageLatestVersion(thisPackage) + if latest_version is not None: + content.append(f"Latest version: {latest_version}") + if latest_version > installed_version: + content.append("Run `pip install --upgrade uniquebible` to upgrade!") + print("\n".join(content)) + + config.internetConnectivity = True else: - print(f"Installed version: {installed_version}") - latest_version = getPackageLatestVersion(thisPackage) - if latest_version is None: - print("Latest version information is not accessible at the moment!") - elif installed_version is not None: - print(f"Latest version: {latest_version}") - if latest_version > installed_version: - print("Run `pip install --upgrade uniquebible` to upgrade!") - - config.internetConnectivity = True + config.internetConnectivity = False + config.version = "0.0.0" + else: - config.internetConnectivity = False config.version = "0.0.0" \ No newline at end of file diff --git a/uniquebible/db/BiblesSqlite.py b/uniquebible/db/BiblesSqlite.py index 820ac4381..21a605071 100644 --- a/uniquebible/db/BiblesSqlite.py +++ b/uniquebible/db/BiblesSqlite.py @@ -869,7 +869,7 @@ def __init__(self, text=None): self.connection = None self.cursor = None self.database = os.path.join(config.marvelData, "bibles", text+".bible") - if os.path.exists(self.database): + if os.path.isfile(self.database): self.connection = apsw.Connection(self.database) self.connection.createscalarfunction("REGEXP", TextUtil.regexp) self.cursor = self.connection.cursor() diff --git a/uniquebible/latest_changes.txt b/uniquebible/latest_changes.txt index 844270dde..ab14806a7 100755 --- a/uniquebible/latest_changes.txt +++ b/uniquebible/latest_changes.txt @@ -1,5 +1,15 @@ PIP package: +0.1.60-0.1.61 + +* version message displayed on console only if newer version is available. + +0.1.58-0.1.59 + +* added commands `ub`, `ubapi`, `ubhttp`, `ubssh`, `ubtelnet` and `ubterm`. Read https://github.com/eliranwong/UniqueBible/wiki/UBA-Run-Modes + +* added `api-client` mode + 0.1.54-0.1.57 * added bible parameter to commands `crossreference` and `tske`. diff --git a/uniquebible/startup/nonGui.py b/uniquebible/startup/nonGui.py index 6220774bb..5097da324 100755 --- a/uniquebible/startup/nonGui.py +++ b/uniquebible/startup/nonGui.py @@ -100,7 +100,7 @@ def checkCommand(command): def run_terminal_mode(): from uniquebible.util.LocalCliHandler import LocalCliHandler from uniquebible.util.prompt_shared_key_bindings import prompt_shared_key_bindings - from uniquebible.util.uba_command_prompt_key_bindings import api_command_prompt_key_bindings + from uniquebible.util.uba_command_prompt_key_bindings import uba_command_prompt_key_bindings from prompt_toolkit.key_binding import merge_key_bindings from prompt_toolkit.shortcuts import set_title, clear_title from prompt_toolkit.auto_suggest import AutoSuggestFromHistory @@ -123,12 +123,12 @@ def run_terminal_mode(): config.terminalCommandDefault = "" default = "" # make key bindings available in config to allow futher customisation via plugins - config.key_bindings = uba_command_prompt_key_bindings + #config.key_bindings = uba_command_prompt_key_bindings # run plugin where users may add customised key bindings runStartupPlugins() config.key_bindings = merge_key_bindings([ prompt_shared_key_bindings, - config.key_bindings, + uba_command_prompt_key_bindings, ]) # make sure user-customised menu contains valid item only. # validation can only be running after, not before, running startup plugin, as some startup plugin works on command shortcuts. diff --git a/uniquebible/util/ConfigUtil.py b/uniquebible/util/ConfigUtil.py index 0bf1cfd29..32c8f254f 100644 --- a/uniquebible/util/ConfigUtil.py +++ b/uniquebible/util/ConfigUtil.py @@ -168,6 +168,10 @@ def getCurrentVenvDir(): # Use PySide6 as Qt Library, even config.qtLibrary is set to a value other than 'pyside6'.""", False) + setConfig("checkVersionOnStartup", """ + # Check installed and latest versions on startup.""", + True) + # Start of api-client mode setting setConfig("web_api_endpoint", """ # UniqueBible App web API endpoint.""",