From 3bb8f4ac210287af2351c5d8a0f02e3fa30f2586 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 2 Jan 2017 11:19:28 -0600 Subject: [PATCH] set ui_version for bundled ui --- lbrynet/lbrynet_daemon/Daemon.py | 3 +-- lbrynet/lbrynet_daemon/UIManager.py | 24 +++++++++++++++++++-- tests/unit/lbrynet_daemon/test_UIManager.py | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index fbc1f5772..0514f9e34 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -252,7 +252,6 @@ class Daemon(AuthJSONRPCServer): self.connection_problem = None self.git_lbrynet_version = None self.git_lbryum_version = None - self.ui_version = None self.platform = None self.first_run = None self.log_file = conf.settings.get_log_filename() @@ -1174,7 +1173,7 @@ class Daemon(AuthJSONRPCServer): 'os_system': platform_info['os_system'], 'lbrynet_version': lbrynet_version, 'lbryum_version': lbryum_version, - 'ui_version': self.ui_version, + 'ui_version': platform_info['ui_version'], 'remote_lbrynet': self.git_lbrynet_version, 'remote_lbryum': self.git_lbryum_version, 'lbrynet_update_available': lbrynet_update_available, diff --git a/lbrynet/lbrynet_daemon/UIManager.py b/lbrynet/lbrynet_daemon/UIManager.py index 89f009fca..8f34a4b1a 100644 --- a/lbrynet/lbrynet_daemon/UIManager.py +++ b/lbrynet/lbrynet_daemon/UIManager.py @@ -67,6 +67,10 @@ class UIManager(object): self.check_requirements = (check_requirements if check_requirements is not None else conf.settings.check_ui_requirements) + # Note that this currently overrides any manual setting of UI. + # It might be worth considering changing that behavior but the expectation + # is generally that any manual setting of the UI will happen during development + # and not for folks checking out the QA / RC builds that bundle the UI. if self._check_for_bundled_ui(): return defer.succeed(True) @@ -94,6 +98,7 @@ class UIManager(object): return d def _check_for_bundled_ui(self): + """Try to load a bundled UI and return True if successful, False otherwise""" try: bundled_path = get_bundled_ui_path() except Exception: @@ -101,7 +106,10 @@ class UIManager(object): return False else: bundle_manager = BundledUIManager(self.root, self.active_dir, bundled_path) - return bundle_manager.setup() + loaded = bundle_manager.setup() + if loaded: + self.loaded_git_version = bundle_manager.version() + return loaded def _up_to_date(self): def _get_git_info(): @@ -256,6 +264,12 @@ class BundledUIManager(object): self.active_dir = active_dir self.bundled_ui_path = bundled_ui_path self.data_path = os.path.join(bundled_ui_path, 'data.json') + self._version = None + + def version(self): + if not self._version: + self._version = open_and_read_sha(self.data_path) + return self._version def bundle_is_available(self): return os.path.exists(self.data_path) @@ -277,7 +291,8 @@ class BundledUIManager(object): def is_active_already_bundled_ui(self): target_data_path = os.path.join(self.active_dir, 'data.json') if os.path.exists(target_data_path): - if are_same_version(self.data_path, target_data_path): + target_version = open_and_read_sha(target_data_path) + if self.version() == target_version: return True return False @@ -293,6 +308,11 @@ def are_same_version(data_a, data_b): return read_sha(a) == read_sha(b) +def open_and_read_sha(filename): + with open(filename) as f: + return read_sha(f) + + def read_sha(filelike): data = json.load(filelike) return data['sha'] diff --git a/tests/unit/lbrynet_daemon/test_UIManager.py b/tests/unit/lbrynet_daemon/test_UIManager.py index d194bd747..ae05f06b4 100644 --- a/tests/unit/lbrynet_daemon/test_UIManager.py +++ b/tests/unit/lbrynet_daemon/test_UIManager.py @@ -39,6 +39,7 @@ class BundledUIManagerTest(unittest.TestCase): touch(os.path.join(self.bundled_dir, 'test.html')) result = self.manager.setup() self.assertTrue(result) + self.assertEqual('BARFOO', self.manager.version()) expected = ['data.json', 'test.html'] self.assertItemsEqual(os.listdir(self.active_dir), expected)