diff options
Diffstat (limited to 'python/apt_pkgmodule.cc')
| -rw-r--r-- | python/apt_pkgmodule.cc | 281 |
1 files changed, 101 insertions, 180 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 1a991a48..8870a6e0 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -21,12 +21,13 @@ #include <apt-pkg/tagfile.h> #include <apt-pkg/md5.h> #include <apt-pkg/sha1.h> -#include <apt-pkg/sha256.h> +#include <apt-pkg/sha2.h> #include <apt-pkg/init.h> #include <apt-pkg/pkgsystem.h> #include <apt-pkg/orderlist.h> #include <apt-pkg/aptconfiguration.h> #include <apt-pkg/fileutl.h> +#include <apt-pkg/gpgv.h> #include <sys/stat.h> #include <libintl.h> @@ -53,23 +54,15 @@ static PyObject *py_gettext(PyObject *self, PyObject *Args) { // newConfiguration - Build a new configuration class /*{{{*/ // --------------------------------------------------------------------- -#ifdef COMPAT_0_7 -static char *doc_newConfiguration = "Construct a configuration instance"; -static PyObject *newConfiguration(PyObject *self,PyObject *args) -{ - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " - "deprecated. Use apt_pkg.Configuration() instead.", 1); - return CppPyObject_NEW<Configuration*>(NULL, &PyConfiguration_Type, new Configuration()); -} -#endif /*}}}*/ // Version Wrappers /*{{{*/ // These are kind of legacy.. static char *doc_VersionCompare = "version_compare(a: str, b: str) -> int\n\n" - "Compare the given versions; return -1 if 'a' is smaller than 'b',\n" - "0 if they are equal, and 2 if 'a' is larger than 'b'."; + "Compare the given versions; return a strictly negative value if 'a' is \n" + "smaller than 'b', 0 if they are equal, and a strictly positive value if\n" + "'a' is larger than 'b'."; static PyObject *VersionCompare(PyObject *Self,PyObject *Args) { char *A; @@ -124,32 +117,6 @@ static PyObject *CheckDep(PyObject *Self,PyObject *Args) return PyBool_FromLong(_system->VS->CheckDep(A,Op,B)); } -#ifdef COMPAT_0_7 -static char *doc_CheckDepOld = "CheckDep(PkgVer,DepOp,DepVer) -> bool"; -static PyObject *CheckDepOld(PyObject *Self,PyObject *Args) -{ - char *A; - char *B; - char *OpStr; - unsigned int Op = 0; - - if (PyArg_ParseTuple(Args,"sss",&A,&OpStr,&B) == 0) - return 0; - if (*debListParser::ConvertRelation(OpStr,Op) != 0) - { - PyErr_SetString(PyExc_ValueError,"Bad comparision operation"); - return 0; - } - - if (_system == 0) - { - PyErr_SetString(PyExc_ValueError,"_system not initialized"); - return 0; - } - - return PyBool_FromLong(_system->VS->CheckDep(A,Op,B)); -} -#endif static char *doc_UpstreamVersion = "upstream_version(ver: str) -> str\n\n" @@ -163,17 +130,19 @@ static PyObject *UpstreamVersion(PyObject *Self,PyObject *Args) } static const char *doc_ParseDepends = -"parse_depends(s: str) -> list\n" +"parse_depends(s: str[, strip_multi_arch : bool = True]) -> list\n" "\n" "Parse the dependencies given by 's' and return a list of lists. Each of\n" "these lists represents one or more options for an 'or' dependency in\n" "the form of '(pkg, ver, comptype)' tuples. The tuple element 'pkg'\n" "is the name of the package; the element 'ver' is the version, or ''\n" "if no version was requested. The element 'ver' is a comparison\n" -"operator ('<', '<=', '=', '>=', or '>')."; +"operator ('<', '<=', '=', '>=', or '>').\n\n" +"If 'strip_multi_arch' is True, :any (and potentially other special values)\n" +"will be stripped from the full package name"; static const char *parse_src_depends_doc = -"parse_src_depends(s: str) -> list\n" +"parse_src_depends(s: str[, strip_multi_arch : bool = True]) -> list\n" "\n" "Parse the dependencies given by 's' and return a list of lists. Each of\n" "these lists represents one or more options for an 'or' dependency in\n" @@ -184,10 +153,12 @@ static const char *parse_src_depends_doc = "\n\n" "Dependencies may be restricted to certain architectures and the result\n" "only contains those dependencies for the architecture set in the\n" -"configuration variable APT::Architecture"; +"configuration variable APT::Architecture\n\n" +"If 'strip_multi_arch' is True, :any (and potentially other special values)\n" +"will be stripped from the full package name"; static PyObject *RealParseDepends(PyObject *Self,PyObject *Args, - bool ParseArchFlags, std::string name, - bool debStyle=false) + bool ParseArchFlags, bool ParseRestrictionsList, + std::string name, bool debStyle=false) { std::string Package; std::string Version; @@ -210,7 +181,8 @@ static PyObject *RealParseDepends(PyObject *Self,PyObject *Args, break; Start = debListParser::ParseDepends(Start,Stop,Package,Version,Op, - ParseArchFlags, StripMultiArch); + ParseArchFlags, StripMultiArch, + ParseRestrictionsList); if (Start == 0) { PyErr_SetString(PyExc_ValueError,"Problem Parsing Dependency"); @@ -243,22 +215,12 @@ static PyObject *RealParseDepends(PyObject *Self,PyObject *Args, } static PyObject *ParseDepends(PyObject *Self,PyObject *Args) { - return RealParseDepends(Self, Args, false, "parse_depends"); + return RealParseDepends(Self, Args, false, false, "parse_depends"); } static PyObject *ParseSrcDepends(PyObject *Self,PyObject *Args) { - return RealParseDepends(Self, Args, true, "parse_src_depends"); + return RealParseDepends(Self, Args, true, true, "parse_src_depends"); } -#ifdef COMPAT_0_7 -static PyObject *ParseDepends_old(PyObject *Self,PyObject *Args) -{ - return RealParseDepends(Self, Args, false, "ParseDepends", true); -} -static PyObject *ParseSrcDepends_old(PyObject *Self,PyObject *Args) -{ - return RealParseDepends(Self, Args, true, "ParseSrcDepends", true); -} -#endif /*}}}*/ // md5sum - Compute the md5sum of a file or string /*{{{*/ // --------------------------------------------------------------------- @@ -350,7 +312,7 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args) return 0; } /*}}}*/ -// sha256sum - Compute the sha1sum of a file or string /*{{{*/ +// sha256sum - Compute the sha256sum of a file or string /*{{{*/ // --------------------------------------------------------------------- static const char *doc_sha256sum = "sha256sum(object) -> str\n\n" @@ -395,6 +357,51 @@ static PyObject *sha256sum(PyObject *Self,PyObject *Args) return 0; } /*}}}*/ +// sha512sum - Compute the sha512sum of a file or string /*{{{*/ +// --------------------------------------------------------------------- +static const char *doc_sha512sum = + "sha512sum(object) -> str\n\n" + "Return the sha512sum of the object. 'object' may either be a string, in\n" + "which case the sha512sum of the string is returned, or a file() object\n" + "(or file descriptor), in which case the sha512sum of its contents is\n" + "returned.";; +static PyObject *sha512sum(PyObject *Self,PyObject *Args) +{ + PyObject *Obj; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) + return 0; + + // Digest of a string. + if (PyBytes_Check(Obj) != 0) + { + char *s; + Py_ssize_t len; + SHA512Summation Sum; + PyBytes_AsStringAndSize(Obj, &s, &len); + Sum.Add((const unsigned char*)s, len); + return CppPyString(Sum.Result().Value()); + } + + // Digest of a file + int Fd = PyObject_AsFileDescriptor(Obj); + if (Fd != -1) + { + SHA512Summation Sum; + struct stat St; + if (fstat(Fd,&St) != 0 || + Sum.AddFD(Fd,St.st_size) == false) + { + PyErr_SetFromErrno(PyExc_SystemError); + return 0; + } + + return CppPyString(Sum.Result().Value()); + } + + PyErr_SetString(PyExc_TypeError,"Only understand strings and files"); + return 0; +} + /*}}}*/ // get_architectures - return the list of architectures /*{{{*/ // --------------------------------------------------------------------- static const char *doc_GetArchitectures = @@ -466,6 +473,25 @@ static PyObject *InitSystem(PyObject *Self,PyObject *Args) return HandleErrors(Py_None); } /*}}}*/ +// gpgv.cc:OpenMaybeClearSignedFile /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_OpenMaybeClearSignedFile = +"open_maybe_clear_signed_file(file: str) -> int\n\n" +"Open a file and ignore a PGP clear signature.\n" +"Return a open file descriptor or a error."; +static PyObject *PyOpenMaybeClearSignedFile(PyObject *Self,PyObject *Args) +{ + PyApt_Filename file; + char errors = false; + if (PyArg_ParseTuple(Args,"O&",PyApt_Filename::Converter, &file,&errors) == 0) + return 0; + + FileFd Fd; + if (OpenMaybeClearSignedFile(file, Fd) == false) + return HandleErrors(MkPyNumber(-1)); + + return HandleErrors(MkPyNumber(dup(Fd.Fd()))); +} // fileutils.cc: GetLock /*{{{*/ // --------------------------------------------------------------------- @@ -479,9 +505,9 @@ static char *doc_GetLock = "provided by apt_pkg.FileLock instead using the with-statement."; static PyObject *GetLock(PyObject *Self,PyObject *Args) { - const char *file; + PyApt_Filename file; char errors = false; - if (PyArg_ParseTuple(Args,"s|b",&file,&errors) == 0) + if (PyArg_ParseTuple(Args,"O&|b",PyApt_Filename::Converter, &file,&errors) == 0) return 0; int fd = GetLock(file, errors); @@ -542,6 +568,9 @@ static PyMethodDef methods[] = {"rewrite_section",RewriteSection,METH_VARARGS,doc_RewriteSection}, #endif + {"open_maybe_clear_signed_file",PyOpenMaybeClearSignedFile,METH_VARARGS, + doc_OpenMaybeClearSignedFile}, + // Locking {"get_lock",GetLock,METH_VARARGS,doc_GetLock}, {"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, @@ -562,10 +591,11 @@ static PyMethodDef methods[] = {"parse_depends",ParseDepends,METH_VARARGS,doc_ParseDepends}, {"parse_src_depends",ParseSrcDepends,METH_VARARGS,parse_src_depends_doc}, - // Stuff + // Hashes {"md5sum",md5sum,METH_VARARGS,doc_md5sum}, {"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum}, {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum}, + {"sha512sum",sha512sum,METH_VARARGS,doc_sha512sum}, // multiarch {"get_architectures", GetArchitectures, METH_VARARGS, doc_GetArchitectures}, @@ -617,57 +647,6 @@ static PyMethodDef methods[] = "Convert the given RFC 1123 formatted string to a Unix timestamp."}, // DEPRECATED - #ifdef COMPAT_0_7 - {"CheckDep",CheckDepOld,METH_VARARGS,doc_CheckDepOld}, - {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, - {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, - {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, - - {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, - {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, -#ifdef HAVE_OPEN_MEMSTREAM - {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, -#endif - - {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, - {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, - {"PkgSystemUnLock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, - - {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, - {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, - {"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, - {"ParseCommandLine",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, - - {"VersionCompare",VersionCompare,METH_VARARGS,doc_VersionCompare}, - {"UpstreamVersion",UpstreamVersion,METH_VARARGS,doc_UpstreamVersion}, - - {"ParseDepends",ParseDepends_old,METH_VARARGS,doc_ParseDepends}, - {"ParseSrcDepends",ParseSrcDepends_old,METH_VARARGS,doc_ParseDepends}, - - {"CheckDomainList",StrCheckDomainList,METH_VARARGS, - "CheckDomainList(String,String) -> Bool"}, - {"QuoteString",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, - {"DeQuoteString",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, - {"SizeToStr",StrSizeToStr,METH_VARARGS,"SizeToStr(int) -> String"}, - {"TimeToStr",StrTimeToStr,METH_VARARGS,"TimeToStr(int) -> String"}, - {"URItoFileName",StrURItoFileName,METH_VARARGS,"URItoFileName(String) -> String"}, - {"Base64Encode",StrBase64Encode,METH_VARARGS,"Base64Encode(String) -> String"}, - {"StringToBool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, - {"TimeRFC1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, - {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, - - {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, - {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, - {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, - {"GetPkgSrcRecords",GetPkgSrcRecords,METH_VARARGS,"GetPkgSrcRecords() -> PkgSrcRecords"}, - {"GetPkgSourceList",GetPkgSourceList,METH_VARARGS,"GetPkgSourceList() -> PkgSourceList"}, - {"GetPkgProblemResolver",GetPkgProblemResolver,METH_VARARGS,"GetDepProblemResolver(DepCache) -> PkgProblemResolver"}, - {"GetPkgActionGroup",GetPkgActionGroup,METH_VARARGS,"GetPkgActionGroup(DepCache) -> PkgActionGroup"}, - {"GetCdrom",GetCdrom,METH_VARARGS,"GetCdrom() -> Cdrom"}, - {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"}, - {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS, doc_GetPkgAcqFile}, - {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager(DepCache) -> PackageManager"}, - #endif {} }; @@ -825,10 +804,6 @@ extern "C" void initapt_pkg() // Global configuration, should never be deleted. Config->NoDelete = true; PyModule_AddObject(Module,"config",Config); - #ifdef COMPAT_0_7 - Py_INCREF(Config); - PyModule_AddObject(Module,"Config",Config); - #endif @@ -908,14 +883,6 @@ extern "C" void initapt_pkg() MkPyNumber(pkgAcquire::Continue)); PyDict_SetItemString(PyAcquire_Type.tp_dict, "RESULT_FAILED", MkPyNumber(pkgAcquire::Failed)); -#ifdef COMPAT_0_7 - PyDict_SetItemString(PyAcquire_Type.tp_dict, "ResultCancelled", - MkPyNumber(pkgAcquire::Cancelled)); - PyDict_SetItemString(PyAcquire_Type.tp_dict, "ResultContinue", - MkPyNumber(pkgAcquire::Continue)); - PyDict_SetItemString(PyAcquire_Type.tp_dict, "ResultFailed", - MkPyNumber(pkgAcquire::Failed)); -#endif // Dependency constants PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_DEPENDS", MkPyNumber(pkgCache::Dep::Depends)); @@ -945,15 +912,9 @@ extern "C" void initapt_pkg() PyDict_SetItemString(PyPackageManager_Type.tp_dict, "RESULT_INCOMPLETE", MkPyNumber(pkgPackageManager::Incomplete)); -#ifdef COMPAT_0_7 - PyDict_SetItemString(PyPackageManager_Type.tp_dict, "ResultCompleted", - MkPyNumber(pkgPackageManager::Completed)); - PyDict_SetItemString(PyPackageManager_Type.tp_dict, "ResultFailed", - MkPyNumber(pkgPackageManager::Failed)); - PyDict_SetItemString(PyPackageManager_Type.tp_dict, "ResultIncomplete", - MkPyNumber(pkgPackageManager::Incomplete)); -#endif - + PyDict_SetItemString(PyVersion_Type.tp_dict, "MULTI_ARCH_NO", + MkPyNumber(pkgCache::Version::None)); + // NONE is deprecated (#782802) PyDict_SetItemString(PyVersion_Type.tp_dict, "MULTI_ARCH_NONE", MkPyNumber(pkgCache::Version::None)); PyDict_SetItemString(PyVersion_Type.tp_dict, "MULTI_ARCH_ALL", @@ -982,18 +943,6 @@ extern "C" void initapt_pkg() PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "STAT_AUTH_ERROR", MkPyNumber(pkgAcquire::Item::StatAuthError)); -#ifdef COMPAT_0_7 - PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatIdle", - MkPyNumber(pkgAcquire::Item::StatIdle)); - PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatFetching", - MkPyNumber(pkgAcquire::Item::StatFetching)); - PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatDone", - MkPyNumber(pkgAcquire::Item::StatDone)); - PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatError", - MkPyNumber(pkgAcquire::Item::StatError)); - PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatAuthError", - MkPyNumber(pkgAcquire::Item::StatAuthError)); -#endif #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 PyObject *PyCapsule = PyCapsule_New(&API, "apt_pkg._C_API", NULL); @@ -1004,8 +953,13 @@ extern "C" void initapt_pkg() // Version.. PyModule_AddStringConstant(Module,"VERSION",(char *)pkgVersion); PyModule_AddStringConstant(Module,"LIB_VERSION",(char *)pkgLibVersion); - PyModule_AddStringConstant(Module,"DATE",__DATE__); - PyModule_AddStringConstant(Module,"TIME",__TIME__); +#ifdef DATE + PyModule_AddStringConstant(Module,"DATE",DATE); + PyModule_AddStringConstant(Module,"TIME",TIME); +#else + PyModule_AddStringConstant(Module,"DATE", "Jan 1 1970"); + PyModule_AddStringConstant(Module,"TIME", "00:00:00"); +#endif // My constants PyModule_AddIntConstant(Module,"PRI_IMPORTANT",pkgCache::State::Important); @@ -1033,39 +987,6 @@ extern "C" void initapt_pkg() PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq); - // DEPRECATED API - #ifdef COMPAT_0_7 - PyModule_AddObject(Module,"RewritePackageOrder", - CharCharToList(TFRewritePackageOrder)); - PyModule_AddObject(Module,"RewriteSourceOrder", - CharCharToList(TFRewriteSourceOrder)); - PyModule_AddStringConstant(Module,"LibVersion",(char *)pkgLibVersion); - PyModule_AddStringConstant(Module,"Date",__DATE__); - PyModule_AddStringConstant(Module,"Time",__TIME__); - PyModule_AddIntConstant(Module,"PriImportant",pkgCache::State::Important); - PyModule_AddIntConstant(Module,"PriRequired",pkgCache::State::Required); - PyModule_AddIntConstant(Module,"PriStandard",pkgCache::State::Standard); - PyModule_AddIntConstant(Module,"PriOptional",pkgCache::State::Optional); - PyModule_AddIntConstant(Module,"PriExtra",pkgCache::State::Extra); - PyModule_AddIntConstant(Module,"CurStateNotInstalled",pkgCache::State::NotInstalled); - PyModule_AddIntConstant(Module,"CurStateUnPacked",pkgCache::State::UnPacked); - PyModule_AddIntConstant(Module,"CurStateHalfConfigured",pkgCache::State::HalfConfigured); - PyModule_AddIntConstant(Module,"CurStateHalfInstalled",pkgCache::State::HalfInstalled); - PyModule_AddIntConstant(Module,"CurStateConfigFiles",pkgCache::State::ConfigFiles); - PyModule_AddIntConstant(Module,"CurStateInstalled",pkgCache::State::Installed); - PyModule_AddIntConstant(Module,"SelStateUnknown",pkgCache::State::Unknown); - PyModule_AddIntConstant(Module,"SelStateInstall",pkgCache::State::Install); - PyModule_AddIntConstant(Module,"SelStateHold",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"SelStateDeInstall",pkgCache::State::DeInstall); - PyModule_AddIntConstant(Module,"SelStatePurge",pkgCache::State::Purge); - PyModule_AddIntConstant(Module,"InstStateOk",pkgCache::State::Ok); - PyModule_AddIntConstant(Module,"InstStateReInstReq",pkgCache::State::ReInstReq); - PyModule_AddIntConstant(Module,"InstStateHold",pkgCache::State::Hold); - PyModule_AddIntConstant(Module,"InstStateHoldReInstReq",pkgCache::State::HoldReInstReq); - PyModule_AddIntConstant(Module,"_COMPAT_0_7",1); - #else - PyModule_AddIntConstant(Module,"_COMPAT_0_7",0); - #endif #if PY_MAJOR_VERSION >= 3 return Module; #endif |
