summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2006-03-27 20:18:16 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2006-03-27 20:18:16 +0200
commitd35c7defd7e19b1f7bcb193c86bd1be5c50dd491 (patch)
treeabeafc5b54efdbc96997938c40c372b672872a1a
parent6297fce66c8243488048690472f0d1ebc329dd52 (diff)
downloadpython-apt-d35c7defd7e19b1f7bcb193c86bd1be5c50dd491.tar.gz
* added the patch from chipzz
-rw-r--r--SoftwareProperties/SoftwareProperties.py14
-rw-r--r--SoftwareProperties/aptsources.py135
-rw-r--r--SoftwareProperties/dialog_add.py91
-rw-r--r--data/SoftwarePropertiesDialogs.glade2
-rw-r--r--debian/changelog2
5 files changed, 167 insertions, 77 deletions
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 "<country>." (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 "<country>." (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
diff --git a/data/SoftwarePropertiesDialogs.glade b/data/SoftwarePropertiesDialogs.glade
index 7ff8d976..581cc565 100644
--- a/data/SoftwarePropertiesDialogs.glade
+++ b/data/SoftwarePropertiesDialogs.glade
@@ -59,7 +59,7 @@
</child>
<child>
- <widget class="GtkButton" id="button3">
+ <widget class="GtkButton" id="button_add">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
diff --git a/debian/changelog b/debian/changelog
index f5132e2e..ac0ac6e5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,7 +6,7 @@ update-manager (0.42.2ubuntu10) dapper; urgency=low
* keybindings fixed (#36116)
* calc the update before downloading the changelog (#36140)
- --
+ -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 27 Mar 2006 16:45:56 +0200
update-manager (0.42.2ubuntu9) dapper; urgency=low