[Mono-devel-list] API to query RPM database?

Rafael Teixeira monoman at gmail.com
Tue Jan 18 08:58:22 EST 2005


I don't know any such binding for Mono, but you can:

1) spawn a process to call "rpm -q" and capture and process it's
output. That is easy to do in Mono. See this excerpt from mbas code to
have an idea:

<code>
		public bool ReferencePackage(string packageName)
		{
			if (packageName == ""){
				DoAbout ();
				return false;
			}
				
			ProcessStartInfo pi = new ProcessStartInfo ();
			pi.FileName = "pkg-config";
			pi.RedirectStandardOutput = true;
			pi.UseShellExecute = false;
			pi.Arguments = "--libs " + packageName;
			Process p = null;
			try {
				p = Process.Start (pi);
			} catch (Exception e) {
				Report.Error (-27, "Couldn't run pkg-config: " + e.Message);
				return false;
			}

			if (p.StandardOutput == null){
				Report.Warning (-27, "Specified package did not return any information");
			}
			string pkgout = p.StandardOutput.ReadToEnd ();
			p.WaitForExit ();
			if (p.ExitCode != 0) {
				Report.Error (-27, "Error running pkg-config. Check the above output.");
				return false;
			}
			p.Close ();
			
			if (pkgout != null) {
				string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
					Split (new Char [] { ' ', '\t'});
				foreach(string arg in xargs) {
					string[] zargs = arg.Split(':', '=');
					try {
						if (zargs.Length > 1)
							AddedReference = zargs[1];
						else
							AddedReference = arg;
					} catch (Exception e) {
						Report.Error (-27, "Something wrong with argument (" + arg + ")
in 'pkg-config --libs' output: " + e.Message);
						return false;
					}
				}
			}

			return true;
		}

</code>

2) write a binding around the rpm libraries. I my FC2 these are the
ones used by /bin/rpm:
        librpm-4.3.so => /usr/lib/librpm-4.3.so (0x00d90000)
        librpmdb-4.3.so => /usr/lib/librpmdb-4.3.so (0x00c66000)
        librpmio-4.3.so => /usr/lib/librpmio-4.3.so (0x00d59000)

Such a binding is mostly C# code with lots of 'P/Invoke's, but
sometimes you may need to cook some C glue code.  See what has been
done for the Mono.Posix library (/mcs/class/Mono.Posix/Mono.Unix/) for
a good, well-thought, example.

On a portability/stability sense I prefer the first way. RPM is such a
delicate business that messing with it's internals may easily lead to
unstable systems.

Also some of the things querying RPM would be needed for, would be
better handled with something like pkg-config or just a plain which or
locate.

Hope it helps,
 

On Tue, 18 Jan 2005 09:29:21 +0530, Roshan Achar <broshan at gmail.com> wrote:
> Hi All,
> 
> I am new to mono and was wondering if there is any API which allows
> querying the rpm database. Something like the "rpm -q" shell command.
> Any help is greatly appreciated.
> 
> Thanks,
> Roshan
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 


-- 
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes. 
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.



More information about the Mono-devel-list mailing list