diff options
| author | Sebastian Heinlein <sebi@sebi-laptop> | 2006-11-25 09:55:04 +0100 |
|---|---|---|
| committer | Sebastian Heinlein <sebi@sebi-laptop> | 2006-11-25 09:55:04 +0100 |
| commit | d21a4328a369e521c49a7ba21834b3e5e950ca97 (patch) | |
| tree | 08f192dfcf3480101cc7e7f923d0fb05876dbde8 /UpdateManager/Common | |
| parent | ee8317343ad726571d5f6ad863ee0b27d58251e5 (diff) | |
| download | python-apt-d21a4328a369e521c49a7ba21834b3e5e950ca97.tar.gz | |
* Fork a pyton-aptsources source tree from update-manager
Diffstat (limited to 'UpdateManager/Common')
| -rw-r--r-- | UpdateManager/Common/DistInfo.py | 164 | ||||
| -rw-r--r-- | UpdateManager/Common/HelpViewer.py | 33 | ||||
| -rw-r--r-- | UpdateManager/Common/Makefile | 350 | ||||
| -rw-r--r-- | UpdateManager/Common/Makefile.am | 5 | ||||
| -rw-r--r-- | UpdateManager/Common/SimpleGladeApp.py | 341 | ||||
| -rw-r--r-- | UpdateManager/Common/__init__.py | 2 | ||||
| -rw-r--r-- | UpdateManager/Common/aptsources.py | 694 | ||||
| -rw-r--r-- | UpdateManager/Common/utils.py | 42 |
8 files changed, 0 insertions, 1631 deletions
diff --git a/UpdateManager/Common/DistInfo.py b/UpdateManager/Common/DistInfo.py deleted file mode 100644 index 57621f52..00000000 --- a/UpdateManager/Common/DistInfo.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env python -# DistInfo.py - simple parser for a xml-based metainfo file -# -# Copyright (c) 2005 Gustavo Noronha Silva -# -# Author: Gustavo Noronha Silva <kov@debian.org> -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA - -import os -import gettext -from os import getenv -import ConfigParser -import string - -from gettext import gettext as _ - -class Suite: - def __init__(self): - self.name = None - self.child = False - self.match_name = None - self.description = None - self.base_uri = None - self.type = None - self.components = {} - self.children = [] - self.match_uri = None - self.valid_mirrors = [] - self.distribution = None - self.available = True - -class Component: - def __init__(self): - self.name = "" - self.description = "" - self.description_long = "" - -class DistInfo: - def __init__(self, - dist = None, - base_dir = "/usr/share/update-manager/channels"): - self.metarelease_uri = '' - self.suites = [] - - if not dist: - pipe = os.popen("lsb_release -i -s") - dist = pipe.read().strip() - pipe.close() - del pipe - - self.dist = dist - - dist_fname = "%s/%s.info" % (base_dir, dist) - dist_file = open (dist_fname) - if not dist_file: - return - suite = None - component = None - for line in dist_file: - tokens = line.split (':', 1) - if len (tokens) < 2: - continue - field = tokens[0].strip () - value = tokens[1].strip () - if field == 'ChangelogURI': - self.changelogs_uri = _(value) - elif field == 'MetaReleaseURI': - self.metarelease_uri = value - elif field == 'Suite': - if suite: - if component: - suite.components["%s" % component.name] = \ - (component.description, - component.description_long) - component = None - self.suites.append (suite) - suite = Suite () - suite.name = value - suite.distribution = dist - suite.match_name = "^%s$" % value - elif field == 'MatchName': - suite.match_name = value - elif field == 'ParentSuite': - suite.child = True - for nanny in self.suites: - if nanny.name == value: - nanny.children.append(suite) - # reuse some properties of the parent suite - if suite.match_uri == None: - suite.match_uri = nanny.match_uri - if suite.valid_mirrors == None: - suite.valid_mirrors = nanny.valid_mirrors - if suite.base_uri == None: - suite.base_uri = nanny.base_uri - elif field == 'Available': - suite.available = value - elif field == 'RepositoryType': - suite.type = value - elif field == 'BaseURI': - suite.base_uri = value - suite.match_uri = value - elif field == 'MatchURI': - suite.match_uri = value - elif field == 'MirrorsFile': - if os.path.exists(value): - suite.valid_mirrors = filter(lambda s: - ((s != "") and - (not s.startswith("#"))), - map(string.strip, - open(value))) - else: - print "WARNING: can't read '%s'" % value - elif field == 'Description': - suite.description = _(value) - elif field == 'Component': - if component: - suite.components["%s" % component.name] = \ - (component.description, - component.description_long) - component = Component () - component.name = value - elif field == 'CompDescription': - component.description = _(value) - elif field == 'CompDescriptionLong': - component.description_long = _(value) - if suite: - if component: - suite.components["%s" % component.name] = \ - (component.description, - component.description_long) - component = None - self.suites.append (suite) - suite = None - - -if __name__ == "__main__": - d = DistInfo ("Ubuntu", "../../data/channels") - print d.changelogs_uri - for suite in d.suites: - print "\nSuite: %s" % suite.name - print "Desc: %s" % suite.description - print "BaseURI: %s" % suite.base_uri - print "MatchURI: %s" % suite.match_uri - print "Mirrors: %s" % suite.valid_mirrors - for component in suite.components: - print " %s - %s - %s - %s" % (component, - suite.components[component][0], - suite.components[component][1]) - for child in suite.children: - print " %s" % child.description diff --git a/UpdateManager/Common/HelpViewer.py b/UpdateManager/Common/HelpViewer.py deleted file mode 100644 index c8b099cc..00000000 --- a/UpdateManager/Common/HelpViewer.py +++ /dev/null @@ -1,33 +0,0 @@ -# helpviewer.py - -import os -import subprocess - -# Hardcoded list of available help viewers -# FIXME: khelpcenter support would be nice -#KNOWN_VIEWERS = ["/usr/bin/yelp", "/usr/bin/khelpcenter"] -KNOWN_VIEWERS = ["/usr/bin/yelp"] - -class HelpViewer: - def __init__(self, docu): - self.command = [] - self.docu = docu - for viewer in KNOWN_VIEWERS: - if os.path.exists(viewer): - self.command = [viewer, "ghelp:%s" % docu] - break - - def check(self): - """check if a viewer is available""" - if self.command == []: - return False - else: - return True - - def run(self): - """open the documentation in the viewer""" - # avoid running the help viewer as root - if os.getuid() == 0 and os.environ.has_key('SUDO_USER'): - self.command = ['sudo', '-u', os.environ['SUDO_USER']] +\ - self.command - subprocess.Popen(self.command) diff --git a/UpdateManager/Common/Makefile b/UpdateManager/Common/Makefile deleted file mode 100644 index 9409e7e8..00000000 --- a/UpdateManager/Common/Makefile +++ /dev/null @@ -1,350 +0,0 @@ -# Makefile.in generated by automake 1.9.6 from Makefile.am. -# Common/Makefile. Generated from Makefile.in by configure. - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - - -srcdir = . -top_srcdir = .. - -pkgdatadir = $(datadir)/update-manager -pkglibdir = $(libdir)/update-manager -pkgincludedir = $(includedir)/update-manager -top_builddir = .. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = /usr/bin/install -c -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -subdir = Common -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; -am__installdirs = "$(DESTDIR)$(modulesdir)" -modulesDATA_INSTALL = $(INSTALL_DATA) -DATA = $(modules_DATA) -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run aclocal-1.9 -AMDEP_FALSE = # -AMDEP_TRUE = -AMTAR = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run tar -AUTOCONF = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run autoconf -AUTOHEADER = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run autoheader -AUTOMAKE = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run automake-1.9 -AWK = gawk -CATALOGS = da.gmo de.gmo el.gmo en_CA.gmo es.gmo fi.gmo fr.gmo hu.gmo ja.gmo pl.gmo pt_BR.gmo ro.gmo rw.gmo sv.gmo zh_CN.gmo xh.gmo -CATOBJEXT = .gmo -CC = gcc -CCDEPMODE = depmode=none -CFLAGS = -g -O2 -CPP = gcc -E -CPPFLAGS = -CYGPATH_W = echo -DATADIRNAME = share -DEFS = -DHAVE_CONFIG_H -DEPDIR = .deps -ECHO_C = -ECHO_N = -n -ECHO_T = -EGREP = grep -E -EXEEXT = -GETTEXT_PACKAGE = update-manager -GMOFILES = da.gmo de.gmo el.gmo en_CA.gmo es.gmo fi.gmo fr.gmo hu.gmo ja.gmo pl.gmo pt_BR.gmo ro.gmo rw.gmo sv.gmo zh_CN.gmo xh.gmo -GMSGFMT = /usr/bin/msgfmt -INSTALL_DATA = ${INSTALL} -m 644 -INSTALL_PROGRAM = ${INSTALL} -INSTALL_SCRIPT = ${INSTALL} -INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s -INSTOBJEXT = .mo -INTLLIBS = -INTLTOOL_CAVES_RULE = %.caves: %.caves.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_DESKTOP_RULE = %.desktop: %.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_DIRECTORY_RULE = %.directory: %.directory.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_EXTRACT = $(top_builddir)/intltool-extract -INTLTOOL_ICONV = /usr/bin/iconv -INTLTOOL_KBD_RULE = %.kbd: %.kbd.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -m -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_KEYS_RULE = %.keys: %.keys.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -k -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_MERGE = $(top_builddir)/intltool-merge -INTLTOOL_MSGFMT = /usr/bin/msgfmt -INTLTOOL_MSGMERGE = /usr/bin/msgmerge -INTLTOOL_OAF_RULE = %.oaf: %.oaf.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -o -p $(top_srcdir)/po $< $@ -INTLTOOL_PERL = /usr/bin/perl -INTLTOOL_PONG_RULE = %.pong: %.pong.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_PROP_RULE = %.prop: %.prop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_SCHEMAS_RULE = %.schemas: %.schemas.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -s -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_SERVER_RULE = %.server: %.server.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -o -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_SHEET_RULE = %.sheet: %.sheet.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_SOUNDLIST_RULE = %.soundlist: %.soundlist.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_THEME_RULE = %.theme: %.theme.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_UI_RULE = %.ui: %.ui.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_UPDATE = $(top_builddir)/intltool-update -INTLTOOL_XAM_RULE = %.xam: %.xml.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -INTLTOOL_XGETTEXT = /usr/bin/xgettext -INTLTOOL_XML_NOMERGE_RULE = %.xml: %.xml.in $(INTLTOOL_MERGE) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u /tmp $< $@ -INTLTOOL_XML_RULE = %.xml: %.xml.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@ -LDFLAGS = -LIBOBJS = -LIBS = -LTLIBOBJS = -MAINT = # -MAINTAINER_MODE_FALSE = -MAINTAINER_MODE_TRUE = # -MAKEINFO = ${SHELL} /tmp/3/update-manager-0.37.1+svn20050404.15/missing --run makeinfo -MKINSTALLDIRS = ./mkinstalldirs -MSGFMT = /usr/bin/msgfmt -OBJEXT = o -PACKAGE = update-manager -PACKAGE_BUGREPORT = -PACKAGE_NAME = -PACKAGE_STRING = -PACKAGE_TARNAME = -PACKAGE_VERSION = -PATH_SEPARATOR = : -POFILES = da.po de.po el.po en_CA.po es.po fi.po fr.po hu.po ja.po pl.po pt_BR.po ro.po rw.po sv.po zh_CN.po xh.po -POSUB = po -PO_IN_DATADIR_FALSE = -PO_IN_DATADIR_TRUE = -SCROLLKEEPER_BUILD_REQUIRED = 0.3.5 -SCROLLKEEPER_CONFIG = /usr/bin/scrollkeeper-config -SET_MAKE = -SHELL = /bin/sh -STRIP = -USE_NLS = yes -VERSION = 0.37.2 -XGETTEXT = /usr/bin/xgettext -ac_ct_CC = gcc -ac_ct_STRIP = -am__fastdepCC_FALSE = -am__fastdepCC_TRUE = # -am__include = include -am__leading_dot = . -am__quote = -am__tar = ${AMTAR} chof - "$$tardir" -am__untar = ${AMTAR} xf - -bindir = ${exec_prefix}/bin -build_alias = -datadir = ${prefix}/share -exec_prefix = ${prefix} -host_alias = -includedir = ${prefix}/include -infodir = ${prefix}/info -install_sh = /tmp/3/update-manager-0.37.1+svn20050404.15/install-sh -libdir = ${exec_prefix}/lib -libexecdir = ${exec_prefix}/libexec -localstatedir = ${prefix}/var -mandir = ${prefix}/man -mkdir_p = mkdir -p -- -oldincludedir = /usr/include -prefix = /tmp/lala -program_transform_name = s,x,x, -sbindir = ${exec_prefix}/sbin -sharedstatedir = ${prefix}/com -sysconfdir = ${prefix}/etc -target_alias = -modules_DATA = SimpleGladeApp.py DistInfo.py -modulesdir = $(datadir)/update-manager/python -EXTRA_DIST = $(modules_DATA) -all: all-am - -.SUFFIXES: -$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Common/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu Common/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: # $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): # $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -uninstall-info-am: -install-modulesDATA: $(modules_DATA) - @$(NORMAL_INSTALL) - test -z "$(modulesdir)" || $(mkdir_p) "$(DESTDIR)$(modulesdir)" - @list='$(modules_DATA)'; for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - f=$(am__strip_dir) \ - echo " $(modulesDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(modulesdir)/$$f'"; \ - $(modulesDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(modulesdir)/$$f"; \ - done - -uninstall-modulesDATA: - @$(NORMAL_UNINSTALL) - @list='$(modules_DATA)'; for p in $$list; do \ - f=$(am__strip_dir) \ - echo " rm -f '$(DESTDIR)$(modulesdir)/$$f'"; \ - rm -f "$(DESTDIR)$(modulesdir)/$$f"; \ - done -tags: TAGS -TAGS: - -ctags: CTAGS -CTAGS: - - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(DATA) -installdirs: - for dir in "$(DESTDIR)$(modulesdir)"; do \ - test -z "$$dir" || $(mkdir_p) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: install-modulesDATA - -install-exec-am: - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-info-am uninstall-modulesDATA - -.PHONY: all all-am check check-am clean clean-generic distclean \ - distclean-generic distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-exec \ - install-exec-am install-info install-info-am install-man \ - install-modulesDATA install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \ - uninstall-am uninstall-info-am uninstall-modulesDATA - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/UpdateManager/Common/Makefile.am b/UpdateManager/Common/Makefile.am deleted file mode 100644 index e32500bd..00000000 --- a/UpdateManager/Common/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -modules_DATA = SimpleGladeApp.py DistInfo.py -modulesdir = $(datadir)/update-manager/python - - -EXTRA_DIST = $(modules_DATA) diff --git a/UpdateManager/Common/SimpleGladeApp.py b/UpdateManager/Common/SimpleGladeApp.py deleted file mode 100644 index 90c598cc..00000000 --- a/UpdateManager/Common/SimpleGladeApp.py +++ /dev/null @@ -1,341 +0,0 @@ -""" - SimpleGladeApp.py - Module that provides an object oriented abstraction to pygtk and libglade. - Copyright (C) 2004 Sandino Flores Moreno -""" - -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA - -import os -import sys -import re - -import tokenize -import gtk -import gtk.glade -import weakref -import inspect - -__version__ = "1.0" -__author__ = 'Sandino "tigrux" Flores-Moreno' - -def bindtextdomain(app_name, locale_dir=None): - """ - Bind the domain represented by app_name to the locale directory locale_dir. - It has the effect of loading translations, enabling applications for different - languages. - - app_name: - a domain to look for translations, tipically the name of an application. - - locale_dir: - a directory with locales like locale_dir/lang_isocode/LC_MESSAGES/app_name.mo - If omitted or None, then the current binding for app_name is used. - """ - try: - import locale - import gettext - locale.setlocale(locale.LC_ALL, "") - gtk.glade.bindtextdomain(app_name, locale_dir) - gettext.install(app_name, locale_dir, unicode=1) - except (IOError,locale.Error), e: - print "Warning", app_name, e - __builtins__.__dict__["_"] = lambda x : x - - -class SimpleGladeApp: - - def __init__(self, path, root=None, domain=None, **kwargs): - """ - Load a glade file specified by glade_filename, using root as - root widget and domain as the domain for translations. - - If it receives extra named arguments (argname=value), then they are used - as attributes of the instance. - - path: - path to a glade filename. - If glade_filename cannot be found, then it will be searched in the - same directory of the program (sys.argv[0]) - - root: - the name of the widget that is the root of the user interface, - usually a window or dialog (a top level widget). - If None or ommited, the full user interface is loaded. - - domain: - A domain to use for loading translations. - If None or ommited, no translation is loaded. - - **kwargs: - a dictionary representing the named extra arguments. - It is useful to set attributes of new instances, for example: - glade_app = SimpleGladeApp("ui.glade", foo="some value", bar="another value") - sets two attributes (foo and bar) to glade_app. - """ - if os.path.isfile(path): - self.glade_path = path - else: - glade_dir = os.path.dirname( sys.argv[0] ) - self.glade_path = os.path.join(glade_dir, path) - for key, value in kwargs.items(): - try: - setattr(self, key, weakref.proxy(value) ) - except TypeError: - setattr(self, key, value) - self.glade = None - self.install_custom_handler(self.custom_handler) - self.glade = self.create_glade(self.glade_path, root, domain) - if root: - self.main_widget = self.get_widget(root) - else: - self.main_widget = None - self.normalize_names() - self.add_callbacks(self) - self.new() - - def __repr__(self): - class_name = self.__class__.__name__ - if self.main_widget: - root = gtk.Widget.get_name(self.main_widget) - repr = '%s(path="%s", root="%s")' % (class_name, self.glade_path, root) - else: - repr = '%s(path="%s")' % (class_name, self.glade_path) - return repr - - def new(self): - """ - Method called when the user interface is loaded and ready to be used. - At this moment, the widgets are loaded and can be refered as self.widget_name - """ - pass - - def add_callbacks(self, callbacks_proxy): - """ - It uses the methods of callbacks_proxy as callbacks. - The callbacks are specified by using: - Properties window -> Signals tab - in glade-2 (or any other gui designer like gazpacho). - - Methods of classes inheriting from SimpleGladeApp are used as - callbacks automatically. - - callbacks_proxy: - an instance with methods as code of callbacks. - It means it has methods like on_button1_clicked, on_entry1_activate, etc. - """ - self.glade.signal_autoconnect(callbacks_proxy) - - def normalize_names(self): - """ - It is internally used to normalize the name of the widgets. - It means a widget named foo:vbox-dialog in glade - is refered self.vbox_dialog in the code. - - It also sets a data "prefixes" with the list of - prefixes a widget has for each widget. - """ - for widget in self.get_widgets(): - widget_name = gtk.Widget.get_name(widget) - prefixes_name_l = widget_name.split(":") - prefixes = prefixes_name_l[ : -1] - widget_api_name = prefixes_name_l[-1] - widget_api_name = "_".join( re.findall(tokenize.Name, widget_api_name) ) - gtk.Widget.set_name(widget, widget_api_name) - if hasattr(self, widget_api_name): - raise AttributeError("instance %s already has an attribute %s" % (self,widget_api_name)) - else: - setattr(self, widget_api_name, widget) - if prefixes: - gtk.Widget.set_data(widget, "prefixes", prefixes) - - def add_prefix_actions(self, prefix_actions_proxy): - """ - By using a gui designer (glade-2, gazpacho, etc) - widgets can have a prefix in theirs names - like foo:entry1 or foo:label3 - It means entry1 and label3 has a prefix action named foo. - - Then, prefix_actions_proxy must have a method named prefix_foo which - is called everytime a widget with prefix foo is found, using the found widget - as argument. - - prefix_actions_proxy: - An instance with methods as prefix actions. - It means it has methods like prefix_foo, prefix_bar, etc. - """ - prefix_s = "prefix_" - prefix_pos = len(prefix_s) - - is_method = lambda t : callable( t[1] ) - is_prefix_action = lambda t : t[0].startswith(prefix_s) - drop_prefix = lambda (k,w): (k[prefix_pos:],w) - - members_t = inspect.getmembers(prefix_actions_proxy) - methods_t = filter(is_method, members_t) - prefix_actions_t = filter(is_prefix_action, methods_t) - prefix_actions_d = dict( map(drop_prefix, prefix_actions_t) ) - - for widget in self.get_widgets(): - prefixes = gtk.Widget.get_data(widget, "prefixes") - if prefixes: - for prefix in prefixes: - if prefix in prefix_actions_d: - prefix_action = prefix_actions_d[prefix] - prefix_action(widget) - - def custom_handler(self, - glade, function_name, widget_name, - str1, str2, int1, int2): - """ - Generic handler for creating custom widgets, internally used to - enable custom widgets (custom widgets of glade). - - The custom widgets have a creation function specified in design time. - Those creation functions are always called with str1,str2,int1,int2 as - arguments, that are values specified in design time. - - Methods of classes inheriting from SimpleGladeApp are used as - creation functions automatically. - - If a custom widget has create_foo as creation function, then the - method named create_foo is called with str1,str2,int1,int2 as arguments. - """ - try: - handler = getattr(self, function_name) - return handler(str1, str2, int1, int2) - except AttributeError: - return None - - def gtk_widget_show(self, widget, *args): - """ - Predefined callback. - The widget is showed. - Equivalent to widget.show() - """ - widget.show() - - def gtk_widget_hide(self, widget, *args): - """ - Predefined callback. - The widget is hidden. - Equivalent to widget.hide() - """ - widget.hide() - - def gtk_widget_grab_focus(self, widget, *args): - """ - Predefined callback. - The widget grabs the focus. - Equivalent to widget.grab_focus() - """ - widget.grab_focus() - - def gtk_widget_destroy(self, widget, *args): - """ - Predefined callback. - The widget is destroyed. - Equivalent to widget.destroy() - """ - widget.destroy() - - def gtk_window_activate_default(self, window, *args): - """ - Predefined callback. - The default widget of the window is activated. - Equivalent to window.activate_default() - """ - widget.activate_default() - - def gtk_true(self, *args): - """ - Predefined callback. - Equivalent to return True in a callback. - Useful for stopping propagation of signals. - """ - return True - - def gtk_false(self, *args): - """ - Predefined callback. - Equivalent to return False in a callback. - """ - return False - - def gtk_main_quit(self, *args): - """ - Predefined callback. - Equivalent to self.quit() - """ - self.quit() - - def main(self): - """ - Starts the main loop of processing events. - The default implementation calls gtk.main() - - Useful for applications that needs a non gtk main loop. - For example, applications based on gstreamer needs to override - this method with gst.main() - - Do not directly call this method in your programs. - Use the method run() instead. - """ - gtk.main() - - def quit(self): - """ - Quit processing events. - The default implementation calls gtk.main_quit() - - Useful for applications that needs a non gtk main loop. - For example, applications based on gstreamer needs to override - this method with gst.main_quit() - """ - gtk.main_quit() - - def run(self): - """ - Starts the main loop of processing events checking for Control-C. - - The default implementation checks wheter a Control-C is pressed, - then calls on_keyboard_interrupt(). - - Use this method for starting programs. - """ - try: - self.main() - except KeyboardInterrupt: - self.on_keyboard_interrupt() - - def on_keyboard_interrupt(self): - """ - This method is called by the default implementation of run() - after a program is finished by pressing Control-C. - """ - pass - - def install_custom_handler(self, custom_handler): - gtk.glade.set_custom_handler(custom_handler) - - def create_glade(self, glade_path, root, domain): - return gtk.glade.XML(self.glade_path, root, domain) - - def get_widget(self, widget_name): - return self.glade.get_widget(widget_name) - - def get_widgets(self): - return self.glade.get_widget_prefix("") diff --git a/UpdateManager/Common/__init__.py b/UpdateManager/Common/__init__.py deleted file mode 100644 index 139597f9..00000000 --- a/UpdateManager/Common/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/UpdateManager/Common/aptsources.py b/UpdateManager/Common/aptsources.py deleted file mode 100644 index 34b5b967..00000000 --- a/UpdateManager/Common/aptsources.py +++ /dev/null @@ -1,694 +0,0 @@ -# aptsource.py.in - parse sources.list -# -# Copyright (c) 2004-2006 Canonical -# 2004 Michiel Sikkes -# 2006 Sebastian Heinlein -# -# Author: Michiel Sikkes <michiel@eyesopened.nl> -# Michael Vogt <mvo@debian.org> -# Sebastian Heinlein -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA - -import string -import gettext -import re -import apt_pkg -import glob -import shutil -import time -import os.path -import sys - -#import pdb - -#from UpdateManager.Common.DistInfo import DistInfo -from 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 efficient way to return uniq list """ - return list(set(s)) - -class SourceEntry: - """ single sources.list entry """ - def __init__(self, line,file=None): - self.invalid = False # is the source entry valid - self.disabled = False # is it disabled ('#' in front) - self.type = "" # what type (deb, deb-src) - self.uri = "" # base-uri - self.dist = "" # distribution (dapper, edgy, etc) - self.comps = [] # list of available componetns (may empty) - self.comment = "" # (optional) comment - self.line = line # the original sources.list line - if file == None: - file = apt_pkg.Config.FindDir("Dir::Etc")+apt_pkg.Config.Find("Dir::Etc::sourcelist") - self.file = file # the file that the entry is located in - self.parse(line) - self.template = None # type DistInfo.Suite - self.children = [] - - def __eq__(self, other): - """ equal operator for two sources.list entries """ - return (self.disabled == other.disabled and - self.type == other.type and - self.uri == other.uri and - self.dist == other.dist and - self.comps == other.comps) - - - def mysplit(self, line): - """ a split() implementation that understands the sources.list - format better and takes [] into account (for e.g. cdroms) """ - line = string.strip(line) - pieces = [] - tmp = "" - # we are inside a [..] block - p_found = False - space_found = False - for i in range(len(line)): - if line[i] == "[": - p_found=True - tmp += line[i] - elif line[i] == "]": - p_found=False - tmp += line[i] - elif space_found and not line[i].isspace(): # we skip one or more space - space_found = False - pieces.append(tmp) - tmp = line[i] - elif line[i].isspace() and not p_found: # found a whitespace - space_found = True - else: - tmp += line[i] - # append last piece - if len(tmp) > 0: - pieces.append(tmp) - return pieces - - def parse(self,line): - """ parse a given sources.list (textual) line and break it up - into the field we have """ - line = string.strip(self.line) - #print line - # check if the source is enabled/disabled - if line == "" or line == "#": # empty line - self.invalid = True - return - if line[0] == "#": - self.disabled = True - pieces = string.split(line[1:]) - # if it looks not like a disabled deb line return - if not (pieces[0] == "deb" or pieces[0] == "deb-src"): - self.invalid = True - return - else: - line = line[1:] - # check for another "#" in the line (this is treated as a comment) - i = line.find("#") - if i > 0: - self.comment = line[i+1:] - line = line[:i] - # source is ok, split it and see what we have - pieces = self.mysplit(line) - # Sanity check - if len(pieces) < 3: - self.invalid = True - return - # Type, deb or deb-src - self.type = string.strip(pieces[0]) - # Sanity check - if self.type not in ("deb", "deb-src"): - self.invalid = True - return - # URI - self.uri = string.strip(pieces[1]) - if len(self.uri) < 1: - self.invalid = True - # distro and components (optional) - # Directory or distro - self.dist = string.strip(pieces[2]) - if len(pieces) > 3: - # List of components - self.comps = pieces[3:] - else: - self.comps = [] - - def set_enabled(self, new_value): - """ set a line to enabled or disabled """ - self.disabled = not new_value - # enable, remove all "#" from the start of the line - if new_value == True: - i=0 - self.line = string.lstrip(self.line) - while self.line[i] == "#": - i += 1 - self.line = self.line[i:] - else: - # disabled, add a "#" - if string.strip(self.line)[0] != "#": - self.line = "#" + self.line - - def __str__(self): - """ debug helper """ - return self.str().strip() - - def str(self): - """ return the current line as string """ - if self.invalid: - return self.line - line = "" - if self.disabled: - line = "# " - line += "%s %s %s" % (self.type, self.uri, self.dist) - if len(self.comps) > 0: - line += " " + " ".join(self.comps) - if self.comment != "": - line += " #"+self.comment - line += "\n" - return line - -class NullMatcher(object): - """ a Matcher that does nothing """ - def match(self, s): - return True - -class SourcesList: - """ represents the full sources.list + sources.list.d file """ - def __init__(self, - withMatcher=True, - matcherPath="/usr/share/update-manager/channels/"): - self.list = [] # the actual SourceEntries Type - if withMatcher: - self.matcher = SourceEntryMatcher(matcherPath) - else: - self.matcher = NullMatcher() - self.refresh() - - def refresh(self): - """ update the list of known entries """ - self.list = [] - # read sources.list - dir = apt_pkg.Config.FindDir("Dir::Etc") - file = apt_pkg.Config.Find("Dir::Etc::sourcelist") - self.load(dir+file) - # read sources.list.d - partsdir = apt_pkg.Config.FindDir("Dir::Etc::sourceparts") - for file in glob.glob("%s/*.list" % partsdir): - self.load(file) - # check if the source item fits a predefined template - for source in self.list: - if source.invalid == False: - self.matcher.match(source) - - def __iter__(self): - """ simple iterator to go over self.list, returns SourceEntry - types """ - for entry in self.list: - yield entry - raise StopIteration - - def add(self, type, uri, dist, comps, comment="", pos=-1, file=None): - """ - Add a new source to the sources.list. - The method will search for existing matching repos and will try to - reuse them as far as possible - """ - # check if we have this source already in the sources.list - for source in self.list: - if source.disabled == False and source.invalid == False and \ - source.type == type and uri == source.uri and \ - source.dist == dist: - for new_comp in comps: - if new_comp in source.comps: - # we have this component already, delete it from the new_comps - # list - del comps[comps.index(new_comp)] - if len(comps) == 0: - return source - for source in self.list: - # if there is a repo with the same (type, uri, dist) just add the - # components - if source.disabled == False and source.invalid == False and \ - source.type == type and uri == source.uri and \ - source.dist == dist: - comps = uniq(source.comps + comps) - source.comps = comps - return source - # if there is a corresponding repo which is disabled, enable it - elif source.disabled == True and source.invalid == False and \ - source.type == type and uri == source.uri and \ - source.dist == dist and \ - len(set(source.comps) & set(comps)) == len(comps): - source.disabled = False - return source - # there isn't any matching source, so create a new line and parse it - 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" - new_entry = SourceEntry(line) - if file != None: - new_entry.file = file - self.matcher.match(new_entry) - self.list.insert(pos, new_entry) - return new_entry - - def remove(self, source_entry): - """ remove the specified entry from the sources.list """ - self.list.remove(source_entry) - - def restoreBackup(self, backup_ext): - " restore sources.list files based on the backup extension " - dir = apt_pkg.Config.FindDir("Dir::Etc") - file = apt_pkg.Config.Find("Dir::Etc::sourcelist") - if os.path.exists(dir+file+backup_ext): - shutil.copy(dir+file+backup_ext,dir+file) - # now sources.list.d - partsdir = apt_pkg.Config.FindDir("Dir::Etc::sourceparts") - for file in glob.glob("%s/*.list" % partsdir): - if os.path.exists(file+backup_ext): - shutil.copy(file+backup_ext,file) - - def backup(self, backup_ext=None): - """ make a backup of the current source files, if no backup extension - is given, the current date/time is used (and returned) """ - already_backuped = set() - if backup_ext == None: - backup_ext = time.strftime("%y%m%d.%H%M") - for source in self.list: - if not source.file in already_backuped: - shutil.copy(source.file,"%s%s" % (source.file,backup_ext)) - return backup_ext - - def load(self,file): - """ (re)load the current sources """ - try: - f = open(file, "r") - lines = f.readlines() - for line in lines: - source = SourceEntry(line,file) - self.list.append(source) - except: - print "could not open file '%s'" % file - else: - f.close() - - def save(self): - """ save the current sources """ - files = {} - for source in self.list: - if not files.has_key(source.file): - files[source.file]=open(source.file,"w") - files[source.file].write(source.str()) - for f in files: - files[f].close() - - def check_for_relations(self, sources_list): - """get all parent and child channels in the sources list""" - parents = [] - used_child_templates = {} - for source in sources_list: - # try to avoid checking uninterressting sources - if source.template == None: - continue - # set up a dict with all used child templates and corresponding - # source entries - if source.template.child == True: - key = source.template - if not used_child_templates.has_key(key): - used_child_templates[key] = [] - temp = used_child_templates[key] - temp.append(source) - else: - # store each source with children aka. a parent :) - if len(source.template.children) > 0: - parents.append(source) - #print self.used_child_templates - #print self.parents - return (parents, used_child_templates) - -# matcher class to make a source entry look nice -# lots of predefined matchers to make it i18n/gettext friendly -class SourceEntryMatcher: - class MatchType: - def __init__(self, a_type,a_descr): - self.type = a_type - self.description = a_descr - - class MatchDist: - def __init__(self,a_uri,a_dist, a_descr,l_comps, l_comps_descr): - self.uri = a_uri - self.dist = a_dist - self.description = a_descr - self.comps = l_comps - self.comps_descriptions = l_comps_descr - - def __init__(self, matcherPath): - self.templates = [] - # Get the human readable channel and comp names from the channel .infos - spec_files = glob.glob("%s/*.info" % matcherPath) - for f in spec_files: - f = os.path.basename(f) - i = f.find(".info") - f = f[0:i] - dist = DistInfo(f,base_dir=matcherPath) - for suite in dist.suites: - if suite.match_uri != None: - self.templates.append(suite) - return - - def match(self, source): - """Add a matching template to the source""" - _ = gettext.gettext - found = False - for template in self.templates: - if (re.search(template.match_uri, source.uri) and - re.match(template.match_name, source.dist)): - found = True - source.template = template - break - for mirror in template.valid_mirrors: - if (is_mirror(mirror,source.uri) and - re.match(template.match_name, source.dist)): - found = True - source.template = template - 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 -s" % 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.default_server = "" - 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.invalid == False and\ - source.template in self.source_template.children: - if source.disabled == False and source.type == "deb": - self.child_sources.append(source) - elif source.disabled == False and source.type == "deb-src": - self.source_code_sources.append(source) - else: - self.disabled_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 - if self.countries.has_key(country_code): - self.country = self.countries[country_code] - else: - self.country = None - - # 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) - - if len(self.main_sources) == 0: - self.default_server = self.main_server - else: - self.default_server = self.main_sources[0].uri - - 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.default_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): - """ - Enable 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 - """ - def add_component_only_once(source, comps_per_dist): - """ - Check if we already added the component to the repository, since - a repository could be splitted into different apt lines. If not - add the component - """ - # if we don't that distro, just reutnr (can happen for e.g. - # dapper-update only in deb-src - if not comps_per_dist.has_key(source.dist): - return - # if we have seen this component already for this distro, - # return (nothing to do - if comp in comps_per_dist[source.dist]: - return - # add it - source.comps.append(comp) - comps_per_dist[source.dist].add(comp) - - sources = [] - sources.extend(self.main_sources) - sources.extend(self.child_sources) - sources.extend(self.source_code_sources) - # store what comps are enabled already per distro (where distro is - # e.g. "dapper", "dapper-updates") - comps_per_dist = {} - for s in sources: - if s.type != "deb": - continue - if not comps_per_dist.has_key(s.dist): - comps_per_dist[s.dist] = set() - map(comps_per_dist[s.dist].add, s.comps) - # 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: - add_component_only_once(source, comps_per_dist) - - # now do the same for source dists - if self.get_source_code == True: - comps_per_dist = {} - for s in self.source_code_sources: - if s.type != "deb-src": - continue - if not comps_per_dist.has_key(s.dist): - comps_per_dist[s.dist] = set() - map(comps_per_dist[s.dist].add, s.comps) - for source in self.source_code_sources: - if comp not in source.comps: - add_component_only_once(source, comps_per_dist) - - - 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() - sources = SourcesList() - - for entry in sources: - print entry.str() - #print entry.uri - - mirror = is_mirror("http://archive.ubuntu.com/ubuntu/", - "http://de.archive.ubuntu.com/ubuntu/") - print "is_mirror(): %s" % mirror - - print 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/UpdateManager/Common/utils.py b/UpdateManager/Common/utils.py deleted file mode 100644 index 1fcd022f..00000000 --- a/UpdateManager/Common/utils.py +++ /dev/null @@ -1,42 +0,0 @@ -import gtk -from gettext import gettext as _ -import locale - -def str_to_bool(str): - if str == "0" or str.upper() == "FALSE": - return False - return True - -def utf8(str): - return unicode(str, 'latin1').encode('utf-8') - - -def error(parent, summary, message): - d = gtk.MessageDialog(parent=parent, - flags=gtk.DIALOG_MODAL, - type=gtk.MESSAGE_ERROR, - buttons=gtk.BUTTONS_CLOSE) - d.set_markup("<big><b>%s</b></big>\n\n%s" % (summary, message)) - d.realize() - d.window.set_functions(gtk.gdk.FUNC_MOVE) - d.set_title("") - res = d.run() - d.destroy() - return - -def humanize_size(bytes): - """ - Convert a given size in bytes to a nicer better readable unit - """ - if bytes == 0: - # TRANSLATORS: download size is 0 - return _("None") - elif bytes < 1024: - # TRANSLATORS: download size of very small updates - return _("1 KB") - elif bytes < 1024 * 1024: - # TRANSLATORS: download size of small updates, e.g. "250 KB" - return locale.format(_("%.0f KB"), bytes/1024) - else: - # TRANSLATORS: download size of updates, e.g. "2.3 MB" - return locale.format(_("%.1f MB"), bytes / 1024 / 1024) |
