4 // Copyright (C) 2006 Pat Double <pat@patdouble.com>
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.
29 using System
.Text
.RegularExpressions
;
32 namespace Beagle
.Filters
{
34 public class FilterEbuild
: FilterPackage
{
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
);
48 PackageName
= match
.Groups
["name"].ToString();
49 PackageVersion
= match
.Groups
["version"].ToString();
51 if (PackageName
.Length
== 0 && PackageVersion
.Length
== 0)
54 // get download file size
55 FileInfo digest
= new FileInfo (file
.Directory
.FullName
+ "/files/digest-" + PackageName
+ "-" + PackageVersion
);
57 long download_size
= 0;
58 StreamReader digest_reader
= new StreamReader (new FileStream (digest
.FullName
, FileMode
.Open
, FileAccess
.Read
, FileShare
.Read
));
59 string digest_line
= null;
60 while ((digest_line
= digest_reader
.ReadLine ()) != null) {
61 string[] digest_parts
= digest_line
.Split (' ');
62 if (digest_parts
.Length
< 4)
64 if (digest_parts
[0].Equals ("MD5"))
65 download_size
+= Int64
.Parse (digest_parts
[3]);
67 Size
= download_size
.ToString ();
68 digest_reader
.Close ();
72 override protected void PullPackageProperties ()
75 while ((str
= TextReader
.ReadLine ()) != null) {
77 if (str
.StartsWith ("#"))
80 // Handle line continuation
82 while (str
.Trim ().EndsWith ("\\") && ((str2
= TextReader
.ReadLine ()) != null) ) {
87 str
= str
.Substring (0, str
.Length
- 1) + " " + str2
.Trim ();
93 // check for meta data
94 MatchCollection matches
;
95 matches
= metadata_pattern
.Matches (str
);
97 if (matches
.Count
> 0) {
98 foreach (Match the_match
in matches
) {
99 String key
= the_match
.Groups
["key"].ToString ();
100 String val
= the_match
.Groups
["value"].ToString ();
101 if (key
.Equals ("DESCRIPTION"))
102 Summary
= val
; // Ebuild descriptions are short - use them as summary.
103 else if (key
.Equals ("LICENSE"))
104 AddProperty (Beagle
.Property
.NewUnsearched ("dc:rights", val
));
105 else if (key
.Equals ("HOMEPAGE"))
109 // check for einfo/ewarn
110 matches
= einfo_pattern
.Matches (str
);
111 if (matches
.Count
> 0) {
112 foreach (Match the_match
in matches
)
113 AppendText (the_match
.Groups
["message"].ToString ());