On 12-08-18 at 12:36am, Andreas Tille wrote:
> On Fri, Aug 17, 2012 at 11:03:27PM +0200, Jonas Smedegaard wrote:
> > > I admit I'm not very experienced with Perl and reading RFC822 files - 
> > > so if somebody would help implementing this I'd be glad.
> > 
> >   grep-dctrl -FFormat -n -sFiles-Excluded \
> >   http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 \
> >   < debian/copyright
> > 
> > Result should be a space-separated list of files or dirs consumable by 
> > find, as documented in copyright format.
> 
> Well, uscan makes some use of system so this could work - but I hoped
> for a more Perl-ish solution (similar to the rfc822 reader in
> python-debian).

Is this Perl-ish enough for you?:

#!/usr/bin/perl -w
use Parse::DebControl;
use feature "say";
$okformat = 
qr'http://www.debian.org/doc/packaging-manuals/copyright-format/1.0';
$parser = new Parse::DebControl(1);
$data = $parser->parse_file($ARGV[0], {
    discardCase=>1,
    singleBlock=>1,
});
die unless ($data->{"format"} =~ m{^$okformat/?$});
foreach (grep {/\//} split /\s+/, $data->{"files-excluded"}) {
    say 'dir: '.$_;
};
foreach (grep {/^[^\/]+$/} split /\s+/, $data->{"files-excluded"}) {
    say 'file: '.$_;
};


Replace "say..." with calls to find ... -delete.


 - Jonas

-- 
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

Attachment: signature.asc
Description: Digital signature

Reply via email to