diff options
| author | glatzor@ubuntu.com <> | 2006-07-21 22:53:55 +0200 |
|---|---|---|
| committer | glatzor@ubuntu.com <> | 2006-07-21 22:53:55 +0200 |
| commit | faa8e24031b9dfb788aa51e50770b7f572f18e9d (patch) | |
| tree | 2e5bff62c8f6f948c6e4b6efb61fdf72ec65d8d4 /SoftwareProperties | |
| parent | 14d80b531b3b1d7e2f13003c9d04cf428b6df1b7 (diff) | |
| download | python-apt-faa8e24031b9dfb788aa51e50770b7f572f18e9d.tar.gz | |
* Moved the Distribution class to aptsources
* Added a command line option: --enable-component
* Added a handler for the toggled popcon checkbutton
Diffstat (limited to 'SoftwareProperties')
| -rw-r--r-- | SoftwareProperties/SoftwareProperties.py | 193 | ||||
| -rw-r--r-- | SoftwareProperties/aptsources.py | 219 |
2 files changed, 211 insertions, 201 deletions
diff --git a/SoftwareProperties/SoftwareProperties.py b/SoftwareProperties/SoftwareProperties.py index 14e570b9..d920b693 100644 --- a/SoftwareProperties/SoftwareProperties.py +++ b/SoftwareProperties/SoftwareProperties.py @@ -73,170 +73,6 @@ CONF_MAP = { STORE_VISIBLE ) = range(5) -class Distribution: - def __init__(self): - """" - Container for distribution specific informations - """ - # LSB information - self.id = "" - self.codename = "" - self.description = "" - self.release = "" - - # get the LSB information - lsb_info = [] - for lsb_option in ["-i", "-c", "-d", "-r"]: - pipe = os.popen("lsb_release %s | cut -d : -f 2-" % lsb_option) - lsb_info.append(pipe.read().strip()) - del pipe - (self.id, self.codename, self.description, self.release) = lsb_info - - # get a list of country codes and real names - self.countries = {} - try: - f = open("/usr/share/iso-codes/iso_3166.tab", "r") - lines = f.readlines() - for line in lines: - parts = line.split("\t") - self.countries[parts[0].lower()] = parts[1] - except: - print "could not open file '%s'" % file - else: - f.close() - - - - def get_sources(self, sources_list): - """ - Find the corresponding template, main and child sources - for the distribution - """ - # corresponding sources - self.source_template = None - self.child_sources = [] - self.main_sources = [] - self.disabled_sources = [] - self.cdrom_sources = [] - self.download_comps = [] - self.enabled_comps = [] - self.cdrom_comps = [] - self.used_media = [] - self.get_source_code = False - self.source_code_sources = [] - - # location of the sources - self.main_server = "" - self.nearest_server = "" - self.used_servers = [] - - # find the distro template - for template in sources_list.matcher.templates: - if template.name == self.codename and\ - template.distribution == self.id: - #print "yeah! found a template for %s" % self.description - #print template.description, template.base_uri, template.components - self.source_template = template - break - if self.source_template == None: - print "Error: could not find a distribution template" - # FIXME: will go away - only for debugging issues - sys.exit(1) - - # find main and child sources - media = [] - comps = [] - cdrom_comps = [] - enabled_comps = [] - source_code = [] - for source in sources_list.list: - if source.invalid == False and\ - source.dist == self.codename and\ - source.template and\ - source.template.name == self.codename: - #print "yeah! found a distro repo: %s" % source.line - # cdroms need do be handled differently - if source.uri.startswith("cdrom:") and \ - source.disabled == False: - self.cdrom_sources.append(source) - cdrom_comps.extend(source.comps) - elif source.uri.startswith("cdrom:") and \ - source.disabled == True: - self.cdrom_sources.append(source) - elif source.type == "deb" and source.disabled == False: - self.main_sources.append(source) - comps.extend(source.comps) - media.append(source.uri) - elif source.type == "deb" and source.disabled == True: - self.disabled_sources.append(source) - elif source.type.endswith("-src") and source.disabled == False: - self.source_code_sources.append(source) - elif source.type.endswith("-src") and source.disabled == True: - self.disabled_sources.append(source) - if source.template in self.source_template.children: - #print "yeah! child found: %s" % source.template.name - if source.type == "deb": - self.child_sources.append(source) - elif source.type == "deb-src": - self.source_code_sources.append(source) - self.download_comps = set(comps) - self.cdrom_comps = set(cdrom_comps) - enabled_comps.extend(comps) - enabled_comps.extend(cdrom_comps) - self.enabled_comps = set(enabled_comps) - self.used_media = set(media) - - self.get_mirrors() - - def get_mirrors(self): - """ - Provide a set of mirrors where you can get the distribution from - """ - # the main server is stored in the template - self.main_server = self.source_template.base_uri - - # try to guess the nearest mirror from the locale - # FIXME: for debian we need something different - if self.id == "Ubuntu": - locale = os.getenv("LANG", default="en.UK") - a = locale.find("_") - z = locale.find(".") - if z == -1: - z = len(locale) - country_code = locale[a+1:z].lower() - self.nearest_server = "http://%s.archive.ubuntu.com/ubuntu/" % \ - country_code - self.country = self.countries[country_code] - - # other used servers - for medium in self.used_media: - if not medium.startswith("cdrom:"): - # seems to be a network source - self.used_servers.append(medium) - - def add_source(self, sources_list, type=None, - uri=None, dist=None, comps=None, comment=""): - """ - Add distribution specific sources - """ - if uri == None: - # FIXME: Add support for the server selector - uri = self.main_server - if dist == None: - dist = self.codename - if comps == None: - comps = list(self.enabled_comps) - if type == None: - type = "deb" - if comment == "": - comment == "Added by software-properties" - new_source = sources_list.add(type, uri, dist, comps, comment) - # if source code is enabled add a deb-src line after the new - # source - if self.get_source_code == True and not type.endswith("-src"): - sources_list.add("%s-src" % type, uri, dist, comps, comment, - file=new_source.file, - pos=sources_list.list.index(new_source)+1) class SoftwareProperties(SimpleGladeApp): @@ -253,7 +89,7 @@ class SoftwareProperties(SimpleGladeApp): self.file = file - self.distro = Distribution() + self.distro = aptsources.Distribution() cell = gtk.CellRendererText() self.combobox_server.pack_start(cell, True) self.combobox_server.add_attribute(cell, 'text', 0) @@ -537,33 +373,10 @@ class SoftwareProperties(SimpleGladeApp): Sync the components of all main sources (excluding cdroms), child sources and source code sources """ - sources = [] - sources.extend(self.distro.main_sources) - sources.extend(self.distro.child_sources) - sources.extend(self.distro.source_code_sources) if checkbutton.get_active() == True: - # check if there is a main source at all - if len(self.distro.main_sources) < 1: - # create a new main source - self.distro.add_source(self.sourceslist, comps=["%s"%comp]) - else: - # add the comp to all main, child and source code sources - for source in sources: - if comp not in source.comps: - source.comps.append(comp) - if self.distro.get_source_code == True: - for source in self.distro.source_code_sources: - if comp not in source.comps: source.comps.append(comp) + self.distro.enable_component(self.sourceslist, comp) else: - if comp in self.distro.cdrom_comps: - sources = [] - sources.extend(self.distro.main_sources) - - for source in sources: - if comp in source.comps: - source.comps.remove(comp) - if len(source.comps) < 1: - self.sourceslist.remove(source) + self.distro.disable_component(self.sourceslist, comp) self.modified_sourceslist() def massive_debug_output(self): diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index 4e76824d..7418a7cb 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -339,17 +339,6 @@ class SourcesList: #print self.parents return (parents, used_child_templates) - def check_for_endangered_dists(self): - """set the components of a child source to the ones of the parent channel""" - (parents, used_child_templates) = self.check_for_relations(self.list) - # the magical part - for mother in parents: - for child_template in mother.template.children: - if used_child_templates.has_key(child_template): - for child in used_child_templates[child_template]: - if child.type == mother.type: - child.comps = mother.comps - # templates for the add dialog class SourceEntryTemplate(SourceEntry): def __init__(self,a_type,uri,dist,description,comps): @@ -495,6 +484,214 @@ class SourceEntryMatcher: break return found +class Distribution: + def __init__(self): + """" + Container for distribution specific informations + """ + # LSB information + self.id = "" + self.codename = "" + self.description = "" + self.release = "" + + # get the LSB information + lsb_info = [] + for lsb_option in ["-i", "-c", "-d", "-r"]: + pipe = os.popen("lsb_release %s | cut -d : -f 2-" % lsb_option) + lsb_info.append(pipe.read().strip()) + del pipe + (self.id, self.codename, self.description, self.release) = lsb_info + + # get a list of country codes and real names + self.countries = {} + try: + f = open("/usr/share/iso-codes/iso_3166.tab", "r") + lines = f.readlines() + for line in lines: + parts = line.split("\t") + self.countries[parts[0].lower()] = parts[1] + except: + print "could not open file '%s'" % file + else: + f.close() + + def get_sources(self, sources_list): + """ + Find the corresponding template, main and child sources + for the distribution + """ + # corresponding sources + self.source_template = None + self.child_sources = [] + self.main_sources = [] + self.disabled_sources = [] + self.cdrom_sources = [] + self.download_comps = [] + self.enabled_comps = [] + self.cdrom_comps = [] + self.used_media = [] + self.get_source_code = False + self.source_code_sources = [] + + # location of the sources + self.main_server = "" + self.nearest_server = "" + self.used_servers = [] + + # find the distro template + for template in sources_list.matcher.templates: + if template.name == self.codename and\ + template.distribution == self.id: + #print "yeah! found a template for %s" % self.description + #print template.description, template.base_uri, template.components + self.source_template = template + break + if self.source_template == None: + print "Error: could not find a distribution template" + # FIXME: will go away - only for debugging issues + sys.exit(1) + + # find main and child sources + media = [] + comps = [] + cdrom_comps = [] + enabled_comps = [] + source_code = [] + for source in sources_list.list: + if source.invalid == False and\ + source.dist == self.codename and\ + source.template and\ + source.template.name == self.codename: + #print "yeah! found a distro repo: %s" % source.line + # cdroms need do be handled differently + if source.uri.startswith("cdrom:") and \ + source.disabled == False: + self.cdrom_sources.append(source) + cdrom_comps.extend(source.comps) + elif source.uri.startswith("cdrom:") and \ + source.disabled == True: + self.cdrom_sources.append(source) + elif source.type == "deb" and source.disabled == False: + self.main_sources.append(source) + comps.extend(source.comps) + media.append(source.uri) + elif source.type == "deb" and source.disabled == True: + self.disabled_sources.append(source) + elif source.type.endswith("-src") and source.disabled == False: + self.source_code_sources.append(source) + elif source.type.endswith("-src") and source.disabled == True: + self.disabled_sources.append(source) + if source.template in self.source_template.children: + #print "yeah! child found: %s" % source.template.name + if source.type == "deb": + self.child_sources.append(source) + elif source.type == "deb-src": + self.source_code_sources.append(source) + self.download_comps = set(comps) + self.cdrom_comps = set(cdrom_comps) + enabled_comps.extend(comps) + enabled_comps.extend(cdrom_comps) + self.enabled_comps = set(enabled_comps) + self.used_media = set(media) + + self.get_mirrors() + + def get_mirrors(self): + """ + Provide a set of mirrors where you can get the distribution from + """ + # the main server is stored in the template + self.main_server = self.source_template.base_uri + + # try to guess the nearest mirror from the locale + # FIXME: for debian we need something different + if self.id == "Ubuntu": + locale = os.getenv("LANG", default="en.UK") + a = locale.find("_") + z = locale.find(".") + if z == -1: + z = len(locale) + country_code = locale[a+1:z].lower() + self.nearest_server = "http://%s.archive.ubuntu.com/ubuntu/" % \ + country_code + self.country = self.countries[country_code] + + # other used servers + for medium in self.used_media: + if not medium.startswith("cdrom:"): + # seems to be a network source + self.used_servers.append(medium) + + def add_source(self, sources_list, type=None, + uri=None, dist=None, comps=None, comment=""): + """ + Add distribution specific sources + """ + if uri == None: + # FIXME: Add support for the server selector + uri = self.main_server + if dist == None: + dist = self.codename + if comps == None: + comps = list(self.enabled_comps) + if type == None: + type = "deb" + if comment == "": + comment == "Added by software-properties" + new_source = sources_list.add(type, uri, dist, comps, comment) + # if source code is enabled add a deb-src line after the new + # source + if self.get_source_code == True and not type.endswith("-src"): + sources_list.add("%s-src" % type, uri, dist, comps, comment, + file=new_source.file, + pos=sources_list.list.index(new_source)+1) + + def enable_component(self, sourceslist, comp): + """ + Disable a component in all main, child and source code sources + (excluding cdrom based sources) + + sourceslist: an aptsource.sources_list + comp: the component that should be enabled + """ + sources = [] + sources.extend(self.main_sources) + sources.extend(self.child_sources) + sources.extend(self.source_code_sources) + # check if there is a main source at all + if len(self.main_sources) < 1: + # create a new main source + self.add_source(sourceslist, comps=["%s"%comp]) + else: + # add the comp to all main, child and source code sources + for source in sources: + if comp not in source.comps: + source.comps.append(comp) + if self.get_source_code == True: + for source in self.source_code_sources: + if comp not in source.comps: source.comps.append(comp) + + def disable_component(self, sourceslist, comp): + """ + Disable a component in all main, child and source code sources + (excluding cdrom based sources) + """ + sources = [] + sources.extend(self.main_sources) + sources.extend(self.child_sources) + sources.extend(self.source_code_sources) + if comp in self.cdrom_comps: + sources = [] + sources.extend(self.main_sources) + + for source in sources: + if comp in source.comps: + source.comps.remove(comp) + if len(source.comps) < 1: + sourceslist.remove(source) + + # some simple tests if __name__ == "__main__": apt_pkg.InitConfig() |
