Skip to content

Commit

Permalink
bug submission MVP. wip configparser
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesguru committed Feb 15, 2024
1 parent 458ffc7 commit 1b9dca7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 47 deletions.
9 changes: 7 additions & 2 deletions ntclient/persistence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
@author: shane
"""
import configparser
import os

from ntclient import NUTRA_HOME

# TODO: create and maintain prefs.json file? See if there's a library for that, lol

PREFS_JSON = os.path.join(NUTRA_HOME, "prefs.json")
PREFS_FILE = os.path.join(NUTRA_HOME, "prefs.ini")

# if
if not os.path.exists(PREFS_FILE):
print("INFO: Generating prefs.ini file")
config = configparser.ConfigParser()
with open(PREFS_FILE, "w", encoding="utf-8") as _prefs_file:
config.write(_prefs_file)
29 changes: 24 additions & 5 deletions ntclient/services/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,33 @@
)


def cache_mirrors() -> str:
"""Cache mirrors"""
for mirror in URLS_API:
try:
_res = requests.get(
mirror,
timeout=(REQUEST_CONNECT_TIMEOUT, REQUEST_READ_TIMEOUT),
verify=mirror.startswith("https://"),
)

_res.raise_for_status()
# TODO: save in persistence config.ini
print(f"INFO: mirror SUCCESS '{mirror}'")
return mirror
except requests.exceptions.ConnectionError:
print(f"WARN: mirror FAILURE '{mirror}'")

return str()


class ApiClient:
"""Client for connecting to the remote server/API."""

def __init__(
self,
host: str = URLS_API[0],
):
self.host = host
def __init__(self) -> None:
self.host = cache_mirrors()
if not self.host:
raise ConnectionError("Cannot find suitable API host!")

def get(self, path: str) -> requests.Response:
"""Get data from the API."""
Expand Down
34 changes: 0 additions & 34 deletions ntclient/services/api/mirrorcache.py

This file was deleted.

6 changes: 0 additions & 6 deletions ntclient/services/bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import ntclient.services.api
from ntclient.persistence.sql.nt import sql as sql_nt
from ntclient.services.api.mirrorcache import cache_mirrors


def insert(args: list, exception: Exception) -> None:
Expand Down Expand Up @@ -53,11 +52,6 @@ def list_bugs() -> list:

def submit_bugs() -> int:
"""Submit bug reports to developer, return n_submitted."""
# Probe mirrors, cache best working one
is_mirror_alive = cache_mirrors()
if not is_mirror_alive:
print("ERROR: we couldn't find an active mirror, can't submit bugs.")
return -1

# Gather bugs for submission
sql_bugs = sql_nt("SELECT * FROM bug WHERE submitted = 0")
Expand Down

0 comments on commit 1b9dca7

Please sign in to comment.