def run(self, InstallProgress): import libbricks.engine as engine from libbricks.features import features atleastone = False for feature, choice in self.moduleclass.modules_settings["bricks"]["features"].items(): status, packages, allpackages = engine.status(feature) dic = features[feature] if not choice: # remove! atleastone = True engine.remove(packages) # We should really, really, really ensure that no # dependency remains. We do this by marking too the # meta-package's dependencies as to be removed. pkgs = [] for typ in dic["enable_selection"]: dps = engine.dependencies_loop_simplified(dic[typ]) for dep in dps: if dep.name.startswith("meta-") or dep.name in pkgs: continue pkgs.append(dep.name) engine.remove(pkgs, auto=False) # Commit if atleastone: engine.cache.commit(install_progress=InstallProgress)
def build_feature_objects(self): """ Builds GTK+ elements to list the features onto the GUI. """ for feature in features_order: dic = features[feature] self._objects[feature] = {} # Generate high level VBox self._objects[feature]["main_container"] = Gtk.VBox() # Generate high level HBox self._objects[feature]["container"] = Gtk.HBox() # Generate icon & text HBox self._objects[feature]["icontextcontainer"] = Gtk.HBox() self._objects[feature]["icontextcontainer"].set_spacing(5) # Generate text VBox (advanced selection also hooked here) self._objects[feature]["textcontainer"] = Gtk.VBox() self._objects[feature]["textcontainer"].set_spacing(3) # Generate switch self._objects[feature]["switch"] = Gtk.Switch() self._objects[feature]["switch"].set_halign(Gtk.Align.END) self._objects[feature]["switch"].set_valign(Gtk.Align.CENTER) # Preset the switch print "FEATURE %s STATUS: %s" % (feature, engine.status(feature)[0]) if engine.status(feature)[0]: self._objects[feature]["switch"].set_active(True) else: self._objects[feature]["switch"].set_active(False) self._objects[feature]["switch"].connect( "notify::active", self.on_switch_pressed, feature) # Generate icon self._objects[feature]["icon"] = Gtk.Image() self._objects[feature]["icon"].set_from_icon_name( dic["icon"], Gtk.IconSize.DIALOG) # Generate title self._objects[feature]["title"] = Gtk.Label() self._objects[feature]["title"].set_alignment(0.0,0.0) self._objects[feature]["title"].set_markup( "<b>%s</b>" % dic["title"]) # Add it self._objects[feature]["textcontainer"].pack_start( self._objects[feature]["title"], False, False, 0) # Generate subtext if "subtext" in dic: self._objects[feature]["subtext"] = Gtk.Label() self._objects[feature]["subtext"].set_alignment(0.0,0.0) self._objects[feature]["subtext"].set_markup( dic["subtext"]) self._objects[feature]["subtext"].set_line_wrap(True) # Add it self._objects[feature]["textcontainer"].pack_start( self._objects[feature]["subtext"], False, False, 0) # Pack icon and textcontainer self._objects[feature]["icontextcontainer"].pack_start( self._objects[feature]["icon"], False, False, 0) self._objects[feature]["icontextcontainer"].pack_start( self._objects[feature]["textcontainer"], True, True, 0) # Pack icontextcontainer and switch self._objects[feature]["container"].pack_start( self._objects[feature]["icontextcontainer"], True, True, 0) self._objects[feature]["container"].pack_start( self._objects[feature]["switch"], False, False, 0) # Pack normal container into the main VBox... self._objects[feature]["main_container"].pack_start( self._objects[feature]["container"], False, False, 0) # Generate Expander to attach, if we should if "enable_selection" in dic: self._objects[feature]["expander_vbox"] = Gtk.VBox() self._objects[feature]["expander_align"] = Gtk.Alignment() self._objects[feature]["expander_align"].set_padding( 5,5,12,0) # Generate a list of checkboxes to add to the vbox.. self.generate_advanced( self._objects[feature]["expander_vbox"], feature) self._objects[feature]["expander_align"].add( self._objects[feature]["expander_vbox"]) # Add it self._objects[feature]["main_container"].pack_start( self._objects[feature]["expander_align"], False, False, 0) # Pack main_container into the main container GObject.idle_add(self.container.pack_start, self._objects[feature]["main_container"], False, False, 0) # Show the box GObject.idle_add(self.waiting.hide) GObject.idle_add(self.selection_box.show_all) GObject.idle_add(self.close.set_sensitive, True) GObject.idle_add(self.advanced_enabled.set_sensitive, True)
def run(self): """ Apply the changes! """ atleastone = False # hack to not commit if not needed try: # Get the status of each switch, then change cache accordingly for feature, objs in self.parent._objects.items(): status, packages, allpackages = engine.status(feature) # Get things to purge, if any to_purge = () if "purge" in features[feature]: to_purge = features[feature]["purge"] change = objs["switch"].get_active() if change and change == status: # We shouldn't touch this feature. continue elif not change: # We need to check every checkbox to see if we need # to change something toinstall = [] toremove = [] allfalse = True # should check if there is at least one True item for dep, checkbox in self.parent.checkboxes[feature].items(): value = checkbox.get_active() if value and not engine.is_installed(dep): # Package needs to be installed. toinstall.append(dep) allfalse = False elif value: allfalse = False elif not value and engine.is_installed(dep): # Package is installed and needs removal toremove.append(dep) if allfalse: # Every checkbox is false, we can mark for removal # the entire "packages" atleastone = True engine.remove(packages, purge=to_purge) else: # the user customized the feature. # We need to be sure that the meta package is # being processed as well. # First, we need to loop through the customizable # metapackages for meta in features[feature]["enable_selection"]: meta = features[feature][meta] # Now that we got the package name, we need to # get its dependencies... deps = engine.dependencies_loop_simplified(meta, asString=True) # ...and see if one of ours is there for pkg in toremove: if pkg in deps: # Yeah! Just add meta to toremove toremove.append(meta) break print "Packages to install:", toinstall print "Packages to remove:", toremove if toinstall: atleastone = True engine.install(toinstall) if toremove: atleastone = True engine.remove(toremove, auto=False, purge=to_purge) else: atleastone = True # Should mark for installation! engine.install(allpackages) #self.parent.progress_set_quota(100) #for lol in range(100): # self.parent.progress_set_text(str(lol)) # self.parent.progress_set_percentage(lol) # #self.parent.update_progress(str(lol), lol) # time.sleep(0.3) # Commit if atleastone: engine.cache.commit(AcquireProgress(self.parent), InstallProgress(self.parent)) except: excp = sys.exc_info() error = "".join(traceback.format_exception(excp[0],excp[1],excp[2])) print(error) GObject.idle_add( self.parent.error_window.format_secondary_markup, # _("Press Close to exit from the application.") + "\n\n<i>" + error + "</i>") "<i>%s</i>\n\n" % excp[1] + _("Press Close to exit from the application.")) GObject.idle_add(self.parent.error_window.show) else: self.parent.really_quit()