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, ))