Forgot to bump FSQ version. Weekend syndrome.
[beagle.git] / Filters / FilterEbuild.cs
blob347afd58f9b5aa7713d09db8cc166026de75f684
1 //
2 // FilterEbuild.cs
3 //
4 // Copyright (C) 2006 Pat Double <pat@patdouble.com>
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using System;
28 using System.IO;
29 using System.Text.RegularExpressions;
30 using Beagle.Daemon;
32 namespace Beagle.Filters {
34 public class FilterEbuild : Beagle.Daemon.Filter {
35 static Regex metadata_pattern = new Regex ("\\s*(?<key>([A-Z_]+))\\s*=\\s*\"(?<value>(.*))\"\\s*");
36 static Regex einfo_pattern = new Regex ("\\s*(einfo|ewarn)\\s+\"(?<message>(.*))\"\\s*");
37 static Regex package_pattern = new Regex ("(?<name>([^0-9]+))-(?<version>(.+)).ebuild");
39 public FilterEbuild ()
41 AddSupportedFlavor (FilterFlavor.NewFromExtension (".ebuild"));
44 override protected void DoOpen (FileInfo file)
46 Match match = package_pattern.Match (file.Name);
47 String pkgname = match.Groups ["name"].ToString();
48 if (pkgname.Length > 0)
49 AddProperty (Beagle.Property.New ("dc:title", pkgname));
51 String version = match.Groups ["version"].ToString();
52 if (version.Length > 0)
53 AddProperty (Beagle.Property.NewUnsearched ("fixme:version", version));
55 StreamReader reader = new StreamReader (new FileStream (file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read));
57 string str = null;
58 while ((str = reader.ReadLine ()) != null) {
59 // Skip comments
60 if (str.StartsWith ("#"))
61 continue;
63 // Handle line continuation
64 string str2 = null;
65 while (str.Trim ().EndsWith ("\\") && ((str2 = reader.ReadLine ()) != null) ) {
66 str = str.Trim ();
67 if (str.Length == 1)
68 str = str2;
69 else
70 str = str.Substring (0, str.Length - 1) + " " + str2.Trim ();
73 if (str.Length == 0)
74 continue;
76 // check for meta data
77 MatchCollection matches;
78 matches = metadata_pattern.Matches (str);
79 if (matches.Count > 0) {
80 foreach (Match the_match in matches) {
81 String key = the_match.Groups ["key"].ToString ();
82 String value = the_match.Groups ["value"].ToString ();
83 if (key.Equals ("DESCRIPTION"))
84 AddProperty (Beagle.Property.New ("dc:description", value));
85 else if (key.Equals ("LICENSE"))
86 AddProperty (Beagle.Property.New ("dc:rights", value));
87 else if (key.Equals ("HOMEPAGE"))
88 AddProperty (Beagle.Property.New ("dc:source", value));
90 } else {
91 // check for einfo/ewarn
92 matches = einfo_pattern.Matches (str);
93 if (matches.Count > 0) {
94 foreach (Match the_match in matches)
95 AppendText (the_match.Groups ["message"].ToString ());
99 Finished ();