diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-06-05 15:00:15 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-06-05 15:00:15 +0200 |
| commit | 14dfadc054e9bdafd2507dbca70dbec925471ae0 (patch) | |
| tree | 8d2c0e85fde3010267e87d14f4f88cb352b23a0e | |
| parent | cdabff6d329baba8024224b362f79d822ddd943e (diff) | |
| download | python-apt-14dfadc054e9bdafd2507dbca70dbec925471ae0.tar.gz | |
Introduce the rename rules formally, and add some exceptions.
| -rw-r--r-- | apt/cache.py | 4 | ||||
| -rw-r--r-- | apt/package.py | 10 | ||||
| -rw-r--r-- | doc/source/apt_pkg.rst | 36 | ||||
| -rw-r--r-- | doc/source/examples/cache-pkgfile.py | 2 | ||||
| -rw-r--r-- | doc/source/whatsnew/0.8.0.rst | 82 | ||||
| -rw-r--r-- | python/acquire.cc | 10 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 16 | ||||
| -rw-r--r-- | python/cache.cc | 2 | ||||
| -rw-r--r-- | python/configuration.cc | 2 | ||||
| -rw-r--r-- | python/depcache.cc | 4 | ||||
| -rw-r--r-- | python/pkgrecords.cc | 2 |
11 files changed, 124 insertions, 46 deletions
diff --git a/apt/cache.py b/apt/cache.py index 56b32d45..8590510c 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -170,8 +170,8 @@ class Cache(object): reqreinst = set() for pkg in self: if (not pkg.candidate.downloadable and - (pkg._pkg.inst_state == apt_pkg.INSTSTATE_RE_INST_REQ or - pkg._pkg.inst_state == apt_pkg.INSTSTATE_HOLD_RE_INST_REQ)): + (pkg._pkg.inst_state == apt_pkg.INSTSTATE_REINSTREQ or + pkg._pkg.inst_state == apt_pkg.INSTSTATE_HOLD_REINSTREQ)): reqreinst.add(pkg.name) return reqreinst diff --git a/apt/package.py b/apt/package.py index a24486e1..48d14595 100644 --- a/apt/package.py +++ b/apt/package.py @@ -379,7 +379,7 @@ class Version(object): .. versionadded:: 0.7.10 """ - return self._records.file_name + return self._records.filename @property def md5(self): @@ -413,7 +413,7 @@ class Version(object): for (packagefile, index) in self._cand.file_list: indexfile = self.package._pcache._list.find_index(packagefile) if indexfile: - yield indexfile.archive_uri(self._records.file_name) + yield indexfile.archive_uri(self._records.filename) @property def uris(self): @@ -443,19 +443,19 @@ class Version(object): .. versionadded:: 0.7.10 """ - base = os.path.basename(self._records.file_name) + base = os.path.basename(self._records.filename) destfile = os.path.join(destdir, base) if _file_is_same(destfile, self.size, self._records.md5_hash): print 'Ignoring already existing file:', destfile return acq = apt_pkg.Acquire(progress or apt.progress.TextFetchProgress()) apt_pkg.AcquireFile(acq, self.uri, self._records.md5_hash, self.size, - base, dest_file=destfile) + base, destfile=destfile) acq.run() for item in acq.items: if item.status != item.stat_done: raise FetchError("The item %r could not be fetched: %s" % - (item.dest_file, item.error_text)) + (item.destfile, item.error_text)) return os.path.abspath(destfile) def fetch_source(self, destdir="", progress=None, unpack=True): diff --git a/doc/source/apt_pkg.rst b/doc/source/apt_pkg.rst index 39b48c35..c814615c 100644 --- a/doc/source/apt_pkg.rst +++ b/doc/source/apt_pkg.rst @@ -167,7 +167,7 @@ Working with the cache If *from_user* is ``True``, the package will be marked as manually installed. This is the default. - .. method:: set_re_install(pkg) + .. method:: set_reinstall(pkg) Set if the :class:`Package` *pkg* should be reinstalled. @@ -398,7 +398,7 @@ Resolving Dependencies The component (eg. main) - .. attribute:: file_name + .. attribute:: filename The name of the file. @@ -430,7 +430,7 @@ Resolving Dependencies for pkgfile in cache.file_list: if pkgfile.not_source: - print 'The file %s has no source.' % pkgfile.file_name + print 'The file %s has no source.' % pkgfile.filename .. attribute:: origin @@ -809,7 +809,7 @@ Records # Now you can access the record print records.SourcePkg # == python-apt - .. attribute:: file_name + .. attribute:: filename Return the field 'Filename' of the record. This is the path to the package, relative to the base path of the archive. @@ -1103,7 +1103,7 @@ installation. Constant for comparing :attr:`AcquireItem.status` -.. class:: AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir, dest_file]) +.. class:: AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir, destfile]) Create a new :class:`AcquireFile()` object and register it with *acquire*, so it will be fetched. AcquireFile objects provide no methods or attributes @@ -1126,9 +1126,9 @@ installation. used to describe the item in the progress class. *short_descr* is the short form of it. - You can use *dest_dir* to manipulate the directory where the file will - be saved in. Instead of *dest_dir*, you can also specify the full path to - the file using the parameter *dest_file*. You can not combine both. + You can use *destdir* to manipulate the directory where the file will + be saved in. Instead of *destdir*, you can also specify the full path to + the file using the parameter *destfile*. You can not combine both. @@ -1379,7 +1379,7 @@ Configuration Check whether the key *key* exists in the configuration. - .. method:: sub_tree(key) + .. method:: subtree(key) Return a sub tree starting at *key*. The resulting object can be used like this one. @@ -1429,7 +1429,7 @@ Configuration Behaves like a :class:`Configuration()` objects, but provides access to a subsection of another Configuration-like object. This type of object is - returned by the :meth:`Configuration.sub_tree()` method. + returned by the :meth:`Configuration.subtree()` method. .. data:: config @@ -1459,7 +1459,7 @@ Modifying the settings therein to the :class:`Configuration()` object specified by the parameter *configuration* -.. function:: parse_command_line(configuration, options, argv) +.. function:: parse_commandline(configuration, options, argv) This function is like getopt except it manipulates a configuration space. output is a list of non-option arguments (filenames, etc). *options* is a @@ -1541,11 +1541,11 @@ String functions apt_pkg.check_domain_list("alioth.debian.org","debian.net,debian.org") -.. function:: de_quote_string(string) +.. function:: dequote_string(string) Dequote the string specified by the parameter *string*, e.g.:: - >>> apt_pkg.DeQuoteString("%61%70%74%20is%20cool") + >>> apt_pkg.dequote_string("%61%70%74%20is%20cool") 'apt is cool' .. function:: quote_string(string, repl) @@ -1627,14 +1627,14 @@ String functions Return the string *version*, eliminating everything following the last '-'. Thus, this should be equivalent to ``version.rsplit('-', 1)[0]``. -.. function:: uri_to_file_name(uri) +.. function:: uri_to_filename(uri) Take a string *uri* as parameter and return a filename which can be used to store the file, based on the URI. Example:: - >>> apt_pkg.uri_to_file_name('http://debian.org/index.html') + >>> apt_pkg.uri_to_filename('http://debian.org/index.html') 'debian.org_index.html' @@ -1667,7 +1667,7 @@ Package States .. data:: CURSTATE_HALF_INSTALLED .. data:: CURSTATE_INSTALLED .. data:: CURSTATE_NOT_INSTALLED -.. data:: CURSTATE_UN_PACKED +.. data:: CURSTATE_UNPACKED @@ -1687,9 +1687,9 @@ Dependency types Installed states ^^^^^^^^^^^^^^^^ .. data:: INSTSTATE_HOLD -.. data:: INSTSTATE_HOLD_RE_INST_REQ +.. data:: INSTSTATE_HOLD_REINSTREQ .. data:: INSTSTATE_OK -.. data:: INSTSTATE_RE_INST_REQ +.. data:: INSTSTATE_REINSTREQ .. _Priorities: diff --git a/doc/source/examples/cache-pkgfile.py b/doc/source/examples/cache-pkgfile.py index 1300a55c..f4cc2e66 100644 --- a/doc/source/examples/cache-pkgfile.py +++ b/doc/source/examples/cache-pkgfile.py @@ -7,7 +7,7 @@ def main(): apt_pkg.init() cache = apt_pkg.Cache() for pkgfile in cache.file_list: - print 'Package-File:', pkgfile.file_name + print 'Package-File:', pkgfile.filename print 'Index-Type:', pkgfile.index_type # 'Debian Package Index' if pkgfile.not_source: print 'Source: None' diff --git a/doc/source/whatsnew/0.8.0.rst b/doc/source/whatsnew/0.8.0.rst index d1ac3ac5..d507e82a 100644 --- a/doc/source/whatsnew/0.8.0.rst +++ b/doc/source/whatsnew/0.8.0.rst @@ -15,19 +15,97 @@ Python-apt is the first Debian package to support the third major release of Python. The port is straight forward and integrates as nicely in Python 3 as the Python 2 builds integrate in Python 2. +Please be aware that python-apt builds for Python 3 are built without the +compatibility options enabled for Python 2 builds. They also do not provide +methods like :meth:`has_key` on mapping objects, because it has been removed +in Python 3. + Real classes in :mod:`apt_pkg` ------------------------------ +The 0.8 release introduces real classes in the :mod:`apt_pkg` extension. This +is an important step forward and makes writing code much easier, because you +can see the classes without having to create an object first. It also makes +it easier to talk about those classes, because they have a real name now. + +The 0.7 series shipped many functions for creating new objects, because the +classes were not exported. In 0.8, the classes themselves replace those +functions, as you can see in the following table. + +.. table:: + + ===================================== ================================= + Function Replacing class + ===================================== ================================= + :func:`apt_pkg.GetAcquire` :class:`apt_pkg.Acquire` + :func:`apt_pkg.GetCache()` :class:`apt_pkg.Cache` + :func:`apt_pkg.GetCdrom()` :class:`apt_pkg.Cdrom` + :func:`apt_pkg.GetDepCache()` :class:`apt_pkg.DepCache` + :func:`apt_pkg.GetPackageManager` :class:`apt_pkg.PackageManager` + :func:`apt_pkg.GetPkgAcqFile` :class:`apt_pkg.AcquireFile` + :func:`apt_pkg.GetPkgActionGroup` :class:`apt_pkg.ActionGroup` + :func:`apt_pkg.GetPkgProblemResolver` :class:`apt_pkg.ProblemResolver` + :func:`apt_pkg.GetPkgRecords` :class:`apt_pkg.PackageRecords` + :func:`apt_pkg.GetPkgSourceList` :class:`apt_pkg.SourceList` + :func:`apt_pkg.GetPkgSrcRecords` :class:`apt_pkg.SourceRecords` + :func:`apt_pkg.ParseSection` :class:`apt_pkg.TagSection` + :func:`apt_pkg.ParseTagFile` :class:`apt_pkg.TagFile` + ===================================== ================================= Complete rename of functions, methods and attributes ----------------------------------------------------- +In May 2008, Ben Finney reported bug 481061 against the python-apt package, +asking for PEP8 conformant names. With the release of python-apt 0.8, this +is finally happening. Supporting new language features like the :keyword:`with` statement ------------------------------------------------------------------- +This is not a real big change, but it's good to have it: +:class:`apt_pkg.ActionGroup` can now be used as a context manager for the +:keyword:`with` statement. This makes it more obvious that you are using an +action group, and is just cooler:: + + with apt_pkg.ActionGroup(depcache): + for package in my_selected_packages: + depcache.mark_install(package) + +This also works for :class:`apt.Cache`:: + + with cache.action_group(): # cache is an Instance of apt.Cache + for package in my_selected_packages: + package.mark_install() # Instance of apt.Package + Other changes ------------- This release of python-apt also features several other, smaller changes: - * Reduced memory usage by creating Package() objects in apt.Cache() only - when needed. + * Reduced memory usage by making :class:`apt.Cache` create + :class:`apt.Package()` object dynamically, instead of creating all of + them during the cache initialization. * Support to set the candidate version in :class:`apt.package.Package` + +Porting your applications to python-apt 0.8 +------------------------------------------- +Porting your application to python-apt 0.8 may be trivial. You should download +the source tarball of python-apt and run the tool utils/migrate-0.8 using +Python 2.6 over your code:: + + python2.6 utils/migrate-0.8.py -c myapp.py mypackage/ + +This will search your code for places where possibly deprecated names are +used. Using the argument ``-c``, you can turn colorized output on. + +Now that you know which parts of your code have to be changed, you have to know +how to do this. For classes, please look at the table. For all attributes, +methods, functions, and their parameters the following rules apply: + + 1. Replace leading [A-Z] with [a-z] (e.g DescURI => descURI) + 2. Replace multiple [A-Z] with [A-Z][a-z] (e.g. descURI => descUri) + 3. Replace every [A-Z] with the corresponding [a-z] (descUri => desc_uri) + +As an exception, refixes such as 'de' (e.g. 'dequote') or 'un' (e.g. 'unlock') +are normally not seperated by underscores from the next word. There are also +some other exceptions which are listed here, and apply to any name containing +this word: **filename**, **filesize**, **destdir**, **destfile**, **dequote**, +**unlock**, **reinstall**, **pinfile**, **REINSTREQ**, **UNPACKED**, +**parse_commandline**. diff --git a/python/acquire.cc b/python/acquire.cc index 1b1c5dd8..5f38f7bd 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -40,9 +40,9 @@ MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthE static PyGetSetDef AcquireItemGetSet[] = { {"complete",AcquireItemGetComplete}, {"desc_uri",AcquireItemGetDescURI}, - {"dest_file",AcquireItemGetDestFile}, + {"destfile",AcquireItemGetDestFile}, {"error_text",AcquireItemGetErrorText}, - {"file_size",AcquireItemGetFileSize}, + {"filesize",AcquireItemGetFileSize}, {"is",AcquireItemGetID}, {"is_trusted",AcquireItemGetIsTrusted}, {"local",AcquireItemGetLocal}, @@ -310,7 +310,7 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject int size = 0; uri = md5 = descr = shortDescr = destDir = destFile = ""; - char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortdescr", + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "short_descr", "destdir", "destfile", NULL}; if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, @@ -335,8 +335,8 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject static char *doc_PkgAcquireFile = - "AcquireFile(owner, uri[, md5, size, descr, short_descr, dest_dir," - "dest_file]) -> New AcquireFile() object\n\n" + "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir," + "destfile]) -> New AcquireFile() object\n\n" "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" "*destdir* OR *destfile* to specify the destination directory/file."; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index bfabc652..403e0ebf 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -407,7 +407,7 @@ static PyMethodDef methods[] = // Locking {"get_lock",GetLock,METH_VARARGS,doc_GetLock}, {"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, - {"pkgsystem_un_lock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, + {"pkgsystem_unlock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, #ifdef COMPAT_0_7 {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, @@ -418,7 +418,7 @@ static PyMethodDef methods[] = {"read_config_file",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"read_config_dir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, {"read_config_file_isc",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, - {"parse_command_line",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, + {"parse_commandline",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, #ifdef COMPAT_0_7 {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, @@ -452,10 +452,10 @@ static PyMethodDef methods[] = // Strings {"check_domain_list",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"quote_string",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, - {"de_quote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, + {"dequote_string",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, {"size_to_str",StrSizeToStr,METH_VARARGS,"SizeToStr(int) -> String"}, {"time_to_str",StrTimeToStr,METH_VARARGS,"TimeToStr(int) -> String"}, - {"uri_to_file_name",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, + {"uri_to_filename",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, {"base64_encode",StrBase64Encode,METH_VARARGS,"Base64Encode(String) -> String"}, {"string_to_bool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"time_rfc1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, @@ -657,7 +657,7 @@ extern "C" void initapt_pkg() #endif // CurState PyModule_AddIntConstant(Module,"CURSTATE_NOT_INSTALLED",pkgCache::State::NotInstalled); - PyModule_AddIntConstant(Module,"CURSTATE_UN_PACKED",pkgCache::State::UnPacked); + PyModule_AddIntConstant(Module,"CURSTATE_UNPACKED",pkgCache::State::UnPacked); PyModule_AddIntConstant(Module,"CURSTATE_HALF_CONFIGURED",pkgCache::State::HalfConfigured); PyModule_AddIntConstant(Module,"CURSTATE_HALF_INSTALLED",pkgCache::State::HalfInstalled); PyModule_AddIntConstant(Module,"CURSTATE_CONFIG_FILES",pkgCache::State::ConfigFiles); @@ -666,13 +666,13 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"SELSTATE_UNKNOWN",pkgCache::State::Unknown); PyModule_AddIntConstant(Module,"SELSTATE_INSTALL",pkgCache::State::Install); PyModule_AddIntConstant(Module,"SELSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"SELSTATE_DE_INSTALL",pkgCache::State::DeInstall); + PyModule_AddIntConstant(Module,"SELSTATE_DEINSTALL",pkgCache::State::DeInstall); PyModule_AddIntConstant(Module,"SELSTATE_PURGE",pkgCache::State::Purge); // InstState PyModule_AddIntConstant(Module,"INSTSTATE_OK",pkgCache::State::Ok); - PyModule_AddIntConstant(Module,"INSTSTATE_RE_INST_REQ",pkgCache::State::ReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_REINSTREQ",pkgCache::State::ReInstReq); PyModule_AddIntConstant(Module,"INSTSTATE_HOLD",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_RE_INST_REQ",pkgCache::State::HoldReInstReq); + PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq); #ifdef COMPAT_0_7 PyModule_AddIntConstant(Module,"CurStateNotInstalled",pkgCache::State::NotInstalled); diff --git a/python/cache.cc b/python/cache.cc index 21a6a872..d09e22f3 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -1030,7 +1030,7 @@ static PyGetSetDef PackageFileGetSet[] = { {(char*)"architecture",PackageFile_GetArchitecture}, {(char*)"archive",PackageFile_GetArchive}, {(char*)"component",PackageFile_GetComponent}, - {(char*)"file_name",PackageFile_GetFileName}, + {(char*)"filename",PackageFile_GetFileName}, {(char*)"id",PackageFile_GetID}, {(char*)"index_type",PackageFile_GetIndexType}, {(char*)"label",PackageFile_GetLabel}, diff --git a/python/configuration.cc b/python/configuration.cc index 7b08d90e..81dd78ac 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -462,7 +462,7 @@ static PyMethodDef CnfMethods[] = // Others {"set",CnfSet,METH_VARARGS,doc_Set}, {"exists",CnfExists,METH_VARARGS,doc_Exists}, - {"sub_tree",CnfSubTree,METH_VARARGS,doc_SubTree}, + {"subtree",CnfSubTree,METH_VARARGS,doc_SubTree}, {"list",CnfList,METH_VARARGS,doc_List}, {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, diff --git a/python/depcache.cc b/python/depcache.cc index 650dcb23..f69802f8 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -535,13 +535,13 @@ static PyMethodDef PkgDepCacheMethods[] = // global cache operations {"upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"fix_broken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"read_pin_file",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"read_pinfile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, {"minimize_upgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, // Manipulators {"mark_keep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, {"mark_delete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, {"mark_install",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"set_re_install",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, + {"set_reinstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, // state information {"is_upgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, {"is_now_broken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 48440387..212e4ab0 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -120,7 +120,7 @@ static PyObject *PkgRecordsGetRecord(PyObject *Self,void*) { return PyString_FromStringAndSize(start,stop-start); } static PyGetSetDef PkgRecordsGetSet[] = { - {"file_name",PkgRecordsGetFileName}, + {"filename",PkgRecordsGetFileName}, {"homepage",PkgRecordsGetHomepage}, {"long_desc",PkgRecordsGetLongDesc}, {"md5_hash",PkgRecordsGetMD5Hash}, |
