Skip to content

Commit

Permalink
improvements to update checking!
Browse files Browse the repository at this point in the history
  • Loading branch information
PycraftDeveloper committed Dec 25, 2024
1 parent 81407d4 commit 958beb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ def _up(path: str) -> str:
from pmma.python_src.utility import cython_utils as _cython_utils
import pmma.python_src.utility.general_utils as _general_utils
from pmma.python_src.utility.logging_utils import InternalLogger as _InternalLogger
from pmma.python_src.utility.pmma_configuration import load_configuration
from pmma.python_src.utility.pmma_configuration import load_configuration, save_configuration

load_configuration()

if (_Registry.last_checked_for_updates is None or _general_utils.get_date_as_number()-_Registry.last_checked_for_updates > 7 or _Registry.update_available is None):
_Registry.last_checked_for_updates = _general_utils.get_date_as_number()
_general_utils.check_for_updates()

def init(
Expand Down
3 changes: 3 additions & 0 deletions experiments/startup test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pmma

pmma.init()
17 changes: 14 additions & 3 deletions python_src/utility/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,29 @@
if _platform__system() == "Windows":
from ctypes import windll as _ctypes__windll

def pad_numerical_string(input_string):
return "0"*(8-len(input_string)) + input_string

def check_for_updates():
if get_date_as_number()-_Registry.last_checked_for_updates > 1 or _Registry.update_available is None:
if _Registry.last_checked_for_updates is None or get_date_as_number()-_Registry.last_checked_for_updates > 1 or _Registry.update_available is None:
_Registry.last_checked_for_updates = get_date_as_number()

tag_data = _requests__get("https://api.github.com/repos/PycraftDeveloper/PMMA/tags")
latest_tag = _loads__loads(tag_data.text)[0]["name"]

split_current_version = _Registry.version.split(".")
current_version_as_integer = int(split_current_version[0] + split_current_version[1] + split_current_version[2])
current_version_as_integer = int(
"1"+
pad_numerical_string(split_current_version[0]) +
pad_numerical_string(split_current_version[1]) +
pad_numerical_string(split_current_version[2]))

split_latest_version = latest_tag.split(".")
latest_version_as_integer = int(split_latest_version[0] + split_latest_version[1] + split_latest_version[2])
latest_version_as_integer = int(
"1"+
pad_numerical_string(split_latest_version[0]) +
pad_numerical_string(split_latest_version[1]) +
pad_numerical_string(split_latest_version[2]))

_Registry.update_available = latest_version_as_integer > current_version_as_integer

Expand Down

0 comments on commit 958beb8

Please sign in to comment.