Hello community,

here is the log from the commit of package brp-extract-appdata for 
openSUSE:Factory checked in at 2012-03-07 13:41:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/brp-extract-appdata (Old)
 and      /work/SRC/openSUSE:Factory/.brp-extract-appdata.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "brp-extract-appdata", Maintainer is ""

Changes:
--------
--- /work/SRC/openSUSE:Factory/brp-extract-appdata/brp-extract-appdata.changes  
2012-03-02 13:47:02.000000000 +0100
+++ 
/work/SRC/openSUSE:Factory/.brp-extract-appdata.new/brp-extract-appdata.changes 
    2012-03-07 13:41:34.000000000 +0100
@@ -1,0 +2,5 @@
+Wed Mar  7 09:25:17 UTC 2012 - co...@suse.com
+
+- adding extract-icons.pl script to be called for kiwi products
+
+-------------------------------------------------------------------

New:
----
  extract-icons.pl

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ brp-extract-appdata.spec ++++++
--- /var/tmp/diff_new_pack.AYyetE/_old  2012-03-07 13:41:39.000000000 +0100
+++ /var/tmp/diff_new_pack.AYyetE/_new  2012-03-07 13:41:39.000000000 +0100
@@ -25,11 +25,20 @@
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 Source0:        %{name}.pl
 Source1:        create-appdata-xml.pl
+Source2:        extract-icons.pl
 BuildArch:      noarch
 
 %description
 Extract appdata.xml from all .deskop files found in build root
 
+%package -n extract-appdata-icons
+Summary:        A little perl script to split appdata.xml
+Group:          Development/Tools/Building
+
+%description -n extract-appdata-icons
+OBS generated appdata.xml contains all icons and this little tool splits
+the XML into the format expected from software center
+
 %prep
 
 %build
@@ -37,10 +46,15 @@
 %install
 install -m0755 -D %SOURCE0 
$RPM_BUILD_ROOT%_rpmconfigdir/brp-suse.d/brp-72-extract-appdata
 install -m0755 -D %SOURCE1 
$RPM_BUILD_ROOT/usr/lib/build/checks/72-translate-appdata
+install -m0755 -D %SOURCE2 $RPM_BUILD_ROOT/usr/bin/extract-appdata-icons
 
 %files
 %defattr(-,root,root)
 %_rpmconfigdir/brp-suse.d
 /usr/lib/build
 
+%files -n extract-appdata-icons
+%defattr(-,root,root)
+/usr/bin/extract-appdata-icons
+
 %changelog

++++++ extract-icons.pl ++++++
#! /usr/bin/perl

# Copyright (c) 2012 Stephan Kulow, SUSE Linux Products GmbH

# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use strict;
use XML::Simple;
use Data::Dumper;
use File::Temp;
use MIME::Base64;
use Cwd;
use File::Path;

my %ids;

sub find_perfect_match($)
{
  my ($ref) = @_;
  my @candidates = sort @$ref;
  if (@candidates == 1) {
    return $candidates[0];
  }
  foreach my $size (qw(32 48 64 24 )) {
    my @sized_icons;
    my $pattern = "/$size" . "x$size/";
    for my $can (@candidates) {
      push(@sized_icons,$can) if ($can =~ m/($pattern)/);
    }
    return $sized_icons[0] if (@sized_icons == 1);
    if (@sized_icons) {
      for my $can (@sized_icons) {
        return $can if ($can =~ m,/hicolor/,);
      }
      print "UNKNOWN $size " . join(' , ', @sized_icons) . "\n";
      return $sized_icons[0];
    }
  }
  print "UNKNOWN " . join(' , ', @candidates) . "\n";
  return $candidates[0];
}

sub extract_icon($$)
{
  my ($ref, $tmpdir) = @_;
  my $name = 'fancy';
  my $name = shift @{$ref->{name}};

  return $name unless ($ref->{filecontent});
  my %files;
  my @fcontent = @{$ref->{filecontent}};
  foreach my $icon (@fcontent) {
     $files{$icon->{file}} = $icon->{content};
  }
  my @candidates = keys %files;
  my $best = find_perfect_match(\@candidates);
  my $suffix = $best;
  $suffix =~ s,^.*\.([^.]*)$,$1,;
  open(ICON, ">", "$tmpdir/$name.$suffix"); 
  print ICON decode_base64($files{$best});
  close(ICON);
  #print "$name $best\n";
  return $name;
}

if (@ARGV != 2 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
  print "Usage: $0 <appdata.xml> <outdir>\n";
  print "  It will output appdata.xml and appdata-icon.tar.gz in outdir\n";
  exit(1);
}

my $inputfile = $ARGV[0];
my $outdir = $ARGV[1];

if (! -d $outdir) {
  print "Output directory must exist.\n";
  exit(1);
} 
 
my $xml = XMLin($inputfile, ForceArray => 1) || die "can't parse $inputfile";
my $apps = $xml->{application};
my $tmpdir = mkdtemp("/tmp/icons.XXXXXX");
my @napps;
for my $app ( @$apps) {
  my $id = shift @{$app->{id}};
  next if defined $ids{$id->{content}};
  $ids{$id->{content}} = 1;
  my $icon = extract_icon(@{$app->{icon}}[0], $tmpdir);
  $app->{icon} = [ { "type" => "local", "content" => $icon } ];
  push(@napps, $app);
}

$xml->{application} = \@napps;
$xml = XMLout($xml, RootName => "applications");

chdir($outdir) || die "can't change into $outdir";
my $cpwd = getcwd;

chdir($tmpdir);
system("tar", "czf", "$cpwd/app-icons.tar.gz", ".");
chdir($cpwd);
rmtree($tmpdir);
open(XML, ">", "$cpwd/appdata.xml");
print XML "$xml";
close(XML);
-- 
To unsubscribe, e-mail: opensuse-commit+unsubscr...@opensuse.org
For additional commands, e-mail: opensuse-commit+h...@opensuse.org

Reply via email to