built in updater i think
This commit is contained in:
parent
fd76a7703d
commit
828750ea8d
2 changed files with 25 additions and 2 deletions
|
@ -34,6 +34,7 @@ MEMORY_FILE = "memory.json"
|
||||||
DEFAULT_DATASET_FILE = "defaultdataset.json"
|
DEFAULT_DATASET_FILE = "defaultdataset.json"
|
||||||
MEMORY_LOADED_FILE = "MEMORY_LOADED"
|
MEMORY_LOADED_FILE = "MEMORY_LOADED"
|
||||||
ALIVEPING = os.getenv("ALIVEPING")
|
ALIVEPING = os.getenv("ALIVEPING")
|
||||||
|
AUTOUPDATE = os.getenv("AUTOUPDATE")
|
||||||
IGNOREWARNING = False
|
IGNOREWARNING = False
|
||||||
song = os.getenv("song")
|
song = os.getenv("song")
|
||||||
arch = platform.machine()
|
arch = platform.machine()
|
||||||
|
|
|
@ -3,6 +3,26 @@ from modules.translations import *
|
||||||
from modules.globalvars import *
|
from modules.globalvars import *
|
||||||
import traceback
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def run_cmd(cmd):
|
||||||
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||||
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
def is_remote_ahead(branch='main', remote='origin'):
|
||||||
|
run_cmd(f'git fetch {remote}')
|
||||||
|
count = run_cmd(f'git rev-list --count HEAD..{remote}/{branch}')
|
||||||
|
return int(count) > 0
|
||||||
|
|
||||||
|
def auto_update(branch='main', remote='origin'):
|
||||||
|
if AUTOUPDATE != "True":
|
||||||
|
pass
|
||||||
|
if is_remote_ahead(branch, remote):
|
||||||
|
print(f"Remote {remote}/{branch} is ahead. Updating...")
|
||||||
|
pull_result = run_cmd(f'git pull {remote} {branch}')
|
||||||
|
print(pull_result)
|
||||||
|
else:
|
||||||
|
print(f"Local {remote}/{branch} is ahead. Not Updating...")
|
||||||
|
|
||||||
def generate_sha256_of_current_file():
|
def generate_sha256_of_current_file():
|
||||||
global currenthash
|
global currenthash
|
||||||
|
@ -27,8 +47,8 @@ def get_latest_version_info():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def check_for_update():
|
def check_for_update():
|
||||||
if ALIVEPING == "false":
|
if ALIVEPING != "True":
|
||||||
return
|
pass
|
||||||
global latest_version, local_version
|
global latest_version, local_version
|
||||||
|
|
||||||
latest_version_info = get_latest_version_info()
|
latest_version_info = get_latest_version_info()
|
||||||
|
@ -53,6 +73,8 @@ def check_for_update():
|
||||||
if local_version < latest_version:
|
if local_version < latest_version:
|
||||||
print(f"{YELLOW}{get_translation(LOCALE, 'new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
|
print(f"{YELLOW}{get_translation(LOCALE, 'new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
|
||||||
print(f"{YELLOW}{get_translation(LOCALE, 'changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
|
print(f"{YELLOW}{get_translation(LOCALE, 'changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
|
||||||
|
auto_update()
|
||||||
|
|
||||||
|
|
||||||
elif local_version == latest_version:
|
elif local_version == latest_version:
|
||||||
print(f"{GREEN}{get_translation(LOCALE, 'latest_version')} {local_version}{RESET}")
|
print(f"{GREEN}{get_translation(LOCALE, 'latest_version')} {local_version}{RESET}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue