diff --git a/conf/repositories.conf b/conf/repositories.conf index a0595d562..7abf9eee3 100644 --- a/conf/repositories.conf +++ b/conf/repositories.conf @@ -4,10 +4,10 @@ # syntax for repositories: # # repository: where the available packages and its database are stored -# repository|servername (no spaces!)|server description| <...>| +#| repository|servername (no spaces!)|server description| <...>| # # example: -## repository|sabayonlinux.org|Sabayon Linux Official Repository|http://www.sabayonlinux.org/packages|http://www.sabayonlinux.org/database +#| repository|sabayonlinux.org|Sabayon Linux Official Repository|http://www.sabayonlinux.org/packages|http://www.sabayonlinux.org/database # # Sabayon Linux Official Repository repository|sabayonlinux.org|Sabayon Linux Official Repository|http://svn.sabayonlinux.org/entropy|http://svn.sabayonlinux.org/entropy#bz2 @@ -59,4 +59,4 @@ officialrepositoryid|sabayonlinux.org # conntestlink: URL which Equo/Entropy can use to test Internet connection availability # conntestlink| # -conntestlink|http://svn.sabayonlinux.org \ No newline at end of file +conntestlink|http://svn.sabayonlinux.org diff --git a/libraries/entropy.py b/libraries/entropy.py index 1dfebf684..84fa67e84 100644 --- a/libraries/entropy.py +++ b/libraries/entropy.py @@ -866,6 +866,25 @@ class EquoInterface(TextInterface): atomMatchCache[atom]['etpRepositoriesOrder'] = etpRepositoriesOrder[:] return repoResults[reponame],reponame + def __repository_move_clear_cache(self, repoid): + # clean world_available cache + self.dumpTools.dumpobj(etpCache['world_available'], {}) + # clean world_update cache + self.dumpTools.dumpobj(etpCache['world_update'], {}) + # clean check_update_package_cache + check_package_update_cache.clear() + self.dumpTools.dumpobj(etpCache['check_package_update'],{}) + # clear atomMatchCache + atomMatchCache.clear() + self.dumpTools.dumpobj(etpCache['atomMatch'],{}) + dbCacheStore[etpCache['dbMatch']+etpConst['dbnamerepoprefix']+repoid] = {} + dbCacheStore[etpCache['dbSearch']+etpConst['dbnamerepoprefix']+repoid] = {} + dbCacheStore[etpCache['dbInfo']+etpConst['dbnamerepoprefix']+repoid] = {} + self.dumpTools.dumpobj(etpCache['dbMatch']+etpConst['dbnamerepoprefix']+repoid,{}) + self.dumpTools.dumpobj(etpCache['dbSearch']+etpConst['dbnamerepoprefix']+repoid,{}) + self.dumpTools.dumpobj(etpCache['dbInfo']+etpConst['dbnamerepoprefix']+repoid,{}) + + def addRepository(self, repodata): # update etpRepositories try: @@ -901,29 +920,49 @@ class EquoInterface(TextInterface): etpRepositoriesOrder.insert(repodata['position'],repodata['repoid']) else: etpRepositoriesOrder.append(repodata['repoid']) - # clean world_available cache - self.dumpTools.dumpobj(etpCache['world_available'], {}) - # clean world_update cache - self.dumpTools.dumpobj(etpCache['world_update'], {}) - # clean check_update_package_cache - check_package_update_cache.clear() - self.dumpTools.dumpobj(etpCache['check_package_update'],{}) - # clear atomMatchCache - atomMatchCache.clear() - self.dumpTools.dumpobj(etpCache['atomMatch'],{}) - generateDependsTreeCache.clear() - self.dumpTools.dumpobj(etpCache['generateDependsTree'],{}) - for dbinfo in dbCacheStore: - if dbinfo == (etpCache['dbMatch']+etpConst['dbnamerepoprefix']+repodata['repoid']) or \ - dbinfo == (etpCache['dbSearch']+etpConst['dbnamerepoprefix']+repodata['repoid']) or \ - dbinfo == (etpCache['dbInfo']+etpConst['dbnamerepoprefix']+repodata['repoid']): - dbCacheStore[dbinfo].clear() - self.dumpTools.dumpobj(dbinfo,{}) - + self.__repository_move_clear_cache(repodata['repoid']) # save new etpRepositories to file self.entropyTools.saveRepositorySettings(repodata) + initConfig_entropyConstants(etpSys['rootdir']) def removeRepository(self, repoid): + + done = False + try: + del etpRepositories[repoid] + done = True + except: + pass + + try: + del etpRepositoriesExcluded[repoid] + done = True + except: + pass + + if done: + try: + etpRepositoriesOrder.remove(repoid) + except: + pass + # it's not vital to reset etpRepositoriesOrder counters + + self.__repository_move_clear_cache(repoid) + # save new etpRepositories to file + repodata = {} + repodata['repoid'] = repoid + self.entropyTools.saveRepositorySettings(repodata, remove = True) + initConfig_entropyConstants(etpSys['rootdir']) + + def enableRepository(self, repoid): + self.__repository_move_clear_cache(repoid) + # save new etpRepositories to file + repodata = {} + repodata['repoid'] = repoid + self.entropyTools.saveRepositorySettings(repodata, enable = True) + initConfig_entropyConstants(etpSys['rootdir']) + + def disableRepository(self, repoid): # update etpRepositories done = False try: @@ -939,17 +978,12 @@ class EquoInterface(TextInterface): pass # it's not vital to reset etpRepositoriesOrder counters - # clean world_available cache - self.dumpTools.dumpobj(etpCache['world_available'], {}) - # clean world_update cache - self.dumpTools.dumpobj(etpCache['world_update'], {}) - # clean check_update_package_cache - check_package_update_cache.clear() - self.dumpTools.dumpobj(etpCache['check_package_update'],{}) + self.__repository_move_clear_cache(repoid) # save new etpRepositories to file repodata = {} repodata['repoid'] = repoid - self.entropyTools.saveRepositorySettings(repodata, remove = True) + self.entropyTools.saveRepositorySettings(repodata, disable = True) + initConfig_entropyConstants(etpSys['rootdir']) ''' diff --git a/libraries/entropyTools.py b/libraries/entropyTools.py index 82fdf181b..44336c1a3 100644 --- a/libraries/entropyTools.py +++ b/libraries/entropyTools.py @@ -1475,35 +1475,68 @@ def getRepositorySettings(repoid): # etpRepositories and etpRepositoriesOrder must be already configured, see where this function is used -def saveRepositorySettings(repodata, remove = False): +def saveRepositorySettings(repodata, remove = False, disable = False, enable = False): if repodata['repoid'].endswith(".tbz2"): return import shutil content = read_repositories_conf() - content = [x.strip() for x in content if not x.startswith("repository|"+repodata['repoid'])] + content = [x.strip() for x in content] + if not disable and not enable: + content = [x.strip() for x in content if not x.strip().startswith("repository|"+repodata['repoid'])] + if remove: + # also remove possible disable repo + content = [x for x in content if not (x.startswith("#") and not x.startswith("##") and (x.find("repository|"+repodata['repoid']) != -1))] if not remove: - repolines = [x for x in content if x.startswith("repository|")] - content = [x.strip() for x in content if x not in repolines] # exclude lines from repolines + repolines = [x for x in content if x.startswith("repository|") or (x.startswith("#") and not x.startswith("##") and (x.find("repository|") != -1))] + content = [x for x in content if x not in repolines] # exclude lines from repolines # filter sane repolines lines repolines = [x for x in repolines if (len(x.split("|")) == 5)] - repolines = [(x,x.split("|")[1]) for x in repolines] - line = "repository|%s|%s|%s|%s#%s" % ( repodata['repoid'], - repodata['description'], - ' '.join(repodata['packages']), - repodata['database'], - repodata['dbcformat'], - ) - repolines.append((line,repodata['repoid'])) + repolines_data = {} + repocount = 0 + for x in repolines: + repolines_data[repocount] = {} + repolines_data[repocount]['repoid'] = x.split("|")[1] + repolines_data[repocount]['line'] = x + if disable and x.split("|")[1] == repodata['repoid']: + repolines_data[repocount]['line'] = "#"+x + elif enable and x.split("|")[1] == repodata['repoid'] and x.startswith("#"): + repolines_data[repocount]['line'] = x[1:] + repocount += 1 + + if not disable and not enable: # so it's a add + + line = "repository|%s|%s|%s|%s#%s" % ( repodata['repoid'], + repodata['description'], + ' '.join(repodata['packages']), + repodata['database'], + repodata['dbcformat'], + ) + + # seek in repolines_data for a disabled entry and remove + to_remove = set() + for c in repolines_data: + if repolines_data[c]['line'].startswith("#") and \ + (repolines_data[c]['line'].find("repository|"+repodata['repoid']) != -1): + # then remove + to_remove.add(c) + for x in to_remove: + del repolines_data[x] + + repolines_data[repocount] = {} + repolines_data[repocount]['repoid'] = repodata['repoid'] + repolines_data[repocount]['line'] = line # inject new repodata - for repoid in etpRepositoriesOrder: + keys = repolines_data.keys() + keys.sort() + for c in keys: + repoid = repolines_data[c]['repoid'] # write the first - for linedata in repolines: - if linedata[1] == repoid: - content.append(linedata[0]) + line = repolines_data[c]['line'] + content.append(line) if os.path.isfile(etpConst['repositoriesconf']): if os.path.isfile(etpConst['repositoriesconf']+".old"): diff --git a/spritz/src/gui.py b/spritz/src/gui.py index 3c79a4b4c..9c3cb9790 100644 --- a/spritz/src/gui.py +++ b/spritz/src/gui.py @@ -276,7 +276,7 @@ class SpritzGUI: self.catsView = CategoriesView(self.ui.tvComps,self.queueView) self.catPackages = EntropyPackageView(self.ui.tvCatPackages,self.queueView) self.catDesc = TextViewConsole(self.ui.catDesc) - self.repoView = EntropyRepoView(self.ui.viewRepo) + self.repoView = EntropyRepoView(self.ui.viewRepo, self.Entropy, self.ui) self.repoMirrorsView = EntropyRepositoryMirrorsView(self.addrepo_ui.mirrorsView) # Left Side Toolbar self.pageButtons = {} # Dict with page buttons diff --git a/spritz/src/spritz.py b/spritz/src/spritz.py index 8a80d6ffa..1636749be 100644 --- a/spritz/src/spritz.py +++ b/spritz/src/spritz.py @@ -159,7 +159,7 @@ class SpritzController(Controller): initConfig_entropyConstants(etpSys['rootdir']) self.setupRepoView() self.addrepo_ui.addRepoWin.hide() - okDialog( self.ui.main, _("You should press %s button") % (_("Regenerate Cache")) ) + okDialog( self.ui.main, _("You should press the %s button now") % (_("Regenerate Cache")) ) def __validateRepoSubmit(self, repodata, edit = False): errors = [] @@ -191,10 +191,9 @@ class SpritzController(Controller): errors = self.__validateRepoSubmit(repodata) if not errors: self.Equo.addRepository(repodata) - initConfig_entropyConstants(etpSys['rootdir']) self.setupRepoView() self.addrepo_ui.addRepoWin.hide() - okDialog( self.ui.main, _("You should now press the %s button") % (_("Update Repositories"),) ) + okDialog( self.ui.main, _("You should now press the %s button now") % (_("Update Repositories"),) ) else: okDialog( self.addrepo_ui.addRepoWin, _("Wrong entries, errors: %s") % (', '.join(errors),) ) @@ -236,7 +235,6 @@ class SpritzController(Controller): okDialog( self.ui.main, _("You! Why do you want to remove the main repository ?")) return True self.Equo.removeRepository(repoid) - initConfig_entropyConstants(etpSys['rootdir']) self.setupRepoView() okDialog( self.ui.main, _("You must now either press the %s or the %s button") % (_("Regenerate Cache"),_("Update Repositories")) ) diff --git a/spritz/src/views.py b/spritz/src/views.py index 7922c87fc..dda94d418 100644 --- a/spritz/src/views.py +++ b/spritz/src/views.py @@ -22,7 +22,6 @@ import gtk import gobject import logging import glob -import sys,os import ConfigParser from i18n import _ @@ -465,51 +464,70 @@ class EntropyRepoView: """ This class controls the repo TreeView """ - def __init__( self, widget): + def __init__( self, widget, EquoConnection, ui): self.view = widget self.headers = [_('Repository'),_('Filename')] self.store = self.setup_view() + self.Equo = EquoConnection + self.ui = ui + import dialogs + self.okDialog = dialogs.okDialog - def on_toggled( self, widget, path): + def on_active_toggled( self, widget, path): """ Repo select/unselect handler """ iter = self.store.get_iter( path ) state = self.store.get_value(iter,0) - self.store.set_value(iter,0, not state) + repoid = self.store.get_value(iter,3) + if repoid != etpConst['officialrepositoryid']: + if state: + self.store.set_value(iter,1, not state) + self.Equo.disableRepository(repoid) + initConfig_entropyConstants(etpSys['rootdir']) + else: + self.Equo.enableRepository(repoid) + initConfig_entropyConstants(etpSys['rootdir']) + self.okDialog(self.ui.main,_("You should press the %s button now") % (_("Regenerate Cache"))) + self.store.set_value(iter,0, not state) + + def on_update_toggled( self, widget, path): + """ Repo select/unselect handler """ + iter = self.store.get_iter( path ) + state = self.store.get_value(iter,1) + active = self.store.get_value(iter,0) + if active: + self.store.set_value(iter,1, not state) def setup_view( self ): """ Create models and columns for the Repo TextView """ - store = gtk.ListStore( 'gboolean', 'gboolean', 'gboolean', gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) + store = gtk.ListStore( 'gboolean', 'gboolean', gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) self.view.set_model( store ) - # Setup Up button - cell0 = gtk.CellRendererSpin() # Selection - #cell0.set_property( 'activatable', True ) - column0 = gtk.TreeViewColumn( "", cell0 ) - #column2.add_attribute( cell2, "active", 2 ) - self.view.append_column( column0 ) - #cell0.connect( "clicked", self.on_up_clicked ) - # Setup Down button - cell1 = gtk.CellRendererSpin() # Selection - column1 = gtk.TreeViewColumn( "", cell1 ) + # Setup Selection Column + cell1 = gtk.CellRendererToggle() # Selection + cell1.set_property( 'activatable', True ) + column1 = gtk.TreeViewColumn( _("Active"), cell1 ) + column1.add_attribute( cell1, "active", 0 ) + column1.set_resizable( True ) + column1.set_sort_column_id( -1 ) self.view.append_column( column1 ) - #cell1.connect( "clicked", self.on_down_clicked ) + cell1.connect( "toggled", self.on_active_toggled ) # Setup Selection Column cell2 = gtk.CellRendererToggle() # Selection cell2.set_property( 'activatable', True ) - column2 = gtk.TreeViewColumn( "Selected", cell2 ) - column2.add_attribute( cell2, "active", 2 ) + column2 = gtk.TreeViewColumn( _("Update"), cell2 ) + column2.add_attribute( cell2, "active", 1 ) column2.set_resizable( True ) column2.set_sort_column_id( -1 ) self.view.append_column( column2 ) - cell2.connect( "toggled", self.on_toggled ) + cell2.connect( "toggled", self.on_update_toggled ) # Setup revision column - self.create_text_column( _('Revision'),3 ) + self.create_text_column( _('Revision'),2 ) # Setup reponame & repofile column's - self.create_text_column( _('Repository Identifier'),4 ) - self.create_text_column( _('Description'),5 ) + self.create_text_column( _('Repository Identifier'),3 ) + self.create_text_column( _('Description'),4 ) self.view.set_search_column( 1 ) self.view.set_reorderable( False ) return store @@ -526,11 +544,12 @@ class EntropyRepoView: first = 0 for repo in etpRepositoriesOrder: repodata = etpRepositories[repo] - self.store.append([first,1,1,repodata['dbrevision'],repo,repodata['description']]) + self.store.append([1,1,repodata['dbrevision'],repo,repodata['description']]) first = 1 # excluded ones for repo in etpRepositoriesExcluded: - self.store.append([first,1,0,etpRepositoriesExcluded['dbrevision'],repo,etpRepositoriesExcluded['description']]) + repodata = etpRepositoriesExcluded[repo] + self.store.append([0,0,repodata['dbrevision'],repo,repodata['description']]) first = 1 def new_pixbuf( self, column, cell, model, iter ): @@ -544,8 +563,9 @@ class EntropyRepoView: selected = [] for elem in self.store: state = elem[0] - name = elem[2] - if state: + selection = elem[1] + name = elem[3] + if state and selection: selected.append( name ) return selected @@ -572,7 +592,7 @@ class EntropyRepoView: def get_repoid(self, iterdata): model, iter = iterdata - return model.get_value( iter, 2 ) + return model.get_value( iter, 3 ) def select_by_keys( self, keys): iterator = self.store.get_iter_first()