// // FilterEbuild.cs // // Copyright (C) 2006 Pat Double // // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // 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*(?([A-Z_]+))\\s*=\\s*\"(?(.*))\"\\s*"); Regex EINFO = new Regex("\\s*(einfo|ewarn)\\s+\"(?(.*))\"\\s*"); Regex PACKAGE = new Regex("(?([^0-9]+))-(?(.+)).ebuild"); public FilterEbuild () { AddSupportedFlavor (FilterFlavor.NewFromExtension (".ebuild")); SetVersion(2); } 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 ("dc: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 = null; while ((str = reader.ReadLine ()) != null) { // Skip comments if (str.StartsWith("#")) continue; // Handle line continuation string str2 = null; while (str.Trim().EndsWith("\\") && ((str2 = reader.ReadLine ()) != null)) { str = str.Trim(); if (str.Length == 1) str = str2; else str = str.Substring(0, str.Length - 1) + " " + str2.Trim(); } 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(); } } }