created migration code which is used to migrate data after an update

moved version code to constants so that code can access it too
changed Install/Remove Chalutier to FIshyQR in options
This commit is contained in:
Adam Saudagar 2021-11-21 16:30:41 +05:30
parent 8ae46dd5a5
commit 9f0974abb3
8 changed files with 78 additions and 27 deletions

View File

@ -1,2 +1,4 @@
from fishy import constants
from fishy.__main__ import main
__version__ = "0.5.2"
__version__ = constants.version

View File

@ -9,13 +9,14 @@ import win32gui
import fishy
from fishy import gui, helper, web
from fishy.constants import chalutier, lam2
from fishy.constants import chalutier, lam2, fishyqr, libgps
from fishy.engine.common.event_handler import EngineEventHandler
from fishy.gui import GUI, splash, update_dialog
from fishy.helper import hotkey
from fishy.helper.active_poll import active
from fishy.helper.config import config
from fishy.helper.hotkey.hotkey_process import hotkey
from fishy.helper.migration import Migration
def check_window_name(title):
@ -28,6 +29,8 @@ def check_window_name(title):
# noinspection PyBroadException
def initialize(window_to_hide):
Migration.migrate()
helper.create_shortcut_first()
helper.initialize_uid()
@ -62,10 +65,7 @@ def initialize(window_to_hide):
helper.install_thread_excepthook()
sys.excepthook = helper.unhandled_exception_logging
if not config.get("addoninstalled", 0) or helper.get_addonversion(chalutier[0]) < chalutier[2]:
helper.install_addon(*chalutier)
helper.install_addon(*lam2)
config.set("addoninstalled", helper.get_addonversion(chalutier[0]))
helper.install_required_addons()
def main():

View File

@ -1,6 +1,11 @@
apiversion = 2
chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/Chalutier_1.1.4.zip", 114)
lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32)
fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/6329586/FishyQR.zip", 100)
# removed since 0.5.3
chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/Chalutier_1.1.4.zip", 114)
# addons used
lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32)
fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/7575974/FishyQR.zip", 101)
libgps = ("LibGPS", "https://cdn.esoui.com/downloads/file601/LibGPS_3_0_3.zip", 30)
version = "0.5.3"

View File

@ -46,12 +46,6 @@ class FullAuto(IEngine):
self.mode = None
def run(self):
addons_req = [libgps, lam2, fishyqr]
for addon in addons_req:
if not helper.addon_exists(*addon):
helper.install_addon(*addon)
self.gui.bot_started(True)
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")

View File

@ -9,7 +9,7 @@ from ttkthemes import ThemedTk
from fishy import helper
from fishy.web import web
from ..constants import chalutier, lam2
from ..constants import chalutier, lam2, fishyqr
from ..helper.config import config
from .discord_login import discord_login
from ..helper.hotkey.hotkey_process import hotkey
@ -59,15 +59,13 @@ def _create(gui: 'GUI'):
filemenu.add_command(label="Update", command=helper.update)
def installer():
if filemenu.entrycget(4, 'label') == "Remove Chalutier":
if helper.remove_addon(chalutier[0]) == 0:
filemenu.entryconfigure(4, label="Install Chalutier")
if filemenu.entrycget(4, 'label') == "Remove FishyQR":
if helper.remove_addon(fishyqr[0]) == 0:
filemenu.entryconfigure(4, label="Install FishyQR")
else:
r = helper.install_addon(*chalutier)
r += helper.install_addon(*lam2)
if r == 0:
filemenu.entryconfigure(4, label="Remove Chalutier")
chaEntry = "Remove Chalutier" if helper.addon_exists(chalutier[0]) else "Install Chalutier"
helper.install_required_addons(True)
filemenu.entryconfigure(4, label="Remove FishyQR")
chaEntry = "Remove FishyQR" if helper.addon_exists(fishyqr[0]) else "Install FishyQR"
filemenu.add_command(label=chaEntry, command=installer)
menubar.add_cascade(label="Options", menu=filemenu)

View File

@ -5,5 +5,5 @@ from .helper import (addon_exists, create_shortcut, create_shortcut_first,
install_addon, install_thread_excepthook, manifest_file,
not_implemented, open_web, playsound_multiple,
remove_addon, restart, unhandled_exception_logging,
update)
update, install_required_addons)
from .luaparser import sv_color_extract

View File

@ -22,6 +22,8 @@ from win32gui import GetForegroundWindow, GetWindowText
import fishy
from fishy import web
from fishy.constants import libgps, lam2, fishyqr
from fishy.helper.config import config
def playsound_multiple(path, count=2):
@ -190,17 +192,34 @@ def get_addonversion(name, url=None, v=None):
return 0
def install_required_addons(force=False):
addons_req = [libgps, lam2, fishyqr]
addon_version = config.get("addon_version", {})
installed = False
for addon in addons_req:
if force or (addon_exists(*addon) and
(addon[0] not in addon_version or (
addon[0] in addon_version and addon_version[addon[0]] < addon[2]))):
remove_addon(*addon)
install_addon(*addon)
addon_version[addon[0]] = addon[2]
installed = True
config.set("addon_version", addon_version)
if installed:
logging.info("Please make sure to enable \"Allow outdated addons\" in ESO")
# noinspection PyBroadException
def install_addon(name, url, v=None):
try:
r = requests.get(url, stream=True)
z = ZipFile(BytesIO(r.content))
z.extractall(path=get_addondir())
logging.info("Add-On " + name +
" installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO")
logging.info("Add-On " + name + " installed successfully!")
return 0
except Exception:
logging.error("Could not install Add-On " + name + ", try doing it manually")
traceback.print_exc()
return 1

33
fishy/helper/migration.py Normal file
View File

@ -0,0 +1,33 @@
import logging
from fishy.helper.auto_update import _normalize_version
from fishy.constants import chalutier, version
from fishy.helper import helper
from .config import config
class Migration:
@staticmethod
def up_to_0_5_3():
helper.remove_addon(*chalutier)
config.delete("addoninstalled")
@staticmethod
def migrate():
prev_version = _normalize_version(config.get("prev_version", "0.0.0"))
current_version = _normalize_version(version)
if current_version > prev_version:
for v, f in migration_code:
if prev_version < _normalize_version(v) <= current_version:
logging.info(f"running migration for {v}")
f()
config.set("prev_version", version)
migration_code = [
# version, upgrade_code
("0.5.3", Migration.up_to_0_5_3)
]