From e4b693b2061a0e3d93feba4fa570df7424bbe0d4 Mon Sep 17 00:00:00 2001 From: "Clayton G. Hobbs" Date: Sun, 27 Dec 2015 17:00:45 -0500 Subject: Rewrote language_updater.sh in Python At the same time, I moved the logic to check if the language should be updated into the new LanguageUpdater class. The README has been updated to reflect the fact that you no longer need to do any of this manually ever. --- blather.py | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'blather.py') diff --git a/blather.py b/blather.py index a90afe3..23802e8 100755 --- a/blather.py +++ b/blather.py @@ -16,6 +16,7 @@ import json from recognizer import Recognizer from config import Config +from languageupdater import LanguageUpdater class Blather: @@ -35,7 +36,7 @@ class Blather: # Read the commands self.read_commands() - if self.options['interface'] != None: + if self.options['interface']: if self.options['interface'] == "g": from gtkui import UI elif self.options['interface'] == "gt": @@ -59,7 +60,8 @@ class Blather: self.history = [] # Update the language if necessary - self.update_language() + self.language_updater = LanguageUpdater(self.config) + self.language_updater.update_language_if_changed() # Create the recognizer self.recognizer = Recognizer(self.config) @@ -95,34 +97,6 @@ class Blather: # Close the file hfile.close() - def update_language(self): - """Update the language if its hash has changed""" - # Load the stored hash from the hash file - try: - with open(self.config.hash_file, 'r') as f: - hashes = json.load(f) - stored_hash = hashes['language'] - except (IOError, KeyError, TypeError): - # No stored hash - stored_hash = '' - - # Calculate the hash the language file has right now - hasher = hashlib.sha256() - with open(self.config.strings_file, 'rb') as sfile: - buf = sfile.read() - hasher.update(buf) - new_hash = hasher.hexdigest() - - # If the hashes differ - if stored_hash != new_hash: - # Update the language - # FIXME: Do this with Python, not Bash - self.run_command('./language_updater.sh') - # Store the new hash - new_hashes = {'language': new_hash} - with open(self.config.hash_file, 'w') as f: - json.dump(new_hashes, f) - def run_command(self, cmd): """Print the command, then run it""" print(cmd) -- cgit 1.4.1