mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
move updater to own module
This commit is contained in:
36
ModuleUpdate.py
Normal file
36
ModuleUpdate.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import importlib
|
||||
|
||||
update_ran = False
|
||||
|
||||
def update_command():
|
||||
subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt', '--upgrade'])
|
||||
|
||||
def update():
|
||||
global update_ran
|
||||
if not update_ran:
|
||||
update_ran = True
|
||||
with open('requirements.txt') as requirementsfile:
|
||||
for line in requirementsfile.readlines():
|
||||
module, remoteversion = line.split(">=")
|
||||
try:
|
||||
module = importlib.import_module(module)
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
input(f'Required python module {module} not found, press enter to install it')
|
||||
update_command()
|
||||
else:
|
||||
if hasattr(module, "__version__"):
|
||||
module_version = module.__version__
|
||||
module = module.__name__ #also unloads the module to make it writable
|
||||
if type(module_version) == str:
|
||||
module_version = tuple(int(part.strip()) for part in module_version.split("."))
|
||||
remoteversion = tuple(int(part.strip()) for part in remoteversion.split("."))
|
||||
if module_version < remoteversion:
|
||||
input(f'Required python module {module} is outdated ({module_version}<{remoteversion}), press enter to upgrade it')
|
||||
update_command()
|
||||
|
||||
if __name__ == "__main__":
|
||||
update()
|
Reference in New Issue
Block a user