File brp-extract-appdata.pl of Package brp-extract-appdata

#! /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.

#
# find files and extract them for later processing
#
use File::Basename;
use File::Find;
use MIME::Base64;

my $basedir=dirname($ENV{'RPM_SOURCE_DIR'}) . "/OTHER";

my $outputfile = "$basedir/$ENV{'RPM_PACKAGE_NAME'}.applications";

if (! -f "/.buildenv") {
  # this looks fishy, skip it
  print "WARNING: I better not trim without a /.buildenv around\n";
  exit(0);
}

if (! -w "$basedir") {
  print "WARNING: Can't write to $BASEDIR, skipping\n";
  exit(0);
}

open(OUTPUT, '>', $outputfile);

chdir("/" . $ENV{'RPM_BUILD_ROOT'});

my @icondirs;

for my $prefix (qw{/usr /opt/kde3 usr opt/kde3}) {
   for my $suffix (qw{pixmaps icons/hicolor icons/crystalsvg icons/gnome}) {
      push(@icondirs, "$prefix/share/$suffix");
   }
}
find(\&wanted, "usr/share/applications/");

my @icons;

sub wanted
{
  return unless $_ =~ /\.desktop$/;
  print OUTPUT "<</$File::Find::name>>\n";
  open(DESKTOP, $_) or return;
  while ( <DESKTOP> ) {
    if ($_ =~ /^Icon=(.*)$/) { push(@icons, $1); }
    print OUTPUT $_;
  }
  close(DESKTOP);
}

our $icon;

sub outputicon
{
  return unless ($_ =~ /^$icon\.(png|svg|svgz|xpm)$/);
  open(my $icon, '<', $_) or return;
  my $content = do { local $/; <$icon> };
  close($icon);
  my $fname = $File::Find::name;
  $fname = "/$fname" unless $fname =~ m,^/,;
  print OUTPUT "<<$fname>>\n";
  print OUTPUT encode_base64($content) . "\n";
}

for $icon (@icons) {
  find(\&outputicon, @icondirs);
}

close(OUTPUT);
openSUSE Build Service is sponsored by