From 98ecb0421d8f5cc2f1420ad39c514315fd048118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Mon, 20 Jan 2014 13:52:30 -0300 Subject: Do not try/except sections in the config, explicitly check for their existence This avoids adding useless tracebacks to the real exceptions caught by Twisted. Possible tx bug here. --- src/launcher.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index b62bd23..2a43e54 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -4,21 +4,22 @@ import time import threading import ConfigParser -from leap.bitmask.app import main as leap_client +from leap.bitmask.app import main as bitmask_client from leap.common.events import server from thandy.ClientCLI import update as thandy_update bundles_per_platform = { - "Windows" : "/bundleinfo/LEAPClient-win/", - "Darwin" : "", - "Linux" : "/bundleinfo/LEAPClient/", + "Windows": "/bundleinfo/LEAPClient-win/", + "Darwin": "", + "Linux": "/bundleinfo/LEAPClient/", } GENERAL_SECTION = "General" UPDATES_KEY = "Updates" + class Thandy(threading.Thread): def run(self): while True: @@ -50,16 +51,16 @@ if __name__ == "__main__": config.read("launcher.conf") launch_thandy = False - try: + + has_config = config.has_section(GENERAL_SECTION) and \ + config.has_option(GENERAL_SECTION, UPDATES_KEY) + + if has_config: launch_thandy = config.getboolean(GENERAL_SECTION, UPDATES_KEY) - except ConfigParser.NoSectionError as ns: - pass - except ConfigParser.NoOptionError as no: - pass if launch_thandy: thandy_thread = Thandy() thandy_thread.daemon = True thandy_thread.start() - leap_client() + bitmask_client() -- cgit v1.2.3 From f02d060b1d19929e4050aace09f193133244f1b8 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 18 Jun 2014 18:02:50 +0200 Subject: Implement updater using TUF --- src/launcher.py | 113 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 35 deletions(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index 2a43e54..9eb5bc1 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -1,47 +1,99 @@ import os +import shutil import platform import time import threading import ConfigParser from leap.bitmask.app import main as bitmask_client -from leap.common.events import server - -from thandy.ClientCLI import update as thandy_update +from leap.common.events import server, signal +from leap.common.events import events_pb2 as proto +import tuf.client.updater bundles_per_platform = { - "Windows": "/bundleinfo/LEAPClient-win/", - "Darwin": "", - "Linux": "/bundleinfo/LEAPClient/", + "Windows": "windows", + "Darwin": "darwin", + "Linux": "linux", } GENERAL_SECTION = "General" -UPDATES_KEY = "Updates" +DELAY_KEY = "updater_delay" + + +class TUF(threading.Thread): + def __init__(self, config): + """ + Initialize the list of mirrors, paths and other TUF dependencies from the config file + """ + if config.has_section(GENERAL_SECTION) and \ + config.has_option(GENERAL_SECTION, DELAY_KEY): + self.delay = config.getboolean(GENERAL_SECTION, DELAY_KEY) + else: + self.delay = 60 + + self._load_mirrors(config) + if not self.mirrors: + print "ERROR: No updater mirrors found (missing or not well formed launcher.conf)" + self.bundle_path = os.getcwd() + self.source_path = self.bundle_path + self.dest_path = os.path.join(self.bundle_path, 'tmp') + self.update_path = os.path.join(self.bundle_path, 'updates') + + threading.Thread.__init__(self) -class Thandy(threading.Thread): def run(self): + """ + Check for updates periodically + """ + if not self.mirrors: + return + while True: try: - os.environ["THANDY_HOME"] = os.path.join(os.getcwd(), - "config", - "thandy") - os.environ["THP_DB_ROOT"] = os.path.join(os.getcwd(), - "packages") - os.environ["THP_INSTALL_ROOT"] = os.path.join(os.getcwd(), - "updates") - args = [ - "--repo=repo/", - "--install", - bundles_per_platform[platform.system()] - ] - thandy_update(args) + tuf.conf.repository_directory = os.path.join(self.bundle_path, 'repo') + + updater = tuf.client.updater.Updater('leap-updater', self.mirrors) + updater.refresh() + + targets = updater.all_targets() + updated_targets = updater.updated_targets(targets, self.source_path) + for target in updated_targets: + updater.download_target(target, self.dest_path) + self._set_permissions(target) + if os.path.isdir(self.dest_path): + if os.path.isdir(self.update_path): + shutil.rmtree(self.update_path) + shutil.move(self.dest_path, self.update_path) + signal(proto.UPDATER_NEW_UPDATES, + content=", ".join(sorted([f['filepath'] for f in updated_targets]))) + return except Exception as e: print "ERROR:", e finally: - # TODO: Make this delay configurable - time.sleep(60) + time.sleep(self.delay) + + def _load_mirrors(self, config): + self.mirrors = {} + for section in config.sections(): + if section[:6] != 'Mirror': + continue + url_prefix = config.get(section, 'url_prefix') + metadata_path = bundles_per_platform[platform.system()] + '/metadata' + targets_path = bundles_per_platform[platform.system()] + '/targets' + self.mirrors[section[7:]] = {'url_prefix': url_prefix, + 'metadata_path': metadata_path, + 'targets_path': targets_path, + 'confined_target_dirs': ['']} + + def _set_permissions(self, target): + file_permisions = int(target["fileinfo"]["custom"]["file_permissions"], 8) + filepath = target['filepath'] + if filepath[0] == '/': + filepath = filepath[1:] + file_path = os.path.join(self.dest_path, filepath) + os.chmod(file_path, file_permisions) if __name__ == "__main__": @@ -50,17 +102,8 @@ if __name__ == "__main__": config = ConfigParser.ConfigParser() config.read("launcher.conf") - launch_thandy = False - - has_config = config.has_section(GENERAL_SECTION) and \ - config.has_option(GENERAL_SECTION, UPDATES_KEY) - - if has_config: - launch_thandy = config.getboolean(GENERAL_SECTION, UPDATES_KEY) - - if launch_thandy: - thandy_thread = Thandy() - thandy_thread.daemon = True - thandy_thread.start() + tuf_thread = TUF(config) + tuf_thread.daemon = True + tuf_thread.start() bitmask_client() -- cgit v1.2.3 From f46163c9be65cb4ab202c5c992c5cd16bed98475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Wed, 16 Jul 2014 17:01:46 -0300 Subject: Modify launcher.py to support refactor --- src/launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index 9eb5bc1..e833fc5 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -5,7 +5,7 @@ import time import threading import ConfigParser -from leap.bitmask.app import main as bitmask_client +from leap.bitmask.app import start_app as bitmask_client from leap.common.events import server, signal from leap.common.events import events_pb2 as proto -- cgit v1.2.3 From 4d08978c2d45099cd47496a883b954f2ad0aa7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Tue, 5 Aug 2014 13:59:31 -0300 Subject: Properly retrieve launcher delay --- src/launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index e833fc5..a47d697 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -28,7 +28,7 @@ class TUF(threading.Thread): """ if config.has_section(GENERAL_SECTION) and \ config.has_option(GENERAL_SECTION, DELAY_KEY): - self.delay = config.getboolean(GENERAL_SECTION, DELAY_KEY) + self.delay = config.getint(GENERAL_SECTION, DELAY_KEY) else: self.delay = 60 -- cgit v1.2.3 From a1f8bd242a88c10b229794fb7f11b19c42ad2dd7 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 10 Sep 2014 12:00:17 -0500 Subject: Fix pep8 errors --- src/launcher.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index a47d697..614101b 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -24,7 +24,8 @@ DELAY_KEY = "updater_delay" class TUF(threading.Thread): def __init__(self, config): """ - Initialize the list of mirrors, paths and other TUF dependencies from the config file + Initialize the list of mirrors, paths and other TUF dependencies from + the config file """ if config.has_section(GENERAL_SECTION) and \ config.has_option(GENERAL_SECTION, DELAY_KEY): @@ -34,7 +35,8 @@ class TUF(threading.Thread): self._load_mirrors(config) if not self.mirrors: - print "ERROR: No updater mirrors found (missing or not well formed launcher.conf)" + print("ERROR: No updater mirrors found (missing or not well " + "formed launcher.conf)") self.bundle_path = os.getcwd() self.source_path = self.bundle_path @@ -52,13 +54,16 @@ class TUF(threading.Thread): while True: try: - tuf.conf.repository_directory = os.path.join(self.bundle_path, 'repo') + tuf.conf.repository_directory = os.path.join(self.bundle_path, + 'repo') - updater = tuf.client.updater.Updater('leap-updater', self.mirrors) + updater = tuf.client.updater.Updater('leap-updater', + self.mirrors) updater.refresh() targets = updater.all_targets() - updated_targets = updater.updated_targets(targets, self.source_path) + updated_targets = updater.updated_targets(targets, + self.source_path) for target in updated_targets: updater.download_target(target, self.dest_path) self._set_permissions(target) @@ -66,8 +71,9 @@ class TUF(threading.Thread): if os.path.isdir(self.update_path): shutil.rmtree(self.update_path) shutil.move(self.dest_path, self.update_path) + filepath = sorted([f['filepath'] for f in updated_targets]) signal(proto.UPDATER_NEW_UPDATES, - content=", ".join(sorted([f['filepath'] for f in updated_targets]))) + content=", ".join(filepath)) return except Exception as e: print "ERROR:", e @@ -88,12 +94,13 @@ class TUF(threading.Thread): 'confined_target_dirs': ['']} def _set_permissions(self, target): - file_permisions = int(target["fileinfo"]["custom"]["file_permissions"], 8) + file_permissions_str = target["fileinfo"]["custom"]["file_permissions"] + file_permissions = int(file_permissions_str, 8) filepath = target['filepath'] if filepath[0] == '/': filepath = filepath[1:] file_path = os.path.join(self.dest_path, filepath) - os.chmod(file_path, file_permisions) + os.chmod(file_path, file_permissions) if __name__ == "__main__": -- cgit v1.2.3 From 6f82fe5991d616bad0e0caf9340544ed7cdc2099 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 10 Sep 2014 12:53:33 -0500 Subject: Add support for multiple archs in one platform --- src/launcher.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index 614101b..fbd0368 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -12,9 +12,8 @@ from leap.common.events import events_pb2 as proto import tuf.client.updater bundles_per_platform = { - "Windows": "windows", - "Darwin": "darwin", - "Linux": "linux", + "Linux-i386": "linux-i368", + "Linux-x86_64": "linux-x86_64", } GENERAL_SECTION = "General" @@ -75,6 +74,9 @@ class TUF(threading.Thread): signal(proto.UPDATER_NEW_UPDATES, content=", ".join(filepath)) return + except NotImplemented as e: + print "NotImplemented: ", e + return except Exception as e: print "ERROR:", e finally: @@ -86,8 +88,8 @@ class TUF(threading.Thread): if section[:6] != 'Mirror': continue url_prefix = config.get(section, 'url_prefix') - metadata_path = bundles_per_platform[platform.system()] + '/metadata' - targets_path = bundles_per_platform[platform.system()] + '/targets' + metadata_path = self._repo_path() + '/metadata' + targets_path = self._repo_path() + '/targets' self.mirrors[section[7:]] = {'url_prefix': url_prefix, 'metadata_path': metadata_path, 'targets_path': targets_path, @@ -102,6 +104,12 @@ class TUF(threading.Thread): file_path = os.path.join(self.dest_path, filepath) os.chmod(file_path, file_permissions) + def _repo_path(self): + system = platform.system() + "-" + platform.machine() + if system not in bundles_per_platform: + raise NotImplemented("Platform %s not supported" % (system,)) + return bundles_per_platform[system] + if __name__ == "__main__": server.ensure_server(port=8090) -- cgit v1.2.3 From 45a6fc7881365f998a4e0be4109e386489b96c98 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 12 Sep 2014 13:15:33 -0500 Subject: Add i686 as arch --- src/launcher.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index fbd0368..5560fe3 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -13,6 +13,7 @@ import tuf.client.updater bundles_per_platform = { "Linux-i386": "linux-i368", + "Linux-i686": "linux-i368", "Linux-x86_64": "linux-x86_64", } @@ -107,7 +108,7 @@ class TUF(threading.Thread): def _repo_path(self): system = platform.system() + "-" + platform.machine() if system not in bundles_per_platform: - raise NotImplemented("Platform %s not supported" % (system,)) + raise NotImplementedError("Platform %s not supported" % (system,)) return bundles_per_platform[system] -- cgit v1.2.3 From 4914d07fd577227f0d84e908cff489e104d7ec55 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 22 Sep 2014 10:05:56 -0500 Subject: Add some logging on updates --- src/launcher.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/launcher.py') diff --git a/src/launcher.py b/src/launcher.py index 5560fe3..bbd4f42 100644 --- a/src/launcher.py +++ b/src/launcher.py @@ -64,6 +64,8 @@ class TUF(threading.Thread): targets = updater.all_targets() updated_targets = updater.updated_targets(targets, self.source_path) + if updated_targets: + print "There is updates needed. Start downloading updates." for target in updated_targets: updater.download_target(target, self.dest_path) self._set_permissions(target) @@ -74,6 +76,7 @@ class TUF(threading.Thread): filepath = sorted([f['filepath'] for f in updated_targets]) signal(proto.UPDATER_NEW_UPDATES, content=", ".join(filepath)) + print "Updates ready: ", filepath return except NotImplemented as e: print "NotImplemented: ", e -- cgit v1.2.3