SVG::Metadata 0.18 release Re: [Clipart] Keys in flags and svg_annotate feature request

Bryce Harrington bryce at bryceharrington.com
Mon Oct 4 22:48:53 PDT 2004


On Mon, 4 Oct 2004, Christian Fredrik Kalager Schaller wrote:
> As stated I still have a lot of work remaining and to get that done I
> have some feature requests for svg_annotate.
> 
> a) include the keyword setting as part of svg_annotate

I've implemented a -k flag for svg_annotate to do this.  The package is
submitted to CPAN so should be available shortly.

What I need you to do is test this out fairly thoroughly, including the
-k, --keyword, and <KEYWORD> capabilities that have now be implemented.
Tell me of anything that does not work right.

> b) let me set a special word like 'prompt' as the value and svg_annotate
> will prompt me for values for each svg instead of forcing me to set a
> global variable

I won't be implementing interactive prompting in SVG::Metadata, but
would accept a script or patch if someone else wishes to do this.

> c) when running svg_annotate *.svg without a title it takes the filename
> of the first file as 'title' for all the files. It would be better if it
> took the filename for each file and used as title.

I'll look into this later

Hope this helps, let me know,
Bryce

> Christian 
> 
> 
> On Sat, 2004-10-02 at 02:36, Jonadab the Unsightly One wrote:
> > Christian Fredrik Kalager Schaller <uraeus at linuxrising.org> writes:
> > 
> > > Ok, I now have the latest svg_anotate working well for me. Only thing is
> > > how am I supposed to add the keywords? there is no -k option for
> > > svg_annotate and I assume I am not meant to add them to the title?
> > 
> > For adding keywords, use this script:
> > 
> > #!/usr/bin/perl
> > # -*- cperl -*-
> > 
> > use SVG::Metadata;
> > use File::Spec::Functions;
> > use Data::Dumper; $|=1;
> > 
> > if (not @ARGV) {
> >   printusage(); exit 0;
> > }
> > 
> > my @file = grep { not /^-/ } @ARGV;
> > my %flag = map { s/^-//; (/^-([^=]+)=(.*)/) ? ($1, $2) : ($_, 1) } grep { /^-/ } @ARGV;
> > $flag{dir} ||= ".";
> > 
> > process(\%flag, @file); exit 0;
> > 
> > sub process {
> >   my %flag = %{shift at _};
> >   warn "[Looking at @_]" if $flag{debug}>1;
> >   for $f (@_) {
> >     if (-f $f) {
> >       processfile(\%flag, $f);
> >     } elsif ($flag{r} and -d $f) {
> >       if (opendir DIR, $f) {
> >         warn "Descending into $f...\n" if $flag{debug};
> >         my @f   = map { catfile($flag{dir}, $f, $_) } grep { not /^[.]+$/ } readdir DIR; closedir DIR;
> >         my ($k) = $f =~ /(\w+)\s*$/;
> >         my %f   = %flag; $f{keywords} .= ",$k";
> >         $f{dir} = catfile($flag{dir}, $f);
> >         if ($f{rlimit}) {
> >           $f{rlimit}--; $f{r} = 0 unless $f{rlimit};
> >         }
> >         warn "Descending with flags: " . Dumper(\%f) if $flag{debug} > 1;
> >         process(\%f, @f);
> >       } else {
> >         warn "Cannot descend into $f: $!\n";
> >       }
> >     } elsif (-d $f) {
> >       warn "Ignoring directory $f (use -r to descend recursively into directories)\n";
> >     } else {
> >       warn "Ignoring $f (not a regular file, not a directory)\n";
> >     }
> >   }
> > }
> > 
> > sub processfile {
> >   # This version only supports SVG with embedded RDF:
> >   my %flag = %{shift at _};
> >   my ($file) = @_;
> > 
> >   warn "Processing $file\n" if $flag{debug}>1;
> >   my $meta = SVG::Metadata->new();
> >   $meta->parse($file) or warn "Failed to parse existing metadata for $file\n";
> >   warn "Starting metadata for $file:  " . Dumper(\$meta) if $flag{debug}>3;
> >   for (split /[,]/, $flag{keywords}) { $meta->addKeyword($_) }
> > 
> >   open SVG, "<" . $file or die "Cannot read $file: $!\n";
> >   my $svg; { local $/ = undef; $svg = <SVG> } close SVG;
> >   my $rdf = $meta->to_rdf();
> > 
> >   $svg =~ s|\s*<$_.*?</$_>||gs for 'metadata', 'rdf:RDF', 'rdf'; # Remove old RDF
> >   $svg =~ s|(?=</svg>)|$rdf|s;                                # Insert new RDF
> > 
> >   open SVG, ">" . $file or die "Cannot write $file: $!\n";
> >   print SVG $svg; close SVG;
> > }
> > 
> > sub printusage {
> >   print <<"USAGE";
> > USAGE:
> >     $0 [options] files
> > 
> > EXAMPLES:
> >     $0 --keywords=party,festive,fun confetti-01.svg confetti-02.svg baloons-01.svg
> >          Adds the keywords 'party', 'festive', and 'fun' to those three SVG images.
> >     $0 -r *
> >          Descends recursively from the current directory, adding keywords to all the
> >          SVG images for each directory it descends through.  For example, the image
> >          in foo/bar/baz.svg will have the keywords 'foo' and 'bar' added.
> > 
> > OPTIONS:
> >     Any option preceded by a single hyphen is given a value of 1.  Any option preceded
> >     by two hyphens must have an equal sign and a value, as with the keywords option
> >     in the example.  This assigns the value after the equal sign to the option.
> > 
> >   SPECIFIC OPTIONS:
> >     debug      Turn on extra debugging output.  Higher value mean more info.
> >     keywords   Comma-separated list of whitespace-free keywords to add.
> >     r          Recurse through subdirectories, adding the subdirectory name to
> >                the list of keywords for everything under that subdirectory.
> > 
> > CAVEATS:
> >    Early versions of SVG::Metadata do not parse existing keywords.  If you use
> >    this program with one of those versions, existing keywords will be removed
> >    as a result of this, and only the keywords you add will remain.  You need
> >    at least version 0.14 of SVG::Metadata installed to avoid this.
> > 
> >    Additionally, any other metadata not fully supported by SVG::Metadata will
> >    be lost.  Please test on duplicate copies of your files before trusting this
> >    with your only copy of anything, to ensure that you do not lose any important
> >    metainformation.
> > 
> > USAGE
> > }
> > 
> > _______________________________________________
> > clipart mailing list
> > clipart at freedesktop.org
> > http://freedesktop.org/mailman/listinfo/clipart
> 
> _______________________________________________
> clipart mailing list
> clipart at freedesktop.org
> http://freedesktop.org/mailman/listinfo/clipart
> 
> 



More information about the clipart mailing list