Beagle filter for Gentoo ebuilds



I've written a filter for Gentoo Linux ebuilds. The main goal is to extract 
information like the title, version, description, etc. It was really easy to 
write. I'd appreciate comments (I'm a Java developer, so I'm sure there are 
some bad things I've done with C# here ;). Any chance this could get included 
in the beagle distribution? How do I go about that, file a bug?

Thanks.


--- code here ---

using System;
using System.IO;
using System.Text.RegularExpressions;
using Beagle.Daemon;

namespace Beagle.Filters {

	public class FilterEbuild : Beagle.Daemon.Filter {
		Regex METADATA_PATTERN = new 
Regex("\\s*(?<key>([A-Z_]+))\\s*=\\s*\"(?<value>(.*))\"\\s*");
		Regex EINFO = new Regex("\\s*(einfo|ewarn)\\s+\"(?<message>(.*))\"\\s*");
		Regex PACKAGE = new Regex("(?<name>([^0-9]+))-(?<version>(.+)).ebuild");

		public FilterEbuild ()
		{
			AddSupportedFlavor (FilterFlavor.NewFromExtension (".ebuild"));
			SetVersion(1);
		}

		override protected void DoOpen (FileInfo file)
		{
			Match match = PACKAGE.Match(file.Name);
			String pkgname = match.Groups["name"].ToString();
			if (pkgname.Length > 0) {
				AddProperty (Beagle.Property.New ("fixme:title", pkgname));
			}
			
			String version = match.Groups["version"].ToString();
			if (version.Length > 0) {
				AddProperty (Beagle.Property.New ("fixme:version", version));
			}

			StreamReader reader = new StreamReader(new FileStream(file.FullName, 
FileMode.Open, FileAccess.Read, FileShare.Read));

			string str = TextReader.ReadLine ();
			while ((str = reader.ReadLine ()) != null) {
				if (str.Length > 0) {
					// check for meta data
					MatchCollection matches;
					matches = METADATA_PATTERN.Matches (str);
					if (matches.Count > 0) {
						foreach (Match theMatch in matches) {
							String key = theMatch.Groups ["key"].ToString ();
							String value = theMatch.Groups ["value"].ToString ();
							if (key.Equals("DESCRIPTION")) {
								AddProperty (Beagle.Property.New ("dc:description", value));
							}
							else if (key.Equals("LICENSE")) {
								AddProperty (Beagle.Property.New ("dc:rights", value));
							}
							else if (key.Equals("HOMEPAGE")) {
								AddProperty (Beagle.Property.New ("dc:source", value));
							}
						}
					}
					else
					{
						// check for einfo/ewarn
						matches = EINFO.Matches (str);
						if (matches.Count > 0) {
							foreach (Match theMatch in matches) {
								AppendText(theMatch.Groups ["message"].ToString ());
							}
						}
					}
				}
			}
			Finished();
		}
	}
}


--- code not here ---


-- 
Pat Double, pat patdouble com
"In the beginning God created the heaven and the earth."

Attachment: pgpgs4ZlLBmLE.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]