From db2f35cf0c123d7b449d3f70355e03b0a548902f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Ali=C3=A8s?= Date: Sun, 24 Jun 2018 15:17:10 +0200 Subject: [PATCH] clean up --- quail/controller/controller_console.py | 4 +-- quail/controller/controller_tkinter.py | 4 +-- quail/manager.py | 40 ++++++++++++++------------ quail/solution/solution_base.py | 10 +++---- quail/solution/solution_github.py | 2 +- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/quail/controller/controller_console.py b/quail/controller/controller_console.py index 65466ee..76bbab4 100644 --- a/quail/controller/controller_console.py +++ b/quail/controller/controller_console.py @@ -8,7 +8,7 @@ def progress_callback(progress): sys.stdout.write(" %d %% updating ...\r" % progress) sys.stdout.flush() - manager.set_solution_hook(progress_callback) + manager.set_solution_progress_hook(progress_callback) print("[*] New version available: %s" % manager.get_solution_version()) manager.update() print("[*] Update successful!") @@ -18,7 +18,7 @@ def progress_callback(progress): sys.stdout.write(" %d %% installing ...\r" % progress) sys.stdout.flush() - manager.set_solution_hook(progress_callback) + manager.set_solution_progress_hook(progress_callback) print("[*] Installing %s" % manager.get_name()) manager.install() print("[*] Installation successful!") diff --git a/quail/controller/controller_tkinter.py b/quail/controller/controller_tkinter.py index bee1a94..8f5837c 100644 --- a/quail/controller/controller_tkinter.py +++ b/quail/controller/controller_tkinter.py @@ -29,7 +29,7 @@ def __init__(self, parent, controller, manager): tk.Frame.__init__(self, parent) self.controller = controller self.manager = manager - manager.set_solution_hook(self.progress_callback) + manager.set_solution_progress_hook(self.progress_callback) manager.set_install_part_solution_hook(self.solution_finished_callback) label = tk.Label(self, text="Updating...", font=controller.title_font) @@ -59,7 +59,7 @@ def __init__(self, parent, controller, manager): tk.Frame.__init__(self, parent) self.controller = controller self.manager = manager - manager.set_solution_hook(self.progress_callback) + manager.set_solution_progress_hook(self.progress_callback) manager.set_install_part_register_hook(self.install_finished_callback) manager.set_install_part_solution_hook(self.solution_finished_callback) diff --git a/quail/manager.py b/quail/manager.py index b0eaeb8..e367839 100644 --- a/quail/manager.py +++ b/quail/manager.py @@ -24,10 +24,17 @@ def _chmod_binary(self): if not (stat.S_IXUSR & os.stat(binary)[stat.ST_MODE]): os.chmod(binary, 0o755) - def set_solution_hook(self, hook): + def _set_solution_installed_version(self): + version = self.get_solution_version() + if version is None: + return + with open(self._get_version_file_path(), "w") as f: + f.write(version) + + def set_solution_progress_hook(self, hook): """Set solution update progress hook """ - self._solution.set_hook(hook) + self._solution.set_progress_hook(hook) def set_install_part_solution_hook(self, hook): """Set install part 1 finished hook @@ -57,16 +64,11 @@ def build(self): raise AssertionError("Can't build from an executable") def get_solution_version(self): + """Get version from solution""" return self._solution.get_version_string() - def _set_solution_installed_version(self): - version = self.get_solution_version() - if version is None: - return - with open(self._get_version_file_path(), "w") as f: - f.write(version) - def get_installed_version(self): + """Get installed version""" if not os.path.isfile(self._get_version_file_path()): return None with open(self._get_version_file_path(), "r") as f: @@ -86,19 +88,13 @@ def install_part_solution(self): self._install_part_solution_hook() def install_part_register(self): - """part 1 of the installation will install the solution + """part 1 of the installation will register the solution """ self._installer.register() self._chmod_binary() if self._install_part_register_hook: self._install_part_register_hook() - def update(self): - self._solutioner.update() - self._set_solution_installed_version() - if self._install_part_solution_hook: - self._install_part_solution_hook() - def install(self): """Installation process was split in multiple parts to allow controller to choose if the installation part must be @@ -109,17 +105,25 @@ def install(self): self.install_part_solution() self.install_part_register() + def update(self): + """Update process""" + self._solutioner.update() + self._set_solution_installed_version() + if self._install_part_solution_hook: + self._install_part_solution_hook() + def uninstall(self): - """ Uninstall + """ Uninstall process """ self._solutioner.uninstall() self._installer.unregister() def is_installed(self): - # TODO: optimisation + """Check if solution is installed""" return self._solutioner.installed() # and self._installer.registered() def run(self): + """Run solution""" binary = self._installer.binary self._chmod_binary() os.system(binary + " " + " ".join(sys.argv[1:])) diff --git a/quail/solution/solution_base.py b/quail/solution/solution_base.py index b1431db..e138fc7 100644 --- a/quail/solution/solution_base.py +++ b/quail/solution/solution_base.py @@ -14,7 +14,7 @@ class SolutionBase(ABC, builder.BuilderAction): - over network """ def __init__(self): - self._hook = None + self._progress_hook = None def __enter__(self): self.open() @@ -23,17 +23,17 @@ def __enter__(self): def __exit__(self, type, value, traceback): self.close() - def set_hook(self, hook): + def set_progress_hook(self, hook): """set progression hook""" - self._hook = hook + self._progress_hook = hook def _update_progress(self, percent): """ This function will be called to update solution progression while downloading. It will call """ - if self._hook: - self._hook(percent) + if self._progress_hook: + self._progress_hook(percent) def get_version_string(self): """ return version string of a solution diff --git a/quail/solution/solution_github.py b/quail/solution/solution_github.py index dc534f7..4d012b4 100644 --- a/quail/solution/solution_github.py +++ b/quail/solution/solution_github.py @@ -68,7 +68,7 @@ def hook(count, block_size, total_size): (zip_file, headers) = urllib.request.urlretrieve(zip_url, reporthook=hook) self._solution_zip = SolutionZip(zip_file) - self._solution_zip.set_hook(self._hook) + self._solution_zip.set_progress_hook(self._progress_hook) return self._solution_zip.open() def close(self):