Inital Deb Filter
- From: Kevin Kubasik <kevin kubasik net>
- To: "dashboard-hackers gnome org" <dashboard-hackers gnome org>
- Subject: Inital Deb Filter
- Date: Fri, 31 Mar 2006 00:08:01 -0500
Let me know what you all think. This is my first shot, hope it works
out. I looked into using one of Mono's decompression libs to extract the
actual description information, but .deb's are in the somewhat obscure
ar archive format. So dpkg-deb it was. If anyone can think of a property
I missed, please let me know, they are quite easy to add.
Also, is there a major objection to just adding the Description field as
text? and furthermore, is it ok that this happens in DoPullProperties()?
as opposed to DoPull()?
--
Cheers,
Kevin Kubasik <kevin kubasik net>
http://blog.kubasik.net
using System;
using System.IO;
using System.Diagnostics;
using Beagle.Daemon;
using Beagle.Util;
namespace Beagle.Filters{
public class FilterDeb : Beagle.Daemon.Filter {
public FilterDeb (){
AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/x-deb"));
AddSupportedFlavor (FilterFlavor.NewFromExtension(".deb") );
}
protected override void DoPullProperties (){
Process pc = new Process ();
pc.StartInfo.FileName = "dpkg-deb";
pc.StartInfo.Arguments = " -I "+ FileInfo.FullName ;
pc.StartInfo.RedirectStandardInput = false;
pc.StartInfo.RedirectStandardOutput = true;
pc.StartInfo.RedirectStandardError = true;
pc.StartInfo.UseShellExecute = false;
try {
pc.Start ();
} catch (System.ComponentModel.Win32Exception) {
Log.Warn ("Error: 'dpkg-deb' command not found or unable to run");
Error ();
return;
}
StreamReader pout = pc.StandardOutput;
string str = null;
string[] tokens = null;
string strMetaTag = null;
bool bKeyword = false;
bool listWords = false;
char[] splits = {',','|'};
string[] list = null;
while ((str = pout.ReadLine ()) != null) {
bKeyword = false;
listWords = false;
strMetaTag = null;
tokens = str.Split (':');
if (tokens.Length > 1) {
switch (tokens[0].Trim()) {
case "Package":
strMetaTag = "dc:title";
break;
case "Maintainer":
strMetaTag = "dc:author";
break;
case "Version":
strMetaTag = "fixme:version";
bKeyword = true;
break;
case "Section":
strMetaTag = "fixme:section";
bKeyword = true;
break;
case "Architecture":
strMetaTag = "fixme:arch";
bKeyword = true;
break;
case "Depends":
listWords = true;
list = tokens[1].Split(splits);
foreach(string s in list){
AddProperty (Beagle.Property.NewKeyword ("fixme:dep",
s.Trim()));
}
break;
case "Recommends":
listWords = true;
list = tokens[1].Split(splits);
foreach(string s in list){
AddProperty (Beagle.Property.NewKeyword ("fixme:recommend",
s.Trim()));
}
break;
case "Conflicts":
listWords = true;
list = tokens[1].Split(splits);
foreach(string s in list){
AddProperty (Beagle.Property.NewKeyword ("fixme:conflict",
s.Trim()));
}
break;
case "Replaces":
listWords = true;
list = tokens[1].Split(splits);
foreach(string s in list){
AddProperty (Beagle.Property.NewKeyword ("fixme:replace",
s.Trim()));
}
break;
case "Provides":
listWords = true;
list = tokens[1].Split(splits);
foreach(string s in list){
AddProperty (Beagle.Property.NewKeyword ("fixme:provide",
s.Trim()));
}
break;
case "Installed-Size":
strMetaTag = "fixme:size";
bKeyword= true;
break;
case "Description":
listWords=true;
AppendText(tokens[1]);
AppendStructuralBreak ();
while ((str = pout.ReadLine ()) != null) {
if(str.Trim()==".")
AppendStructuralBreak();
else
AppendText(str);
}
break;
}
if (strMetaTag != null) {
if(!listWords){
if (bKeyword){
AddProperty (Beagle.Property.NewKeyword (strMetaTag,
tokens[1].Trim()));
}
else{
AddProperty (Beagle.Property.New (strMetaTag,
tokens[1].Trim()));
}
}
}
}
}
pout.Close ();
pc.WaitForExit ();
pc.Close ();
Finished ();
}
}
}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]