Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mouuff committed Jun 24, 2018
1 parent 8e748ed commit db2f35c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions quail/controller/controller_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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!")
Expand Down
4 changes: 2 additions & 2 deletions quail/controller/controller_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
40 changes: 22 additions & 18 deletions quail/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:]))
10 changes: 5 additions & 5 deletions quail/solution/solution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion quail/solution/solution_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit db2f35c

Please sign in to comment.