def _on_file_set(self, chooser): f = chooser.get_filename() with zipfile.ZipFile(f, 'r') as z: try: fragment = () file_extension = None file_metadata = None for n in z.namelist(): if n.endswith("metadata.json"): fragment = n.split("/")[0:-1] file_metadata = n if n.endswith("extension.js"): if file_extension: raise Exception("Only one extension per zip file") file_extension = n if not file_metadata: raise Exception("Could not find metadata.json") if not file_extension: raise Exception("Could not find extension.js") #extract the extension uuid extension_uuid = None tmp = tempfile.mkdtemp() z.extract(file_metadata, tmp) with open(os.path.join(tmp, file_metadata)) as f: try: extension_uuid = json.load(f)["uuid"] except: logging.warning("Invalid extension format", exc_info=True) ok = False if extension_uuid: ok, updated = extract_zip_file( z, "/".join(fragment), os.path.join(self._shell.EXTENSION_DIR, extension_uuid)) if ok: if updated: verb = _("%s extension updated successfully" ) % extension_uuid else: verb = _("%s extension installed successfully" ) % extension_uuid self.notify_logout() else: self.notify_information(_("Error installing extension")) except: #does not look like a valid theme self.notify_information(_("Invalid extension")) logging.warning("Error parsing theme zip", exc_info=True) #set button back to default state chooser.unselect_all()
def _on_file_set(self, chooser): f = chooser.get_filename() with zipfile.ZipFile(f, 'r') as z: try: fragment = () file_extension = None file_metadata = None for n in z.namelist(): if n.endswith("metadata.json"): fragment = n.split("/")[0:-1] file_metadata = n if n.endswith("extension.js"): if file_extension: raise Exception("Only one extension per zip file") file_extension = n if not file_metadata: raise Exception("Could not find metadata.json") if not file_extension: raise Exception("Could not find extension.js") #extract the extension uuid extension_uuid = None tmp = tempfile.mkdtemp() z.extract(file_metadata, tmp) with open(os.path.join(tmp, file_metadata)) as f: try: extension_uuid = json.load(f)["uuid"] except: logging.warning("Invalid extension format", exc_info=True) ok = False if extension_uuid: ok, updated = extract_zip_file( z, "/".join(fragment), os.path.join(self._shell.EXTENSION_DIR, extension_uuid)) if ok: if updated: verb = _("%s extension updated successfully") % extension_uuid else: verb = _("%s extension installed successfully") % extension_uuid self.notify_logout() else: self.notify_information(_("Error installing extension")) except: #does not look like a valid theme self.notify_information(_("Invalid extension")) logging.warning("Error parsing theme zip", exc_info=True) #set button back to default state chooser.unselect_all()
def _on_file_set(self, chooser): f = chooser.get_filename() with zipfile.ZipFile(f, 'r') as z: try: fragment = () theme_name = None for n in z.namelist(): if n.endswith("gnome-shell.css"): fragment = n.split("/")[0:-1] if n.endswith("gnome-shell/theme.json"): logging.info("New style theme detected (theme.json)") #new style theme - extract the name from the json file tmp = tempfile.mkdtemp() z.extract(n, tmp) with open(os.path.join(tmp, n)) as f: try: theme_name = json.load( f)["shell-theme"]["name"] except: logging.warning("Invalid theme format", exc_info=True) if not fragment: raise Exception("Could not find gnome-shell.css") if not theme_name: logging.info( "Old style theme detected (missing theme.json)") #old style themes name was taken from the zip name if fragment[0] == "theme" and len(fragment) == 1: theme_name = os.path.basename(f) else: theme_name = fragment[0] theme_members_path = "/".join(fragment) ok, updated = extract_zip_file( z, theme_members_path, os.path.join(ShellThemeTweak.THEME_DIR, theme_name, "gnome-shell")) if ok: if updated: self.notify_information( _("%s theme updated successfully") % theme_name) else: self.notify_information( _("%s theme installed successfully") % theme_name) #I suppose I could rely on updated as indicating whether to add the theme #name to the combo, but just check to see if it is already there model = self._combo.get_model() if theme_name not in [r[0] for r in model]: model.append((theme_name, theme_name)) else: self.notify_information(_("Error installing theme")) except: #does not look like a valid theme self.notify_information(_("Invalid theme")) logging.warning("Error parsing theme zip", exc_info=True) #set button back to default state chooser.unselect_all()
def _on_file_set(self, chooser): f = chooser.get_filename() with zipfile.ZipFile(f, 'r') as z: try: fragment = () theme_name = None for n in z.namelist(): if n.endswith("gnome-shell.css"): fragment = n.split("/")[0:-1] if n.endswith("gnome-shell/theme.json"): logging.info("New style theme detected (theme.json)") #new style theme - extract the name from the json file tmp = tempfile.mkdtemp() z.extract(n, tmp) with open(os.path.join(tmp,n)) as f: try: theme_name = json.load(f)["shell-theme"]["name"] except: logging.warning("Invalid theme format", exc_info=True) if not fragment: raise Exception("Could not find gnome-shell.css") if not theme_name: logging.info("Old style theme detected (missing theme.json)") #old style themes name was taken from the zip name if fragment[0] == "theme" and len(fragment) == 1: theme_name = os.path.basename(f) else: theme_name = fragment[0] theme_members_path = "/".join(fragment) ok, updated = extract_zip_file( z, theme_members_path, os.path.join(ShellThemeTweak.THEME_DIR, theme_name, "gnome-shell")) if ok: if updated: self.notify_information(_("%s theme updated successfully") % theme_name) else: self.notify_information(_("%s theme installed successfully") % theme_name) #I suppose I could rely on updated as indicating whether to add the theme #name to the combo, but just check to see if it is already there model = self._combo.get_model() if theme_name not in [r[0] for r in model]: model.append( (theme_name, theme_name) ) else: self.notify_information(_("Error installing theme")) except: #does not look like a valid theme self.notify_information(_("Invalid theme")) logging.warning("Error parsing theme zip", exc_info=True) #set button back to default state chooser.unselect_all()