QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / Filters / FilterDeb.cs
blob972e126c1d951880b6d7059a2ef94178e8b3ff01
1 //
2 // FilterDeb.cs
3 //
4 // Copyright (C) 2006 Kevin Kubasik <kevin@kubasik.net>
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.
26 using System;
27 using System.IO;
28 using System.Diagnostics;
30 using Beagle.Daemon;
31 using Beagle.Util;
33 namespace Beagle.Filters {
34 public class FilterDeb : Beagle.Filters.FilterPackage {
36 public FilterDeb ()
38 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/x-deb"));
41 protected override void PullPackageProperties ()
43 SafeProcess pc = new SafeProcess ();
44 pc.Arguments = new string [] { "dpkg-deb", "-I", FileInfo.FullName};
45 pc.RedirectStandardOutput = true;
47 try {
48 pc.Start ();
49 } catch (SafeProcessException e) {
50 Log.Warn (e.Message);
51 Error ();
52 return;
55 StreamReader pout = new StreamReader (pc.StandardOutput);
57 string str = null;
58 string[] tokens = null;
59 char[] splits = { ',', '|'};
60 string[] list = null;
62 while ((str = pout.ReadLine ()) != null) {
63 tokens = str.Split (':');
64 if (tokens.Length <= 1)
65 continue;
67 switch (tokens[0].Trim ()) {
69 case "Package":
70 PackageName = tokens[1];
71 break;
73 case "Maintainer":
74 list = tokens [1].Split ('<');
75 PackagerName = list [0];
76 if (list.Length > 1)
77 PackagerEmail = list [1].Replace ('>', ' ');
78 break;
80 case "Version":
81 PackageVersion = tokens[1];
82 break;
84 case "Section":
85 Category = tokens [1];
86 break;
88 case "Architecture":
89 AddProperty (Beagle.Property.NewUnsearched ("fixme:arch", tokens [1]));
90 break;
92 case "Depends":
93 list = tokens [1].Split (splits);
94 foreach (string s in list)
95 AddProperty (Beagle.Property.NewUnsearched ("fixme:depends", s));
96 break;
98 case "Recommends":
99 list = tokens [1].Split (splits);
100 foreach (string s in list)
101 AddProperty (Beagle.Property.NewUnsearched ("fixme:recommend", s));
102 break;
104 case "Conflicts":
105 list = tokens [1].Split (splits);
106 foreach (string s in list)
107 AddProperty (Beagle.Property.NewUnsearched ("fixme:conflict", s));
108 break;
110 case "Replaces":
111 list = tokens [1].Split (splits);
112 foreach (string s in list)
113 AddProperty (Beagle.Property.NewUnsearched ("fixme:replaces", s));
114 break;
116 case "Provides":
117 list = tokens [1].Split (splits);
118 foreach (string s in list)
119 AddProperty (Beagle.Property.NewUnsearched ("fixme:provides", s));
120 break;
122 case "Installed-Size":
123 // Installed-Size is given in number of KBs
124 AddProperty (Beagle.Property.NewUnsearched ("fixme:size", tokens [1] + "000"));
125 break;
127 case "Description":
128 AppendText (tokens [1]);
129 AppendStructuralBreak ();
130 while ((str = pout.ReadLine ()) != null) {
131 if(str.Trim () == ".")
132 AppendStructuralBreak ();
133 else
134 AppendText (str);
136 break;
140 pout.Close ();
141 pc.Close ();