Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement to repositories management #36

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 101 additions & 32 deletions dnfdragora/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from dnfdragora import const
import dnfdragora.misc as misc
from dnfdragora import const
import dnfdragora.config


import gettext
from gettext import gettext as _
Expand Down Expand Up @@ -182,7 +184,17 @@ def __init__(self, parent):
self.mgaFactory = self.parent.mgaFactory
self.backend = self.parent.backend
self.itemList = {}

self.expert = False
self.config_repos = dnfdragora.config.AppConfig('dnfdragora-repos')
self.hideStandard = False
self.config_repos.load()
self.simplified = self.config_repos.content
if self.simplified == None:
print ("Config file dnfdragora-repos.yaml not found. Expert mode selected")
self.expert = True
self.hideStandard = True


def _setupUI(self):
'''
setup the dialog layout
Expand All @@ -206,14 +218,20 @@ def _setupUI(self):

self.factory.createHeading(hbox_iconbar, _("Repository Management"))

hbox_top = self.factory.createHBox(vbox)
hbox_middle = self.factory.createHBox(vbox)
hbox_bottom = self.factory.createHBox(vbox)
hbox_footbar = self.factory.createHBox(vbox)

hbox_footbar.setWeight(1,10)
hbox_middle.setWeight(1,50)
hbox_bottom.setWeight(1,30)
hbox_footbar.setWeight(1,10)

if not self.hideStandard:
self.cb_expert = self.factory.createPushButton(hbox_top, _("Expert mode"))
else:
self.cb_expert = None
repoList_header = yui.YTableHeader()
columns = [ _('Name'), _("Enabled")]

Expand All @@ -232,23 +250,39 @@ def _setupUI(self):
self.quitButton = self.factory.createIconButton(hbox_footbar,"",_("&Cancel"))
self.quitButton.setWeight(0,3)
self.dialog.setDefaultButton(self.quitButton)
self.drawList()

def drawList(self):
self.itemList = {}
# TODO fix the workaround when GetRepo(id) works again
repos = self.backend.get_repo_ids("*")
for r in repos:
item = yui.YCBTableItem(r)
# TODO name from repo info
self.itemList[r] = {
'item' : item, 'name': r, 'enabled' : False
}
item.this.own(False)
enabled_repos = self.backend.get_repo_ids("enabled")
for r in enabled_repos:
if r in self.itemList.keys():
self.itemList[r]["enabled"] = True
self.itemList[r]["item"].check(True)

if self.expert:
for r in repos:
item = yui.YCBTableItem(r)
# TODO name from repo info
self.itemList[r] = {
'item' : item, 'name': r, 'enabled' : False
}
item.this.own(False)
enabled_repos = self.backend.get_repo_ids("enabled")
for r in enabled_repos:
if r in self.itemList.keys():
self.itemList[r]["enabled"] = True
self.itemList[r]["item"].check(True)
else: # Standard mode
cat = self.simplified['categs']
enabled_repos = self.backend.get_repo_ids("enabled")
for c in cat:
item = yui.YCBTableItem(c['name'])
# TODO name from repo info
self.itemList[c['name']] = {
'item' : item, 'name': c['name'], 'enabled' : False
}
item.this.own(False)
r = c['repos'][0]
if r in enabled_repos:
self.itemList[c['name']]['enabled'] = True
self.itemList[c['name']]['item'].check(True)
keylist = sorted(self.itemList.keys())
v = []
for key in keylist :
Expand All @@ -264,6 +298,12 @@ def _setupUI(self):
self.repoList.addItems(itemCollection)
self.repoList.doneMultipleChanges()

def toogle_expert(self):
self.expert = not self.expert
self.cb_expert.setLabel( _("Standard mode") if self.expert else _("Expert mode"))
self.drawList()
self.dialog.recalcLayout()

def _selectedRepository(self) :
'''
gets the selected repository id from repo list, if any selected
Expand Down Expand Up @@ -303,7 +343,14 @@ def _handleEvents(self):
enabled_repos = []
for k in self.itemList.keys():
if self.itemList[k]['enabled'] :
enabled_repos.append(k)
if self.expert:
enabled_repos.append(k)
else:
for c in self.simplified['categs']:
# Enabling categories which can't be disabled an selected ones
if c['name'] == self.itemList[k]['name'] or not c['disabling']:
for r in c['repos']:
enabled_repos.append(r)
logger.info("Enabling repos %s "%" ".join(enabled_repos))
self.backend.SetEnabledRepos(enabled_repos)
break
Expand All @@ -315,23 +362,45 @@ def _handleEvents(self):
for it in self.itemList:
if (self.itemList[it]['item'] == changedItem) :
self.itemList[it]['enabled'] = changedItem.checked()
repo_id = self._selectedRepository()
s = "TODO show repo %s information<br> See https://github.com/timlau/dnf-daemon/issues/11"%(repo_id if repo_id else "---")
# TODO decide what and how to show when the crash https://github.com/timlau/dnf-daemon/issues/11 is fixed
try:
ri = self.backend.GetRepo(repo_id)
logger.debug(ri)
s = ""
for k in sorted(ri.keys()):
if (ri[k]):
s+= "<b>%s</b>: %s<br>"%(k, ri[k])
except NameError as e:
logger.error("dnfdaemon NameError: %s ", e)
except AttributeError as e:
logger.error("dnfdaemon AttributeError: %s ", e)
except:
logger.error("Unexpected error: %s ", sys.exc_info()[0])
self.info.setText(s)
if self.expert:
repo_id = self._selectedRepository()
s = "TODO show repo %s information<br> See https://github.com/timlau/dnf-daemon/issues/11"%(repo_id if repo_id else "---")
# TODO decide what and how to show when the crash https://github.com/timlau/dnf-daemon/issues/11 is fixed
try:
ri = self.backend.GetRepo(repo_id)
logger.debug(ri)
s = ""
for k in sorted(ri.keys()):
if (ri[k]):
s+= "<b>%s</b>: %s<br>"%(k, ri[k])
except NameError as e:
logger.error("dnfdaemon NameError: %s ", e)
except AttributeError as e:
logger.error("dnfdaemon AttributeError: %s ", e)
except:
logger.error("Unexpected error: %s ", sys.exc_info()[0])
self.info.setText(s)
else:
cat = self.simplified['categs']
for it in self.itemList:
if (self.itemList[it]['item'] == changedItem) :
if (self.itemList[it]['enabled']):
s=_("Enabling:<br>")
else:
s=_("Disabling:<br>")
for c in cat:
if c['name']==self.itemList[it]['name']:
if c['disabling']:
for r in c['repos']:
s+="- %s<br>"%r
else:
s = _("Disabling is not allowed.")
break
break
self.info.setText(s)
elif(widget == self.cb_expert):
logger.info('Toogle expert mode')
self.toogle_expert()

def run(self):
'''
Expand Down
22 changes: 22 additions & 0 deletions share/dnfdragora/dnfdragora-repos.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
categs:
- name: Core
disabling: False
repos:
- mageia-x86_64
- updates-x86_64
- mageia-i586
- updates-i586
- name: Nonfree
disabling True
repos:
- mageia-x86_64-nonfree
- updates-x86_64-nonfree
- mageia-i586-nonfree
- updates-i586-nonfree
- name: Tainted
disabling: True
repos':
- mageia-x86_64-tainted
- updates-x86_64-tainted
- mageia-i586-tainted
- updates-i586-tainted