File: extract.pl

package info (click to toggle)
metacity-themes 1.0.13
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 500 kB
  • sloc: perl: 377; makefile: 14; sh: 6
file content (79 lines) | stat: -rwxr-xr-x 2,132 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w
#
# extract.pl
# A script to extract files from each theme.
# This should be called *before* doing anything with the documentation.
#
# Licensed under the GPL-2
# © 2009 Mauro Lizaur <mauro@cacavoladora.org>
#

use warnings;
use strict;
use debian::themedata; 
use FileHandle;

my $PWD = `pwd`;
chomp($PWD);
my $DOCDIR = "debian/metacity-themes/usr/share/doc/metacity-themes";
my $THEMEDIR = "debian/metacity-themes/usr/share/themes";
my $TMPDIR = "debian/tmp";

&make_extract_themes();
print "\nDone";

sub extract_themes {
   my @x=@_;
   my $file=$x[0];
   my $path=$x[1];

   if ($file=~ m/gz$/){
       `tar zxf $file -C $path`;
   }else{
       `bunzip2 -k -c $file | tar -x -C $path`;
   }
}

sub fix_themes {
    my $tweak=$_[0];
    my $name=$_[1];
    my $file=$_[2];

    my $tarball=$file;
    if( $tweak eq 1 ){
        mkdir $TMPDIR;
        &extract_themes( ($file, $TMPDIR) );
        $tarball="TWEAK-".$name.".tar.gz";
        chdir($TMPDIR);
        my $themepath=`ls -F1|grep -e "/\$"`;
        chomp($themepath);
        my @docfiles=map { $themepath.$_; } split("\n",`ls $themepath`);
        my $docfiles=join(" ",@docfiles);
        `cp $docfiles $themepath$name`;
        `mv $themepath$name .`;
        `tar czvf $tarball $name`;
        `cp $tarball ../..`;
        chdir($PWD);
        `rm -fr debian/tmp`;
    }
    return $tarball;
}

sub make_extract_themes(){
    print "\nExtracting themes...\n";
    # Creates documentation for the themes which were installed.
    foreach my $theme (@themedata::installed){
        unless (-e "$THEMEDIR/$theme->{name}"){
            if (mkdir "$THEMEDIR/$theme->{name}"){
                print "$theme->{name}: created theme directory, $THEMEDIR/$theme->{name}.\n";
            }else{
                die "Error creating theme doc directory, $THEMEDIR/$theme->{name}\: $!\n";
            }
        }
        
        # /ugly/ hack to fix some themes that aren't extracted /correctly/
        my $filename = fix_themes( ($theme->{tweak}, $theme->{name}, $theme->{filename}) );
        &extract_themes( ($filename, $THEMEDIR) );
        
    }
}