summaryrefslogtreecommitdiff
path: root/SoftwareProperties
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2006-04-12 20:47:22 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2006-04-12 20:47:22 +0200
commitcc818961d3cae94e1240bf33b2349381aa1750fc (patch)
tree2490019b1f11fe03e30d4580f02cfb37d9544e5a /SoftwareProperties
parentc5279cfbb9ad48c9d95e535734f311d7c9d98818 (diff)
parent00af0c2e8a7b983a1570e69a1a0696c51a58685b (diff)
downloadpython-apt-cc818961d3cae94e1240bf33b2349381aa1750fc.tar.gz
* merged with update-manager--chipzz
Diffstat (limited to 'SoftwareProperties')
-rw-r--r--SoftwareProperties/SoftwareProperties.py14
-rw-r--r--SoftwareProperties/aptsources.py105
-rw-r--r--SoftwareProperties/dialog_add.py104
3 files changed, 164 insertions, 59 deletions
diff --git a/SoftwareProperties/SoftwareProperties.py b/SoftwareProperties/SoftwareProperties.py
index 9ccf12ad..296c71dc 100644
--- a/SoftwareProperties/SoftwareProperties.py
+++ b/SoftwareProperties/SoftwareProperties.py
@@ -369,8 +369,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 53ae2e84..a2d0a67d 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:
@@ -156,15 +197,6 @@ 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
-
-
# the SourceList file as a class
class SourcesList:
def __init__(self):
@@ -187,40 +219,11 @@ 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:
+ 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
@@ -282,7 +285,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
@@ -290,6 +292,21 @@ 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
@@ -546,9 +563,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..fbf741c5 100644
--- a/SoftwareProperties/dialog_add.py
+++ b/SoftwareProperties/dialog_add.py
@@ -26,13 +26,23 @@ 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
+ if source_entry:
+ self.source_entry_index = sourceslist.list.index(source_entry)
+ else:
+ self.source_entry_index = None
# templates
self.templatelist = aptsources.SourceEntryTemplates(datadir)
@@ -52,16 +62,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 +108,63 @@ 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
+ 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()
+ if res == gtk.RESPONSE_CANCEL:
+ # restore original SourceEntry
+ 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
+ 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 "
+ # 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 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
+ line += "\n"
+ return aptsources.SourceEntry(line,self.source_entry.file)
+
def run(self):
res = self.main.run()
if res == gtk.RESPONSE_OK:
@@ -103,9 +172,18 @@ 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:
+ entry = self._make_source_entry()
+ if entry:
+ self.sourceslist.list[self.source_entry_index] = entry
+ else:
+ # 'add' mode
+ self.sourceslist.add(self.selected.type,
+ self.selected.uri,
+ self.selected.dist,
+ self.selected_comps)
self.main.hide()
return res