Re: Inital Deb Filter



Hi,

On Fri, 2006-03-31 at 00:08 -0500, Kevin Kubasik wrote:
> 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.

Can you attach some sample dpkg-deb output?  I don't have a Debian or
Ubuntu box, so it's hard to see if we're doing the right thing with
regards to parsing.

> 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()? 

That's fine.
        
>         public FilterDeb (){
>                 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/x-deb"));
>                 AddSupportedFlavor (FilterFlavor.NewFromExtension(".deb") );
>         }

Are both of these necessary?  I prefer to avoid setting NewFromExtension
unless there's a chance that the mime type detection won't work without
it.

>                         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()));
>                                                         }
>                                                 }
>                                         }

Sorry for quoting such a big block.  A few things here.  First, the
entire code block is within a "if (tokens.Length > 1)" block.  We can
remove an entire level of indentation by just saying "if (tokens.Length
<= 1) continue;" here, assuming it's not an error.

Also, rather than setting strMetaTag, bKeyword, listWords and a handfull
of other variables and carrying that state through, I think it'd be lot
easier to just add a AddProp() and AddKeyword() method and just call
those when you need to.  Method overhead is negligible.  And that
removes the nasty special case you do for listWords anyway.

Joe




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]