Debian Codegraph @

tools/updt_embedded_rsc.pl

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/perl
2 #-----------------------------------------------------------------------------
3 #
4 # Script used to update javascript and css files embedded into pgcluu.
5 # It will replace all content after the __DATA__ in the right order with
6 # the files content stored into the resources/min/ directory.
7 #
8 # This script must be executed from the main source repository as follow:
9 # 
10 # This script must be executed from the main source repository as follow:
11 #  ./tools/updt_embedded_rsc.pl
12 #
13 # The fontawesome.css must also embedded the TrueType font, this is done
14 #-----------------------------------------------------------------------------
15 use strict;
16
17 my $RSC_DIR = 'resources';
18 my $PGCLUU_PROG = 'pgcluu';
19 my $DEST_TMP_FILE = 'pgcluu.new';
20 my $CGI_DEST_DIR = 'cgi-bin/rsc';
21
22 # Ordered resources files list
23 my @rsc_list = qw(jquery.jqplot.css jquery.js jquery.jqplot.js jqplot.pieRenderer.js jqplot.barRenderer.js jqplot.dateAxisRenderer.js jqplot.canvasTextRenderer.js jqplot.categoryAxisRenderer.js jqplot.canvasAxisTickRenderer.js jqplot.canvasAxisLabelRenderer.js jqplot.highlighter.js jqplot.highlighter.js jqplot.cursor.js jqplot.pointLabels.js bean.js underscore.js bootstrap.css bootstrap-datetimepicker.css fontawesome.css bootstrap.js bootstrap-datetimepicker.js pgcluu_slide.js pgcluu.css pgcluu.js sorttable.js w3.js);
24 my @min_rsc_list = ();
25
26 if (!-d $RSC_DIR) {
27 die "FATAL: can't find directory: $RSC_DIR.\n";
28 }
29
30 # Apply patch on jquery.jqplot.js to fix infinite loop
31 # May be removed with next jqplot release update
32 `patch -r - -s -N resources/jquery.jqplot.js -i resources/patch-jquery.jqplot.js`;
33
34 # Apply patch on sorttable.js to allow sort on human size
35 # and always start sort in reverse order
36 `patch -r - -s -N resources/sorttable.js -i resources/patch-sorttable.js`;
37
38 # Generate all minified resources files
39 mkdir "$RSC_DIR/min";
40 foreach my $f (@rsc_list) {
41 my $dest = $f;
42 $dest =~ s/\.(js|css)$/.min.$1/;
43 push(@min_rsc_list, $dest);
44 # minify resources files
45 `yui-compressor $RSC_DIR/$f -o $RSC_DIR/min/$dest`;
46 }
47
48 # Embedded fontawesome webfont into the CSS file as base64 data
49 print `base64 -w 0 $RSC_DIR/font/FontAwesome.otf > $RSC_DIR/font/FontAwesome.otf.b64`;
50 open(IN, "$RSC_DIR/font/FontAwesome.otf.b64") or die "FATAL: can't open file $RSC_DIR/font/FontAwesome.otf.b64, $!\n";
51 my $b64_font = <IN>;
52 close(IN);
53
54 # Update minimized fontawesome.css file
55 open(IN, "$RSC_DIR/min/fontawesome.min.css") or die "FATAL: can't open file $RSC_DIR/min/fontawesome.min.css\n";
56 my @content = <IN>;
57 close(IN);
58 open(OUT, ">$RSC_DIR/min/fontawesome.min.css") or die "FATAL: can't write to file $RSC_DIR/min/fontawesome.min.css\n";
59 foreach my $l (@content) {
60 $l =~ s|;src:url.* format.* format\('svg'\);|;src: url('data:font\/opentype;charset=utf-8;base64,$b64_font') format('truetype');|;
61 print OUT $l;
62 }
63 close(OUT);
64
65 if (!-e $PGCLUU_PROG) {
66 die "FATAL: can't find pgcluu script: $PGCLUU_PROG\n";
67 }
68
69 # Extract content of pgcluu script until __DATA__ is found
70 my $content = '';
71 open(IN, $PGCLUU_PROG) or die "FATAL: can't open file $PGCLUU_PROG, $!\n";
72 while (<IN>) {
73 last if (/^__DATA__$/);
74 $content .= $_;
75 }
76 close(IN);
77
78 # Write script base to destination file
79 open(OUT, ">$DEST_TMP_FILE") or die "FATAL: can't write to file $DEST_TMP_FILE, $!\n";
80 print OUT $content;
81 print OUT "__DATA__\n";
82
83 # Append each minified resources file
84 foreach my $f (@min_rsc_list) {
85 print OUT "\nWRFILE: $f\n\n";
86 open(IN, "$RSC_DIR/min/$f") or die "FATAL: can't open file $RSC_DIR/min/$f, $!\n";
87 my @tmp = <IN>;
88 close(IN);
89 print OUT @tmp;
90 }
91 close(OUT);
92
93 # Clobber original pgcluu file.
94 rename($DEST_TMP_FILE, $PGCLUU_PROG) or die "FATAL: can't rename $DEST_TMP_FILE into $PGCLUU_PROG\n";
95
96 # Move minified resources files in the CGI directory
97 `mv $RSC_DIR/min/* $CGI_DEST_DIR/`;
98
99 # Change attibut of the script
100 `chmod 755 $PGCLUU_PROG`;
101
102 exit 0;