def updateAddons(self): """ For all the addons in the addon db, check their version number and download status, and install any addons that have updates available or have never been installed. Arguments: - `self`: """ with self.conn: cur = self.conn.execute("SELECT * FROM addons;") for addon in cur: addon = Addon(*addon) # check to see if an update is available # if the addon isn't installed at all, we will # still use the version fetched by this function # to record. update_available = addon.updateAvailable() if update_available and addon.installed: # TODO: fix this. shouldn't need to check for the version twice in one fuction addon.newest_file = addon.getNewestVersion() print("Upate available, installing %s." % addon.name) self.installAddon(addon) else: print("%s is up to date." % addon.name)
def installAddon(self, addon): """ Download, and extract an addon into the addons folder. Arguments: - `self`: - `addon`: Addon or String """ if isinstance(addon, str): addon = Addon(addon) # check if item is already in the DB with self.conn: in_db = self.conn.execute("SELECT name FROM addons WHERE name=?",\ (addon.name, )) if not addon.installed and not in_db.fetchone(): # add new if addon.getFile() and addon.unzipFile(self.addons_dir): addon.newest_file = addon.getNewestVersion() with self.conn: # print debugging print("Adding record for %s." % addon.name) print("Version -> %s" % addon.newest_file) print("Files extracted -> %s" % json.dumps(addon.files)) self.conn.execute("INSERT INTO addons VALUES (?, ?, ?, ?)",\ (addon.name, addon.newest_file, True, json.dumps(addon.files), )) else: #update... assume new version number and files only if addon.getFile() and addon.unzipFile(self.addons_dir): addon.newest_file = addon.getNewestVersion() with self.conn: # print debugging print("Updating record for %s." % addon.name) print("Version -> %s" % addon.newest_file) print("Files extracted -> %s" % json.dumps(addon.files)) self.conn.execute("UPDATE addons SET version=?,files=?,downloaded=? WHERE name=?;",\ (addon.newest_file, json.dumps(addon.files), True, addon.name, ))