diff options
| -rw-r--r-- | apt/__init__.py | 1 | ||||
| -rw-r--r-- | apt/cdrom.py | 48 | ||||
| -rw-r--r-- | apt/progress.py | 2 | ||||
| -rw-r--r-- | aptsources/distro.py | 23 | ||||
| -rw-r--r-- | aptsources/sourceslist.py | 9 | ||||
| -rw-r--r-- | debian/changelog | 9 | ||||
| -rw-r--r-- | python/string.cc | 6 |
7 files changed, 86 insertions, 12 deletions
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/aptsources/distro.py b/aptsources/distro.py index 5b4c6522..ac1b53e7 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) @@ -254,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: @@ -270,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. ''' @@ -277,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]) diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 800f462f..208e6c7d 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") diff --git a/debian/changelog b/debian/changelog index 79e6d078..7833dc00 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +python-apt (0.6.21) unstable; urgency=low + + * apt/cdrom.py: + - better cdrom handling support + * python/string.cc: + - SizeToString supports PyLong too + + -- + python-apt (0.6.20) unstable; urgency=low * python/generic.h: 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; |
