From d35c7defd7e19b1f7bcb193c86bd1be5c50dd491 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 27 Mar 2006 20:18:16 +0200 Subject: * added the patch from chipzz --- SoftwareProperties/SoftwareProperties.py | 14 +++- SoftwareProperties/aptsources.py | 135 +++++++++++++++++-------------- SoftwareProperties/dialog_add.py | 91 ++++++++++++++++++--- 3 files changed, 165 insertions(+), 75 deletions(-) (limited to 'SoftwareProperties') diff --git a/SoftwareProperties/SoftwareProperties.py b/SoftwareProperties/SoftwareProperties.py index 9613b49e..8453cc24 100644 --- a/SoftwareProperties/SoftwareProperties.py +++ b/SoftwareProperties/SoftwareProperties.py @@ -363,8 +363,18 @@ class SoftwareProperties(SimpleGladeApp): if not iter: return source_entry = model.get_value(iter, LIST_ENTRY_OBJ) - dialog = dialog_edit.dialog_edit(self.window_main, self.sourceslist, - source_entry, self.datadir) + # see if we know what this thing should look like + found_matcher = False + for item in aptsources.SourceEntryTemplates(self.datadir).templates: + if item.matches(source_entry): + found_matcher = True + break + if found_matcher: + dialog = dialog_add.dialog_add(self.window_main, self.sourceslist, + self.datadir, source_entry) + else: + dialog = dialog_edit.dialog_edit(self.window_main, self.sourceslist, + source_entry, self.datadir) if dialog.run() == gtk.RESPONSE_OK: self.reload_sourceslist() self.modified = True diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index 77de510b..3e82c74b 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -32,6 +32,47 @@ import os.path from UpdateManager.Common.DistInfo import DistInfo + +# some global helpers +def is_mirror(master_uri, compare_uri): + """check if the given add_url is idential or a mirror of orig_uri + e.g. master_uri = archive.ubuntu.com + compare_uri = de.archive.ubuntu.com + -> True + """ + # remove traling spaces and "/" + compare_uri = compare_uri.rstrip("/ ") + master_uri = master_uri.rstrip("/ ") + # uri is identical + if compare_uri == master_uri: + #print "Identical" + return True + # add uri is a master site and orig_uri has the from "XX.mastersite" + # (e.g. de.archive.ubuntu.com) + try: + compare_srv = compare_uri.split("//")[1] + master_srv = master_uri.split("//")[1] + #print "%s == %s " % (add_srv, orig_srv) + except IndexError: # ok, somethings wrong here + #print "IndexError" + return False + # remove the leading "." (if any) and see if that helps + if "." in compare_srv and \ + compare_srv[compare_srv.index(".")+1:] == master_srv: + #print "Mirror" + return True + return False + +def uniq(s): + """ simple (and not efficient) way to return uniq list """ + u = [] + for x in s: + if x not in u: + u.append(x) + return u + + + # actual source.list entries class SourceEntry: @@ -148,14 +189,23 @@ class SourceEntry: line += "\n" return line -def uniq(s): - """ simple (and not efficient) way to return uniq list """ - u = [] - for x in s: - if x not in u: - u.append(x) - return u - + def add(self, type, uri, dist, comps, comment="", pos=-1): + # if there is a repo with the same (type, uri, dist) just add the + # components + for i in self.list: + if i.type == type and is_mirror(uri,i.uri) and i.dist == dist: + comps = uniq(i.comps + comps) + # set to the old position and preserve comment + comment = i.comment + pos = self.list.index(i) + self.list.remove(i) + line = "%s %s %s" % (type,uri,dist) + for c in comps: + line = line + " " + c; + if comment != "": + line = "%s #%s\n" %(line,comment) + line = line + "\n" + self.list.insert(pos, SourceEntry(line)) # the SourceList file as a class class SourcesList: @@ -179,53 +229,6 @@ class SourcesList: yield entry raise StopIteration - def is_mirror(self, master_uri, compare_uri): - """check if the given add_url is idential or a mirror of orig_uri - e.g. master_uri = archive.ubuntu.com - compare_uri = de.archive.ubuntu.com - -> True - """ - # remove traling spaces and "/" - compare_uri = compare_uri.rstrip("/ ") - master_uri = master_uri.rstrip("/ ") - # uri is identical - if compare_uri == master_uri: - #print "Identical" - return True - # add uri is a master site and orig_uri has the from "XX.mastersite" - # (e.g. de.archive.ubuntu.com) - try: - compare_srv = compare_uri.split("//")[1] - master_srv = master_uri.split("//")[1] - #print "%s == %s " % (add_srv, orig_srv) - except IndexError: # ok, somethings wrong here - #print "IndexError" - return False - # remove the leading "." (if any) and see if that helps - if "." in compare_srv and \ - compare_srv[compare_srv.index(".")+1:] == master_srv: - #print "Mirror" - return True - return False - - def add(self, type, uri, dist, comps, comment="", pos=-1): - # if there is a repo with the same (type, uri, dist) just add the - # components - for i in self.list: - if i.type == type and self.is_mirror(uri,i.uri) and i.dist == dist: - comps = uniq(i.comps + comps) - # set to the old position and preserve comment - comment = i.comment - pos = self.list.index(i) - self.list.remove(i) - line = "%s %s %s" % (type,uri,dist) - for c in comps: - line = line + " " + c; - if comment != "": - line = "%s #%s\n" %(line,comment) - line = line + "\n" - self.list.insert(pos, SourceEntry(line)) - def remove(self, source_entry): self.list.remove(source_entry) @@ -274,7 +277,6 @@ class SourcesList: # templates for the add dialog class SourceEntryTemplate(SourceEntry): def __init__(self,a_type,uri,dist,description,comps): - self.comps = [] self.comps_descriptions = [] self.type = a_type self.uri = uri @@ -282,6 +284,19 @@ class SourceEntryTemplate(SourceEntry): self.description = description self.comps = comps + def matches(self,source_entry): + """ check if a given source_entry matches this one """ + if (self.type <> source_entry.type): return False + if (self.dist <> source_entry.dist): return False + if not is_mirror(self.uri,source_entry.uri): + return False + for e_comp in source_entry.comps: + for t_comp in self.comps: + if e_comp == t_comp.name: break + else: + return False + return True + class SourceCompTemplate: def __init__(self, name, description, on_by_default): self.name = name @@ -538,9 +553,9 @@ if __name__ == "__main__": print entry.str() #print entry.uri - mirror = sources.is_mirror("http://archive.ubuntu.com/ubuntu/", - "http://de.archive.ubuntu.com/ubuntu/") + mirror = is_mirror("http://archive.ubuntu.com/ubuntu/", + "http://de.archive.ubuntu.com/ubuntu/") print "is_mirror(): %s" % mirror - print sources.is_mirror("http://archive.ubuntu.com/ubuntu", - "http://de.archive.ubuntu.com/ubuntu/") + print is_mirror("http://archive.ubuntu.com/ubuntu", + "http://de.archive.ubuntu.com/ubuntu/") diff --git a/SoftwareProperties/dialog_add.py b/SoftwareProperties/dialog_add.py index 9b384623..4ee17a87 100644 --- a/SoftwareProperties/dialog_add.py +++ b/SoftwareProperties/dialog_add.py @@ -26,13 +26,19 @@ import os import gobject import gtk import gtk.glade +from gettext import gettext as _ import aptsources +import dialog_edit class dialog_add: - def __init__(self, parent, sourceslist, datadir): + def __init__(self, parent, sourceslist, datadir, source_entry = None): self.sourceslist = sourceslist self.parent = parent + self.datadir = datadir + self.custom = False + # we have a source_entry that we want to modify + self.source_entry = source_entry # templates self.templatelist = aptsources.SourceEntryTemplates(datadir) @@ -52,16 +58,31 @@ class dialog_add: combo.pack_start(cell, True) combo.add_attribute(cell, 'text', 0) self.fill_combo(combo) + if source_entry: + self.main.set_title(_("Edit Channel")) + self.gladexml.get_widget("button_add").set_label("gtk-ok") self.gladexml.signal_connect("on_button_custom_clicked", self.on_button_custom_clicked, None) def fill_combo(self,combo): liststore = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT) + matched_template = None for item in self.templatelist.templates: liststore.append((item.description, item)) + if self.source_entry and item.matches(self.source_entry): + matched_template = item combo.set_model(liststore) - combo.set_active(0) + if matched_template: + try: + combo.set_active(self.templatelist.templates.index(matched_template)) + vbox = self.gladexml.get_widget("vbox_comps") + for c in vbox.get_children(): + c.set_active(c.get_data("name") in self.source_entry.comps) + except ValueError: + pass + else: + combo.set_active(0) def on_combobox_what_changed(self, combobox, user): #print "on_combobox_what_changed" @@ -83,19 +104,55 @@ class dialog_add: #print "on_button_custom_clicked()" # this hide here is ugly :/ self.main.hide() - dialog = self.gladexml.get_widget("dialog_add_custom") - dialog.set_transient_for(self.parent) - res = dialog.run() - dialog.hide() - entry = self.gladexml.get_widget("entry_source_line") - line = entry.get_text() + "\n" - self.sourceslist.list.append(aptsources.SourceEntry(line)) + # check if we are in add or edit-matched mode + if self.source_entry: + # we are in "edit" mode + # get the SourceEntry as it is now (with local changes) + # and display the "old" edit dialog + self.selected_comps = [] + vbox = self.gladexml.get_widget("vbox_comps") + vbox.foreach(self.get_enabled_comps) + source_entry = self._make_source_entry() + # since we're passing the SourceEntry as it is now, + # this SourceEntry needs to be in the sourceslist, + # so temporarily swap the original for the current + source_entry_index = self.sourcelist.list.index(source_entry) + self.sourceslist.list[source_entry_index] = source_entry + dialog = dialog_edit.dialog_edit(self.parent, self.sourceslist, + source_entry, self.datadir) + res = dialog.run() + if res == gtk.RESPONSE_CANCEL: + # restore original SourceEntry + self.sourceslist.list[source_entry_index] = self.source_entry + elif res == gtk.RESPONSE_OK: + # the sourceslist is allready updated, but we'll overwrite it + # in self.run if we're not carefull + self.custom = True + else: + # we are in "add" mode + dialog = self.gladexml.get_widget("dialog_add_custom") + dialog.set_transient_for(self.parent) + res = dialog.run() + dialog.hide() + entry = self.gladexml.get_widget("entry_source_line") + line = entry.get_text() + "\n" + self.sourceslist.list.append(aptsources.SourceEntry(line)) self.main.response(res) def get_enabled_comps(self, checkbutton): if checkbutton.get_active(): self.selected_comps.append(checkbutton.get_data("name")) + def _make_source_entry(self): + " helper for the 'edit' mode " + line = "%s %s %s" % (self.selected.type, self.source_entry.uri, self.selected.dist) + if len(self.selected_comps) > 0: + line += " " + " ".join(self.selected_comps) + if self.selected.matches(self.source_entry) and self.source_entry.comment != "": + line += " #"+self.source_entry.comment + line += "\n" + return aptsources.SourceEntry(line,self.source_entry.file) + def run(self): res = self.main.run() if res == gtk.RESPONSE_OK: @@ -103,9 +160,17 @@ class dialog_add: self.selected_comps = [] vbox = self.gladexml.get_widget("vbox_comps") vbox.foreach(self.get_enabled_comps) - self.sourceslist.add(self.selected.type, - self.selected.uri, - self.selected.dist, - self.selected_comps) + # check if we are in 'add' or 'edit' mode + if self.source_entry: + # 'edit' - ode + if not self.custom: + source_entry_index = self.sourcelist.list.index(source_entry) + self.sourceslist.list[source_entry_index] = self._make_source_entry() + else: + # 'add' mode + self.sourceslist.add(self.selected.type, + self.selected.uri, + self.selected.dist, + self.selected_comps) self.main.hide() return res -- cgit v1.2.3 From bd4359789d0e72fbbcd49f22b7f535e9238f3f93 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 27 Mar 2006 20:35:23 +0200 Subject: * more comments added --- SoftwareProperties/dialog_add.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'SoftwareProperties') diff --git a/SoftwareProperties/dialog_add.py b/SoftwareProperties/dialog_add.py index 4ee17a87..9a074396 100644 --- a/SoftwareProperties/dialog_add.py +++ b/SoftwareProperties/dialog_add.py @@ -145,6 +145,9 @@ class dialog_add: def _make_source_entry(self): " helper for the 'edit' mode " + # we use "selected" for pretty much everything *but* we use + # self.source_entry.uri to make sure that the mirror information is + # preserved line = "%s %s %s" % (self.selected.type, self.source_entry.uri, self.selected.dist) if len(self.selected_comps) > 0: line += " " + " ".join(self.selected_comps) -- cgit v1.2.3 From 01c2875f19b40695b75c1014f4d1adc536c081fe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 27 Mar 2006 21:25:05 +0200 Subject: * small fixes --- SoftwareProperties/aptsources.py | 36 ++++++++++++++++++------------------ SoftwareProperties/dialog_add.py | 12 +++++++----- 2 files changed, 25 insertions(+), 23 deletions(-) (limited to 'SoftwareProperties') diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index 3e82c74b..933d9960 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -189,24 +189,6 @@ class SourceEntry: line += "\n" return line - def add(self, type, uri, dist, comps, comment="", pos=-1): - # if there is a repo with the same (type, uri, dist) just add the - # components - for i in self.list: - if i.type == type and is_mirror(uri,i.uri) and i.dist == dist: - comps = uniq(i.comps + comps) - # set to the old position and preserve comment - comment = i.comment - pos = self.list.index(i) - self.list.remove(i) - line = "%s %s %s" % (type,uri,dist) - for c in comps: - line = line + " " + c; - if comment != "": - line = "%s #%s\n" %(line,comment) - line = line + "\n" - self.list.insert(pos, SourceEntry(line)) - # the SourceList file as a class class SourcesList: def __init__(self): @@ -229,6 +211,24 @@ class SourcesList: yield entry raise StopIteration + def add(self, type, uri, dist, comps, comment="", pos=-1): + # if there is a repo with the same (type, uri, dist) just add the + # components + for i in self.list: + if i.type == type and is_mirror(uri,i.uri) and i.dist == dist: + comps = uniq(i.comps + comps) + # set to the old position and preserve comment + comment = i.comment + pos = self.list.index(i) + self.list.remove(i) + line = "%s %s %s" % (type,uri,dist) + for c in comps: + line = line + " " + c; + if comment != "": + line = "%s #%s\n" %(line,comment) + line = line + "\n" + self.list.insert(pos, SourceEntry(line)) + def remove(self, source_entry): self.list.remove(source_entry) diff --git a/SoftwareProperties/dialog_add.py b/SoftwareProperties/dialog_add.py index 9a074396..cee2f9b8 100644 --- a/SoftwareProperties/dialog_add.py +++ b/SoftwareProperties/dialog_add.py @@ -39,6 +39,10 @@ class dialog_add: self.custom = False # we have a source_entry that we want to modify self.source_entry = source_entry + if source_entry: + self.source_entry_index = sourceslist.list.index(source_entry) + else: + self.source_entry_index = None # templates self.templatelist = aptsources.SourceEntryTemplates(datadir) @@ -116,14 +120,13 @@ class dialog_add: # since we're passing the SourceEntry as it is now, # this SourceEntry needs to be in the sourceslist, # so temporarily swap the original for the current - source_entry_index = self.sourcelist.list.index(source_entry) - self.sourceslist.list[source_entry_index] = source_entry + self.sourceslist.list[self.source_entry_index] = source_entry dialog = dialog_edit.dialog_edit(self.parent, self.sourceslist, source_entry, self.datadir) res = dialog.run() if res == gtk.RESPONSE_CANCEL: # restore original SourceEntry - self.sourceslist.list[source_entry_index] = self.source_entry + self.sourceslist.list[self.source_entry_index] = self.source_entry elif res == gtk.RESPONSE_OK: # the sourceslist is allready updated, but we'll overwrite it # in self.run if we're not carefull @@ -167,8 +170,7 @@ class dialog_add: if self.source_entry: # 'edit' - ode if not self.custom: - source_entry_index = self.sourcelist.list.index(source_entry) - self.sourceslist.list[source_entry_index] = self._make_source_entry() + self.sourceslist.list[self.source_entry_index] = self._make_source_entry() else: # 'add' mode self.sourceslist.add(self.selected.type, -- cgit v1.2.3 From 00af0c2e8a7b983a1570e69a1a0696c51a58685b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 12 Apr 2006 20:21:59 +0200 Subject: * fix disable and "no components selected" --- SoftwareProperties/dialog_add.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'SoftwareProperties') diff --git a/SoftwareProperties/dialog_add.py b/SoftwareProperties/dialog_add.py index cee2f9b8..fbf741c5 100644 --- a/SoftwareProperties/dialog_add.py +++ b/SoftwareProperties/dialog_add.py @@ -120,7 +120,8 @@ class dialog_add: # since we're passing the SourceEntry as it is now, # this SourceEntry needs to be in the sourceslist, # so temporarily swap the original for the current - self.sourceslist.list[self.source_entry_index] = source_entry + if source_entry: + self.sourceslist.list[self.source_entry_index] = source_entry dialog = dialog_edit.dialog_edit(self.parent, self.sourceslist, source_entry, self.datadir) res = dialog.run() @@ -151,8 +152,13 @@ class dialog_add: # we use "selected" for pretty much everything *but* we use # self.source_entry.uri to make sure that the mirror information is # preserved + line = "%s %s %s" % (self.selected.type, self.source_entry.uri, self.selected.dist) - if len(self.selected_comps) > 0: + if self.source_entry.disabled: + line = "#" + line + if len(self.selected.comps) > 0 and len(self.selected_comps) == 0: + line = "#" + line + elif len(self.selected_comps) > 0: line += " " + " ".join(self.selected_comps) if self.selected.matches(self.source_entry) and self.source_entry.comment != "": line += " #"+self.source_entry.comment @@ -170,7 +176,9 @@ class dialog_add: if self.source_entry: # 'edit' - ode if not self.custom: - self.sourceslist.list[self.source_entry_index] = self._make_source_entry() + entry = self._make_source_entry() + if entry: + self.sourceslist.list[self.source_entry_index] = entry else: # 'add' mode self.sourceslist.add(self.selected.type, -- cgit v1.2.3