diff options
author | Michael Schroeder <mls@suse.de> | 2013-06-14 11:50:12 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2013-06-14 11:50:12 +0200 |
commit | cb3836353d190ef3ce45778d29038d001f5b29b8 (patch) | |
tree | 0f9e0c378cbbea3fc471de11500f5004d7b4359e | |
parent | 8243f6d9275395544baa614e8788596fb11c5d34 (diff) | |
download | libsolv-cb3836353d190ef3ce45778d29038d001f5b29b8.tar.gz libsolv-cb3836353d190ef3ce45778d29038d001f5b29b8.tar.bz2 libsolv-cb3836353d190ef3ce45778d29038d001f5b29b8.zip |
bindings: add pool.errstr, make add_rpm/... return Solvable objects
-rw-r--r-- | bindings/solv.i | 24 | ||||
-rw-r--r-- | doc/libsolv-bindings.3 | 89 | ||||
-rw-r--r-- | doc/libsolv-bindings.txt | 77 | ||||
-rwxr-xr-x | examples/pysolv | 11 |
4 files changed, 118 insertions, 83 deletions
diff --git a/bindings/solv.i b/bindings/solv.i index 139a9a5..ed609d3 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -1248,6 +1248,7 @@ typedef struct { } Repo *installed; + const char * const errstr; %{ SWIGINTERN void Pool_installed_set(Pool *pool, Repo *installed) { pool_set_installed(pool, installed); @@ -1255,6 +1256,9 @@ typedef struct { Repo *Pool_installed_get(Pool *pool) { return pool->installed; } + const char *Pool_errstr_get(Pool *pool) { + return pool_errstr(pool); + } %} Queue matchprovidingids(const char *match, int flags) { @@ -1430,16 +1434,18 @@ rb_eval_string( bool add_rpmdb_reffp(FILE *reffp, int flags = 0) { return repo_add_rpmdb_reffp($self, reffp, flags) == 0; } - Id add_rpm(const char *name, int flags = 0) { - return repo_add_rpm($self, name, flags); + %newobject add_rpm; + XSolvable *add_rpm(const char *name, int flags = 0) { + return new_XSolvable($self->pool, repo_add_rpm($self, name, flags)); } #endif #ifdef ENABLE_RPMDB_PUBKEYS bool add_rpmdb_pubkeys(int flags = 0) { return repo_add_rpmdb_pubkeys($self, flags) == 0; } - Id add_pubkey(const char *key, int flags = 0) { - return repo_add_pubkey($self, key, flags); + %newobject add_pubkey; + XSolvable *add_pubkey(const char *key, int flags = 0) { + return new_XSolvable($self->pool, repo_add_pubkey($self, key, flags)); } #endif #ifdef ENABLE_RPMMD @@ -1463,8 +1469,9 @@ rb_eval_string( bool add_debpackages(FILE *fp, int flags = 0) { return repo_add_debpackages($self, fp, flags) == 0; } - Id add_deb(const char *name, int flags = 0) { - return repo_add_deb($self, name, flags); + %newobject add_deb; + XSolvable *add_deb(const char *name, int flags = 0) { + return new_XSolvable($self->pool, repo_add_deb($self, name, flags)); } #endif #ifdef ENABLE_SUSEREPO @@ -1493,8 +1500,9 @@ rb_eval_string( bool add_arch_local(const char *dir, int flags = 0) { return repo_add_arch_local($self, dir, flags) == 0; } - Id add_arch_pkg(const char *name, int flags = 0) { - return repo_add_arch_pkg($self, name, flags); + %newobject add_arch_pkg; + XSolvable *add_arch_pkg(const char *name, int flags = 0) { + return new_XSolvable($self->pool, repo_add_arch_pkg($self, name, flags)); } #endif void internalize() { diff --git a/doc/libsolv-bindings.3 b/doc/libsolv-bindings.3 index 3ac85c6..c29315f 100644 --- a/doc/libsolv-bindings.3 +++ b/doc/libsolv-bindings.3 @@ -2,12 +2,12 @@ .\" Title: Libsolv-Bindings .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/> -.\" Date: 06/13/2013 +.\" Date: 06/14/2013 .\" Manual: LIBSOLV .\" Source: libsolv .\" Language: English .\" -.TH "LIBSOLV\-BINDINGS" "3" "06/13/2013" "libsolv" "LIBSOLV" +.TH "LIBSOLV\-BINDINGS" "3" "06/14/2013" "libsolv" "LIBSOLV" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -452,6 +452,21 @@ Look up a Repository by its id\&. .\} .sp Define which repository contains all the installed packages\&. +.sp +.if n \{\ +.RS 4 +.\} +.nf +\fBconst char *errstr;\fR /* read only */ +my \fI$err\fR \fB=\fR \fI$pool\fR\fB\->{errstr}\fR; +\fIerr\fR \fB=\fR \fIpool\fR\fB\&.errstr\fR +\fIerr\fR \fB=\fR \fIpool\fR\fB\&.errstr\fR +.fi +.if n \{\ +.RE +.\} +.sp +Return the last error string that was stored in the pool\&. .SS "CONSTANTS" .PP \fBPOOL_FLAG_PROMOTEEPOCH\fR @@ -1685,9 +1700,9 @@ Add a single empty solvable to the repository\&. Returns a Solvable object, see .\} .nf \fBbool add_solv(const char *\fR\fIname\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_solv(\fR\fI$name\fR\fB,\fR \fI$flags\fR\fB)\fR; -\fIrepo\fR\fB\&.add_solv(\fR\fIname\fR\fB,\fR \fIflags\fR\fB)\fR -\fIrepo\fR\fB\&.add_solv(\fR\fIname\fR\fB,\fR \fIflags\fR\fB)\fR +\fI$repo\fR\fB\->add_solv(\fR\fI$name\fR\fB)\fR; +\fIrepo\fR\fB\&.add_solv(\fR\fIname\fR\fB)\fR +\fIrepo\fR\fB\&.add_solv(\fR\fIname\fR\fB)\fR .fi .if n \{\ .RE @@ -1698,9 +1713,9 @@ Add a single empty solvable to the repository\&. Returns a Solvable object, see .\} .nf \fBbool add_solv(FILE *\fR\fIfp\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_solv(\fR\fI$fp\fR\fB,\fR \fI$flags\fR\fB)\fR; -\fIrepo\fR\fB\&.add_solv(\fR\fIfp\fR\fB,\fR \fIflags\fR\fB)\fR -\fIrepo\fR\fB\&.add_solv(\fR\fIfp\fR\fB,\fR \fIflags\fR\fB)\fR +\fI$repo\fR\fB\->add_solv(\fR\fI$fp\fR\fB)\fR; +\fIrepo\fR\fB\&.add_solv(\fR\fIfp\fR\fB)\fR +\fIrepo\fR\fB\&.add_solv(\fR\fIfp\fR\fB)\fR .fi .if n \{\ .RE @@ -1713,9 +1728,9 @@ Read a \(lqsolv\(rq file and add its contents to the repository\&. These files c .\} .nf \fBbool add_rpmdb(int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_rpmdb(\fR\fI$flags\fR\fB)\fR; -\fIrepo\fR\fB\&.add_rpmdb(\fR\fIflags\fR\fB)\fR -\fIrepo\fR\fB\&.add_rpmdb(\fR\fIflags\fR\fB)\fR +\fI$repo\fR\fB\->add_rpmdb()\fR; +\fIrepo\fR\fB\&.add_rpmdb()\fR +\fIrepo\fR\fB\&.add_rpmdb()\fR .fi .if n \{\ .RE @@ -1726,9 +1741,9 @@ Read a \(lqsolv\(rq file and add its contents to the repository\&. These files c .\} .nf \fBbool add_rpmdb_reffp(FILE *\fR\fIreffp\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_rpmdb_reffp(\fR\fI$reffp\fR\fB,\fR \fI$flags\fR\fB)\fR; -\fIrepo\fR\fB\&.add_rpmdb_reffp(\fR\fI$reffp\fR\fB,\fR \fIflags\fR\fB)\fR -\fIrepo\fR\fB\&.add_rpmdb_reffp(\fR\fI$reffp\fR\fB,\fR \fIflags\fR\fB)\fR +\fI$repo\fR\fB\->add_rpmdb_reffp(\fR\fI$reffp\fR\fB)\fR; +\fIrepo\fR\fB\&.add_rpmdb_reffp(\fR\fIreffp\fR\fB)\fR +\fIrepo\fR\fB\&.add_rpmdb_reffp(\fR\fIreffp\fR\fB)\fR .fi .if n \{\ .RE @@ -1740,10 +1755,10 @@ Add the contents of the rpm database to the repository\&. If a solv file contain .RS 4 .\} .nf -\fBbool add_rpm(const char *\fR\fIname\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_rpm(\fR\fI$name\fR\fB,\fR \fI$flags\fR\fB)\fR; -\fIrepo\fR\fB\&.add_rpm(\fR\fIname\fR\fB,\fR \fIflags\fR\fB)\fR -\fIrepo\fR\fB\&.add_rpm(\fR\fIname\fR\fB,\fR \fIflags\fR\fB)\fR +\fBSolvable add_rpm(const char *\fR\fIfilename\fR\fB, int\fR \fIflags\fR \fB= 0)\fR +my \fI$solvable\fR \fB=\fR \fI$repo\fR\fB\->add_rpm(\fR\fI$filename\fR\fB)\fR; +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_rpm(\fR\fIfilename\fR\fB)\fR +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_rpm(\fR\fIfilename\fR\fB)\fR .fi .if n \{\ .RE @@ -1770,10 +1785,10 @@ Add all pubkeys contained in the rpm database to the repository\&. Note that new .RS 4 .\} .nf -\fBbool add_pubkey(const char *\fR\fIkeyfile\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_pubkey(\fR\fI$keyfile\fR\fB)\fR; -\fIrepo\fR\fB\&.add_pubkey(\fR\fI$keyfile\fR\fB)\fR -\fIrepo\fR\fB\&.add_pubkey(\fR\fI$keyfile\fR\fB)\fR +\fBSolvable add_pubkey(const char *\fR\fIkeyfile\fR\fB, int\fR \fIflags\fR \fB= 0)\fR +my \fI$solvable\fR \fB=\fR \fI$repo\fR\fB\->add_pubkey(\fR\fI$keyfile\fR\fB)\fR; +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_pubkey(\fR\fIkeyfile\fR\fB)\fR +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_pubkey(\fR\fIkeyfile\fR\fB)\fR .fi .if n \{\ .RE @@ -1786,9 +1801,9 @@ Add a pubkey from a file to the repository\&. .\} .nf \fBbool add_rpmmd(FILE *\fR\fIfp\fR\fB, const char *\fR\fIlanguage\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_rpmmd(\fR\fI$fp\fR\fB,\fR \fI$language\fR\fB)\fR; -\fIrepo\fR\fB\&.add_rpmmd(\fR\fIfp\fR\fB,\fR \fIlanguage\fR\fB)\fR -\fIrepo\fR\fB\&.add_rpmmd(\fR\fIfp\fR\fB,\fR \fIlanguage\fR\fB)\fR +\fI$repo\fR\fB\->add_rpmmd(\fR\fI$fp\fR\fB,\fR \fIundef\fR\fB)\fR; +\fIrepo\fR\fB\&.add_rpmmd(\fR\fIfp\fR\fB,\fR \fINone\fR\fB)\fR +\fIrepo\fR\fB\&.add_rpmmd(\fR\fIfp\fR\fB,\fR \fInil\fR\fB)\fR .fi .if n \{\ .RE @@ -1875,10 +1890,10 @@ Add the contents of the debian repository metadata (the "packages" file) to the .RS 4 .\} .nf -\fBbool add_deb(const char *\fR\fIfilename\fR\fB, int\fR \fIflags\fR \fB= 0)\fR -\fI$repo\fR\fB\->add_deb(\fR\fI$filename\fR\fB)\fR; -\fIrepo\fR\fB\&.add_deb(\fR\fIfilename\fR\fB)\fR -\fIrepo\fR\fB\&.add_deb(\fR\fIfilename\fR\fB)\fR +\fBSolvable add_deb(const char *\fR\fIfilename\fR\fB, int\fR \fIflags\fR \fB= 0)\fR +my \fI$solvable\fR \fB=\fR \fI$repo\fR\fB\->add_deb(\fR\fI$filename\fR\fB)\fR; +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_deb(\fR\fIfilename\fR\fB)\fR +\fIsolvable\fR \fB=\fR \fIrepo\fR\fB\&.add_deb(\fR\fIfilename\fR\fB)\fR .fi .if n \{\ .RE @@ -1892,8 +1907,8 @@ Add the metadata of a single deb package to the repository\&. .nf \fBbool add_mdk(FILE *\fR\fIfp\fR\fB, int\fR \fIflags\fR \fB= 0)\fR \fI$repo\fR\fB\->add_mdk(\fR\fI$fp\fR\fB)\fR; -\fIrepo\fR\fB\&.add_mdk(\fR\fI$fp\fR\fB)\fR -\fIrepo\fR\fB\&.add_mdk(\fR\fI$fp\fR\fB)\fR +\fIrepo\fR\fB\&.add_mdk(\fR\fIfp\fR\fB)\fR +\fIrepo\fR\fB\&.add_mdk(\fR\fIfp\fR\fB)\fR .fi .if n \{\ .RE @@ -1907,8 +1922,8 @@ Add the contents of the mageia/mandriva repository metadata (the "synthesis\&.hd .nf \fBbool add_mdk_info(FILE *\fR\fIfp\fR\fB, int\fR \fIflags\fR \fB= 0)\fR \fI$repo\fR\fB\->add_mdk(\fR\fI$fp\fR\fB)\fR; -\fIrepo\fR\fB\&.add_mdk(\fR\fI$fp\fR\fB)\fR -\fIrepo\fR\fB\&.add_mdk(\fR\fI$fp\fR\fB)\fR +\fIrepo\fR\fB\&.add_mdk(\fR\fIfp\fR\fB)\fR +\fIrepo\fR\fB\&.add_mdk(\fR\fIfp\fR\fB)\fR .fi .if n \{\ .RE @@ -1922,8 +1937,8 @@ Extend the packages from the synthesis file with the info\&.xml and files\&.xml .nf \fBbool add_arch_repo(FILE *\fR\fIfp\fR\fB, int\fR \fIflags\fR \fB= 0)\fR \fI$repo\fR\fB\->add_arch_repo(\fR\fI$fp\fR\fB)\fR; -\fIrepo\fR\fB\&.add_arch_repo(\fR\fI$fp\fR\fB)\fR -\fIrepo\fR\fB\&.add_arch_repo(\fR\fI$fp\fR\fB)\fR +\fIrepo\fR\fB\&.add_arch_repo(\fR\fIfp\fR\fB)\fR +\fIrepo\fR\fB\&.add_arch_repo(\fR\fIfp\fR\fB)\fR .fi .if n \{\ .RE @@ -1937,8 +1952,8 @@ Add the contents of the archlinux repository metadata (the "\&.db\&.tar" file) t .nf \fBbool add_arch_local(const char *\fR\fIdir\fR\fB, int\fR \fIflags\fR \fB= 0)\fR \fI$repo\fR\fB\->add_arch_local(\fR\fI$dir\fR\fB)\fR; -\fIrepo\fR\fB\&.add_arch_local(\fR\fI$dir\fR\fB)\fR -\fIrepo\fR\fB\&.add_arch_local(\fR\fI$dir\fR\fB)\fR +\fIrepo\fR\fB\&.add_arch_local(\fR\fIdir\fR\fB)\fR +\fIrepo\fR\fB\&.add_arch_local(\fR\fIdir\fR\fB)\fR .fi .if n \{\ .RE diff --git a/doc/libsolv-bindings.txt b/doc/libsolv-bindings.txt index e190cb3..8d273ff 100644 --- a/doc/libsolv-bindings.txt +++ b/doc/libsolv-bindings.txt @@ -235,6 +235,13 @@ Look up a Repository by its id. Define which repository contains all the installed packages. + const char *errstr; /* read only */ + my $err = $pool->{errstr}; + err = pool.errstr + err = pool.errstr + +Return the last error string that was stored in the pool. + === CONSTANTS === *POOL_FLAG_PROMOTEEPOCH*:: @@ -965,37 +972,37 @@ Add a single empty solvable to the repository. Returns a Solvable object, see the Solvable class for more information. bool add_solv(const char *name, int flags = 0) - $repo->add_solv($name, $flags); - repo.add_solv(name, flags) - repo.add_solv(name, flags) + $repo->add_solv($name); + repo.add_solv(name) + repo.add_solv(name) bool add_solv(FILE *fp, int flags = 0) - $repo->add_solv($fp, $flags); - repo.add_solv(fp, flags) - repo.add_solv(fp, flags) + $repo->add_solv($fp); + repo.add_solv(fp) + repo.add_solv(fp) Read a ``solv'' file and add its contents to the repository. These files can be written with the write() method and are normally used as fast cache for repository metadata. bool add_rpmdb(int flags = 0) - $repo->add_rpmdb($flags); - repo.add_rpmdb(flags) - repo.add_rpmdb(flags) + $repo->add_rpmdb(); + repo.add_rpmdb() + repo.add_rpmdb() bool add_rpmdb_reffp(FILE *reffp, int flags = 0) - $repo->add_rpmdb_reffp($reffp, $flags); - repo.add_rpmdb_reffp($reffp, flags) - repo.add_rpmdb_reffp($reffp, flags) + $repo->add_rpmdb_reffp($reffp); + repo.add_rpmdb_reffp(reffp) + repo.add_rpmdb_reffp(reffp) Add the contents of the rpm database to the repository. If a solv file containing an old version of the database is available, it can be passed as reffp to speed up reading. - bool add_rpm(const char *name, int flags = 0) - $repo->add_rpm($name, $flags); - repo.add_rpm(name, flags) - repo.add_rpm(name, flags) + Solvable add_rpm(const char *filename, int flags = 0) + my $solvable = $repo->add_rpm($filename); + solvable = repo.add_rpm(filename) + solvable = repo.add_rpm(filename) Add the metadata of a single rpm package to the repository. @@ -1008,17 +1015,17 @@ Add all pubkeys contained in the rpm database to the repository. Note that newer rpm versions also allow to store the pubkeys in some directory instead of the rpm database. - bool add_pubkey(const char *keyfile, int flags = 0) - $repo->add_pubkey($keyfile); - repo.add_pubkey($keyfile) - repo.add_pubkey($keyfile) + Solvable add_pubkey(const char *keyfile, int flags = 0) + my $solvable = $repo->add_pubkey($keyfile); + solvable = repo.add_pubkey(keyfile) + solvable = repo.add_pubkey(keyfile) Add a pubkey from a file to the repository. bool add_rpmmd(FILE *fp, const char *language, int flags = 0) - $repo->add_rpmmd($fp, $language); - repo.add_rpmmd(fp, language) - repo.add_rpmmd(fp, language) + $repo->add_rpmmd($fp, undef); + repo.add_rpmmd(fp, None) + repo.add_rpmmd(fp, nil) Add metadata stored in the "rpm-md" format (i.e. from files in the ``repodata'' directory) to a repository. Supported files are "primary", "filelists", @@ -1070,41 +1077,41 @@ Add the contents of the debian installed package database to the repository. Add the contents of the debian repository metadata (the "packages" file) to the repository. - bool add_deb(const char *filename, int flags = 0) - $repo->add_deb($filename); - repo.add_deb(filename) - repo.add_deb(filename) + Solvable add_deb(const char *filename, int flags = 0) + my $solvable = $repo->add_deb($filename); + solvable = repo.add_deb(filename) + solvable = repo.add_deb(filename) Add the metadata of a single deb package to the repository. bool add_mdk(FILE *fp, int flags = 0) $repo->add_mdk($fp); - repo.add_mdk($fp) - repo.add_mdk($fp) + repo.add_mdk(fp) + repo.add_mdk(fp) Add the contents of the mageia/mandriva repository metadata (the "synthesis.hdlist" file) to the repository. bool add_mdk_info(FILE *fp, int flags = 0) $repo->add_mdk($fp); - repo.add_mdk($fp) - repo.add_mdk($fp) + repo.add_mdk(fp) + repo.add_mdk(fp) Extend the packages from the synthesis file with the info.xml and files.xml data. Do not forget to specify *REPO_EXTEND_SOLVABLES*. bool add_arch_repo(FILE *fp, int flags = 0) $repo->add_arch_repo($fp); - repo.add_arch_repo($fp) - repo.add_arch_repo($fp) + repo.add_arch_repo(fp) + repo.add_arch_repo(fp) Add the contents of the archlinux repository metadata (the ".db.tar" file) to the repository. bool add_arch_local(const char *dir, int flags = 0) $repo->add_arch_local($dir); - repo.add_arch_local($dir) - repo.add_arch_local($dir) + repo.add_arch_local(dir) + repo.add_arch_local(dir) Add the contents of the archlinux installed package database to the repository. The _dir_ parameter is usually set to "/var/lib/pacman/local". diff --git a/examples/pysolv b/examples/pysolv index bc12766..da9971a 100755 --- a/examples/pysolv +++ b/examples/pysolv @@ -234,6 +234,7 @@ class repo_generic(dict): def writecachedrepo(self, ext, info=None): if 'incomplete' in self: return + tmpname = None try: if not os.path.isdir("/var/cache/solv"): os.mkdir("/var/cache/solv", 0755) @@ -273,7 +274,7 @@ class repo_generic(dict): flags |= solv.Repo.REPO_LOCALPOOL info.add_solv(nf, flags) os.rename(tmpname, self.cachepath(ext)) - except IOError, e: + except (OSError, IOError), e: if tmpname: os.unlink(tmpname) @@ -670,7 +671,11 @@ if cmd == 'list' or cmd == 'info' or cmd == 'install': cmdlinerepo = repo_cmdline('@commandline', 'cmdline') cmdlinerepo.load(pool) cmdlinerepo['packages'] = {} - cmdlinerepo['packages'][arg] = cmdlinerepo.handle.add_rpm(arg, solv.Repo.REPO_REUSE_REPODATA|solv.Repo.REPO_NO_INTERNALIZE) + s = cmdlinerepo.handle.add_rpm(arg, solv.Repo.REPO_REUSE_REPODATA|solv.Repo.REPO_NO_INTERNALIZE) + if not s: + print pool.errstr + sys.exit(1) + cmdlinerepo['packages'][arg] = s if cmdlinerepo: cmdlinerepo.handle.internalize() @@ -686,7 +691,7 @@ pool.createwhatprovides() jobs = [] for arg in args: if cmdlinerepo and arg in cmdlinerepo['packages']: - jobs.append(pool.Job(solv.Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg])) + jobs.append(pool.Job(solv.Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg].id)) else: flags = solv.Selection.SELECTION_NAME|solv.Selection.SELECTION_PROVIDES|solv.Selection.SELECTION_GLOB flags |= solv.Selection.SELECTION_CANON|solv.Selection.SELECTION_DOTARCH|solv.Selection.SELECTION_REL |