From 3ee70c61924e65e3c4ef6bf0fa0673d2e866b042 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Mon, 5 Feb 2007 09:19:39 +0100 Subject: * write an empty default sources.list if all sources have been removed --- aptsources/distro.py | 1 - aptsources/sourceslist.py | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/aptsources/distro.py b/aptsources/distro.py index 5b4c6522..f53783dc 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -244,7 +244,6 @@ class Distribution: 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) diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 14c2a0ea..e5b8dab9 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -342,6 +342,15 @@ class SourcesList: def save(self): """ save the current sources """ files = {} + # write an empty default config file if there aren't any sources + if len(self.list) == 0: + path = "%s%s" % (apt_pkg.Config.FindDir("Dir::Etc"), + apt_pkg.Config.Find("Dir::Etc::sourcelist")) + header = ("## See sources.list(5) for more information, especialy\n" + "# Remember that you can only use http, ftp or file URIs\n" + "# CDROMs are managed through the apt-cdrom tool.\n") + open(path,"w").write(header) + return for source in self.list: if not files.has_key(source.file): files[source.file]=open(source.file,"w") -- cgit v1.2.3 From e2b1181b6600d5dfb1f5e1ebd31d89ee9229db8c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 6 Feb 2007 14:40:45 +0100 Subject: * better cdrom support merged --- apt/__init__.py | 1 + apt/cdrom.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ apt/progress.py | 2 ++ debian/changelog | 7 +++++++ 4 files changed, 58 insertions(+) create mode 100644 apt/cdrom.py diff --git a/apt/__init__.py b/apt/__init__.py index 15df6990..c6a2ff39 100644 --- a/apt/__init__.py +++ b/apt/__init__.py @@ -7,6 +7,7 @@ import os from apt.package import Package from apt.cache import Cache from apt.progress import OpProgress, FetchProgress, InstallProgress, CdromProgress +from apt.cdrom import Cdrom from apt_pkg import SizeToStr, TimeToStr, VersionCompare # init the package system diff --git a/apt/cdrom.py b/apt/cdrom.py new file mode 100644 index 00000000..d499b30a --- /dev/null +++ b/apt/cdrom.py @@ -0,0 +1,48 @@ + +import apt_pkg +from apt.progress import CdromProgress + +class Cdrom(object): + def __init__(self, progress=None, mountpoint=None, nomount=True): + """ Support for apt-cdrom like features. + Options: + - progress: optional progress.CdromProgress() subclass + - mountpoint: optional alternative mountpoint + - nomount: do not mess with mount/umount the CD + """ + self._cdrom = apt_pkg.GetCdrom() + if progress is None: + self._progress = apt.progress.CdromProgress() + else: + self._progress = progress + # see if we have a alternative mountpoint + if mountpoint is not None: + apt_pkg.Config.Set("Acquire::cdrom::mount",mountpoint) + # do not mess with mount points by default + if nomount is True: + apt_pkg.Config.Set("APT::CDROM::NoMount", "true") + else: + apt_pkg.Config.Set("APT::CDROM::NoMount", "false") + def add(self): + " add cdrom to the sources.list " + return self._cdrom.Add(self._progress) + def ident(self): + " identify the cdrom " + (res, ident) = self._cdrom.Ident(self._progress) + if res: + return ident + return None + @property + def inSourcesList(self): + " check if the cdrom is already in the current sources.list " + cdid = self.ident() + if cdid is None: + # FIXME: throw exception instead + return False + # FIXME: check sources.list.d/ as well + for line in open(apt_pkg.Config.FindFile("Dir::Etc::sourcelist")): + line = line.strip() + if not line.startswith("#") and cdid in line: + return True + return False + diff --git a/apt/progress.py b/apt/progress.py index 5169adf7..bb1bce35 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -28,6 +28,8 @@ from errno import * import select import apt_pkg +import apt + class OpProgress(object): """ Abstract class to implement reporting on cache opening Subclass this class to implement simple Operation progress reporting diff --git a/debian/changelog b/debian/changelog index 79e6d078..da487377 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.6.21) unstable; urgency=low + + * apt/cdrom.py: + - better cdrom handling support + + -- + python-apt (0.6.20) unstable; urgency=low * python/generic.h: -- cgit v1.2.3 From fb94875bd4e108c6d22e05d5312de7ed9f86b057 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 Feb 2007 15:31:00 +0100 Subject: * python/string.cc: - SizeToString supports PyLong too --- debian/changelog | 2 ++ python/string.cc | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index da487377..7833dc00 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ python-apt (0.6.21) unstable; urgency=low * apt/cdrom.py: - better cdrom handling support + * python/string.cc: + - SizeToString supports PyLong too -- diff --git a/python/string.cc b/python/string.cc index 16adc8cd..d0926da5 100644 --- a/python/string.cc +++ b/python/string.cc @@ -53,9 +53,11 @@ PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"O",&Obj) == 0) return 0; if (PyInt_Check(Obj)) - return CppPyString(SizeToStr(PyInt_AS_LONG(Obj))); + return CppPyString(SizeToStr(PyInt_AsLong(Obj))); + if (PyLong_Check(Obj)) + return CppPyString(SizeToStr(PyLong_AsLong(Obj))); if (PyFloat_Check(Obj)) - return CppPyString(SizeToStr(PyFloat_AS_DOUBLE(Obj))); + return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); return 0; -- cgit v1.2.3 From 89ac70a4cdc9507e6db3921497680aea95b6a7c2 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Mon, 26 Feb 2007 20:13:42 +0100 Subject: * separate the checking of duplicates of binary and source repositories when changing the server of the distro - fix LP #86219 --- aptsources/distro.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/aptsources/distro.py b/aptsources/distro.py index f53783dc..ac1b53e7 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -253,13 +253,7 @@ class Distribution: def change_server(self, uri): ''' Change the server of all distro specific sources to a given host ''' - sources = [] - seen = [] - self.default_server = uri - sources.extend(self.main_sources) - sources.extend(self.child_sources) - sources.extend(self.source_code_sources) - for source in sources: + def change_server_of_source(source, uri, seen): # Avoid creating duplicate entries source.uri = uri for comp in source.comps: @@ -269,6 +263,16 @@ class Distribution: seen.append([source.uri, source.dist, comp]) if len(source.comps) < 1: self.sourceslist.remove(source) + seen_binary = [] + seen_source = [] + self.default_server = uri + sources = [] + sources.extend(self.main_sources) + sources.extend(self.child_sources) + for source in sources: + change_server_of_source(source, uri, seen_binary) + for source in self.source_code_sources: + change_server_of_source(source, uri, seen_source) def is_codename(self, name): ''' Compare a given name with the release codename. ''' @@ -276,13 +280,13 @@ class Distribution: return True else: return False - + def get_server_list(self): ''' Return a list of used and suggested servers ''' # Store all available servers: # Name, URI, active mirrors = [] - + mirrors.append([_("Main server"), self.main_server, len(self.used_servers) == 1 and self.used_servers[0] == self.main_server]) -- cgit v1.2.3