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

Andrew agomez at wke.es
Tue Jan 18 09:43:35 EST 2005


Rafael Teixeira escribió:
> 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

Hello. All of this stuff sounds interesting.

Can that code (1) run on Mono for windows to call Win32 executables?
Can that code (1) be compiled by MS VS.NET?

I write because I need to do something similar, but with "grep" instead 
of "rpm". Is there some .NET library (for Mono or VS.NET) out there that 
already does the "dirty stuff" of the grep tool? Or should I use the 
first method proposed by Rafael Texeira? Or should I code the library 
myself (it seems not very difficult)?

Any opinions will be appreciated.

-- 
	Regards,

		Andrew



More information about the Mono-devel-list mailing list