]> Nutra Git (v1) - nutratech/cli.git/commitdiff
wip bug report
authorShane Jaroch <chown_tee@proton.me>
Tue, 13 Feb 2024 19:31:37 +0000 (14:31 -0500)
committerShane Jaroch <chown_tee@proton.me>
Tue, 13 Feb 2024 19:36:17 +0000 (14:36 -0500)
ntclient/__main__.py
ntclient/ntsqlite
ntclient/services/api/__init__.py [copied from ntclient/services/bugs.py with 66% similarity]
ntclient/services/api/funcs.py [new file with mode: 0644]
ntclient/services/bugs.py
ntclient/utils/__init__.py
ntclient/utils/sql.py [new file with mode: 0644]

index 6de1e07e6d2c6ed2b70777da2c208c6ddd17d2de..0d48b651be4dea3d56a11a9af5637736775a32d7 100644 (file)
@@ -23,8 +23,9 @@ from ntclient import (
     __version__,
 )
 from ntclient.argparser import build_subcommands
-from ntclient.utils import CLI_CONFIG, handle_runtime_exception
+from ntclient.utils import CLI_CONFIG
 from ntclient.utils.exceptions import SqlException
+from ntclient.utils.sql import handle_runtime_exception
 
 
 def build_arg_parser() -> argparse.ArgumentParser:
@@ -101,19 +102,19 @@ def main(args: list = None) -> int:  # type: ignore
         exit_code, *_results = func(_parser)
     except SqlException as sql_exception:  # pragma: no cover
         print("Issue with an sqlite database: " + repr(sql_exception))
-        handle_runtime_exception(sql_exception)
+        handle_runtime_exception(args, sql_exception)
     except HTTPError as http_error:  # pragma: no cover
         err_msg = "{0}: {1}".format(http_error.code, repr(http_error))
         print("Server response error, try again: " + err_msg)
-        handle_runtime_exception(http_error)
+        handle_runtime_exception(args, http_error)
     except URLError as url_error:  # pragma: no cover
         print("Connection error, check your internet: " + repr(url_error.reason))
-        handle_runtime_exception(url_error)
+        handle_runtime_exception(args, url_error)
     except Exception as exception:  # pylint: disable=broad-except  # pragma: no cover
         print("Unforeseen error, run with --debug for more info: " + repr(exception))
         print("You can open an issue here: %s" % __url__)
         print("Or send me an email with the debug output: %s" % __email__)
-        handle_runtime_exception(exception)
+        handle_runtime_exception(args, exception)
     finally:
         if CLI_CONFIG.debug:
             exc_time = time.time() - start_time
index 939f55077b97bd1fe1c8e2b897b032dbc1564487..c5c64d3371a5f1e5c600989e79563c5827486224 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 939f55077b97bd1fe1c8e2b897b032dbc1564487
+Subproject commit c5c64d3371a5f1e5c600989e79563c5827486224
similarity index 66%
copy from ntclient/services/bugs.py
copy to ntclient/services/api/__init__.py
index b29e6c10e2b0622eff3eee9a4fe4d6ffb16238db..83fe132786bb84332f65c0f754d88da9e7800bb4 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 """
-Created on Tue Feb 13 09:51:48 2024
+Created on Tue Feb 13 14:28:20 2024
 
 @author: shane
 """
diff --git a/ntclient/services/api/funcs.py b/ntclient/services/api/funcs.py
new file mode 100644 (file)
index 0000000..c955dd0
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Tue Feb 13 14:28:44 2024
+
+@author: shane
+"""
+
+
+def post_bug(bug: tuple) -> None:
+    """Post a bug report to the developer."""
+    print("posting bug report...")
index b29e6c10e2b0622eff3eee9a4fe4d6ffb16238db..efd99c71d6c1bd219c559666dab2086dc4dac8f6 100644 (file)
@@ -5,3 +5,45 @@ Created on Tue Feb 13 09:51:48 2024
 
 @author: shane
 """
+import os
+import traceback
+
+import ntclient.services.api.funcs
+from ntclient.persistence.sql.nt import sql as sql_nt
+
+
+def insert(args: list, exception: Exception) -> None:
+    """Insert bug report into nt.sqlite3, return True/False."""
+    print("inserting bug reports...", end="")
+    sql_nt(
+        """
+INSERT INTO bug
+  (profile_id, arguments, repr, stack, client_info, app_info, user_details)
+  VALUES
+    (?,?,?,?,?,?,?)
+        """,
+        (
+            1,
+            " ".join(args),
+            repr(exception),
+            os.linesep.join(traceback.format_tb(exception.__traceback__)),
+            "client_info",
+            "app_info",
+            "user_details",
+        ),
+    )
+
+
+def submit() -> int:
+    """Submit bug reports to developer, return n_submitted."""
+    n_submitted = 0
+    sql_bugs = sql_nt("SELECT * FROM bug WHERE submitted = 0")
+    print(f"submitting {len(sql_bugs)} bug reports...")
+    for bug in sql_bugs:
+        # print(", ".join(str(x) for x in bug))
+        ntclient.services.api.funcs.post_bug(bug)
+        n_submitted += 1
+    # 1 / 0  # force exception
+    # raise Exception("submitting bug reports failed")
+
+    return n_submitted
index f5fc7b0c89f12289d4da9c5b5335af2efb14a9c7..042f66f2ebe8a772d00c34b14f36fc957f8c460b 100644 (file)
@@ -150,12 +150,3 @@ def activity_factor_from_index(activity_factor: int) -> float:
     raise ValueError(  # pragma: no cover
         "No such ActivityFactor for value: %s" % activity_factor
     )
-
-
-def handle_runtime_exception(exception: Exception) -> None:
-    """
-    Handles exceptions raised during runtime.
-    """
-    print("Exception: %s" % exception)
-    if CLI_CONFIG.debug:
-        raise exception
diff --git a/ntclient/utils/sql.py b/ntclient/utils/sql.py
new file mode 100644 (file)
index 0000000..2c3a151
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Tue Feb 13 14:15:21 2024
+
+@author: shane
+"""
+from ntclient.services.bugs import insert as bug_insert
+from ntclient.utils import CLI_CONFIG
+
+
+def handle_runtime_exception(args: list, exception: Exception) -> None:
+    """
+    Handles exceptions raised during runtime.
+    """
+    print("Exception: %s" % exception)
+    if CLI_CONFIG.debug:
+        bug_insert(args, exception)
+        raise exception