~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/toolkit/mozapps/installer/makejs.pl

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!c:\perl\bin\perl
 
2
 
3
# The contents of this file are subject to the Netscape Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/NPL/
 
7
#  
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
#  
 
13
# The Original Code is Mozilla Communicator client code, released
 
14
# March 31, 1998.
 
15
 
16
# The Initial Developer of the Original Code is Netscape
 
17
# Communications Corporation. Portions created by Netscape are
 
18
# Copyright (C) 1998-1999 Netscape Communications Corporation. All
 
19
# Rights Reserved.
 
20
 
21
# Contributor(s): 
 
22
# Sean Su <ssu@netscape.com>
 
23
 
24
 
 
25
#
 
26
# This perl script parses the input file for special variables
 
27
# in the format of $Variable$ and replace it with the appropriate
 
28
# value(s).
 
29
#
 
30
# Input: .jst file              - which is a .js template
 
31
#        default version        - a date in the form of:
 
32
#                                 major.minor.release.yyyymmdyhr
 
33
#                                 ie: 5.0.0.1999120910
 
34
#        component staging path - path to where the components are staged at
 
35
#
 
36
#        ie: perl makejs.pl xpcom.jst 5.0.0.99256
 
37
#
 
38
 
 
39
use File::Copy;
 
40
use File::Basename;
 
41
use Cwd;
 
42
 
 
43
# Make sure there are at least three arguments
 
44
if($#ARGV < 2)
 
45
{
 
46
  die "usage: $0 <.jst file> <default version> <staging path>
 
47
 
 
48
       .jst file              : .js template input file
 
49
       default version        : default julian base version number to use in the
 
50
                                form of: major.minor.release.yydoy
 
51
                                ie: 5.0.0.99256
 
52
       component staging path : path to where this component is staged at
 
53
                                ie: z:/stage/windows/32bit/en/5.0/xpcom
 
54
       \n";
 
55
}
 
56
 
 
57
$DEPTH = "../../..";
 
58
$topsrcdir        = GetTopSrcDir();
 
59
$inJstFile        = $ARGV[0];
 
60
$inVersion        = $ARGV[1];
 
61
$inStagePath      = $ARGV[2];
 
62
 
 
63
# get environment vars
 
64
$userAgent        = $ENV{WIZ_userAgent};
 
65
$userAgentShort   = $ENV{WIZ_userAgentShort};
 
66
$xpinstallVersion = $ENV{WIZ_xpinstallVersion};
 
67
$nameCompany      = $ENV{WIZ_nameCompany};
 
68
$nameProduct      = $ENV{WIZ_nameProduct};
 
69
$nameProductInternal = $ENV{WIZ_nameProductInternal};
 
70
$shortNameProduct = $ENV{WIZ_shortNameProduct};
 
71
$fileMainExe      = $ENV{WIZ_fileMainExe};
 
72
$fileUninstall    = $ENV{WIZ_fileUninstall};
 
73
$greBuildID       = $ENV{WIZ_greBuildID};
 
74
$greFileVersion   = $ENV{WIZ_greFileVersion};
 
75
$greUniqueID      = $ENV{WIZ_greUniqueID};
 
76
$greVersion       = $ENV{WIZ_greVersion};
 
77
 
 
78
# Get the name of the file replacing the .jst extension with a .js extension
 
79
$inJstFileBase    = $inJstFile;
 
80
$inJstFileBase    =~ s/\.jst//;
 
81
$outJsFile        = "$inJstFileBase.js";
 
82
$outTempFile      = "$inJstFileBase.template";
 
83
$foundLongFiles   = 0;
 
84
 
 
85
print " copy \"$topsrcdir/xpinstall/packager/common/share.t\" $outTempFile\n";
 
86
copy("$topsrcdir/xpinstall/packager/common/share.t", "$outTempFile");
 
87
system("cat $inJstFile >> $outTempFile");
 
88
 
 
89
# Open the input .template file
 
90
open(fpInTemplate, $outTempFile) || die "\ncould not open $outTempFile: $!\n";
 
91
 
 
92
# Open the output .js file
 
93
open(fpOutJs, ">$outJsFile") || die "\nCould not open $outJsFile: $!\n";
 
94
 
 
95
# While loop to read each line from input file
 
96
while($line = <fpInTemplate>)
 
97
{
 
98
  if($line =~ /\$SpaceRequired\$/i) # For each line read, search and replace $SpaceRequired$ with the calculated size
 
99
  {
 
100
    $spaceRequired = 0;
 
101
 
 
102
    # split read line by ":" deliminator
 
103
    @colonSplit = split(/:/, $line);
 
104
    if($#colonSplit > 0)
 
105
    {
 
106
      @semiColonSplit = split(/;/, $colonSplit[1]);
 
107
      $subDir         = $semiColonSplit[0];
 
108
      $spaceRequired  = GetSpaceRequired("$inStagePath/$subDir");
 
109
      $line =~ s/\$SpaceRequired\$:$subDir/$spaceRequired/i;
 
110
    }
 
111
    else
 
112
    {
 
113
      $spaceRequired = GetSpaceRequired("$inStagePath");
 
114
      $line =~ s/\$SpaceRequired\$/$spaceRequired/i;
 
115
    }
 
116
  }
 
117
  else
 
118
  {
 
119
    $line =~ s/\$Version\$/$inVersion/i;
 
120
    $line =~ s/\$UserAgent\$/$userAgent/i;
 
121
    $line =~ s/\$UserAgentShort\$/$userAgentShort/i;
 
122
    $line =~ s/\$XPInstallVersion\$/$xpinstallVersion/i;
 
123
    $line =~ s/\$CompanyName\$/$nameCompany/i;
 
124
    $line =~ s/\$ProductName\$/$nameProduct/i;
 
125
    $line =~ s/\$ProductShortName\$/$shortNameProduct/i;
 
126
    $line =~ s/\$ProductNameInternal\$/$nameProductInternal/gi;
 
127
    $line =~ s/\$MainExeFile\$/$fileMainExe/i;
 
128
    $line =~ s/\$UninstallFile\$/$fileUninstall/i;
 
129
    $line =~ s/\$GreBuildID\$/$greBuildID/gi;
 
130
    $line =~ s/\$GreFileVersion\$/$greFileVersion/gi;
 
131
    $line =~ s/\$GreUniqueID\$/$greUniqueID/gi;
 
132
    $line =~ s/\$GreVersion\$/$greVersion/gi;
 
133
  }
 
134
 
 
135
  print fpOutJs $line;
 
136
}
 
137
 
 
138
close(fpInTemplate);
 
139
close(fpOutJs);
 
140
exit(0);
 
141
 
 
142
sub GetSpaceRequired()
 
143
{
 
144
  my($inPath) = @_;
 
145
  my($spaceRequired) = 0;
 
146
 
 
147
  print "   calculating size for $inPath\n";
 
148
  if ($win32) {
 
149
      $spaceRequired    = `\"$ENV{WIZ_distInstallPath}/ds32.exe\" /D /L0 /A /S /C 32768 $inPath`;
 
150
  } else {
 
151
      @dirEntries = <$inPath/*>;
 
152
 
 
153
    # iterate over all dir entries
 
154
    foreach $item ( @dirEntries )
 
155
    {
 
156
        # if dir entry is dir
 
157
        if (-d $item)
 
158
        {
 
159
            # add GetSpaceRequired(<dirEntry>) to space used
 
160
            $spaceRequired += GetSpaceRequired($item);
 
161
        }
 
162
        # else if dir entry is file
 
163
        elsif (-e $item)
 
164
        {
 
165
            # add size of file to space used
 
166
            $spaceRequired += (-s $item);
 
167
        }
 
168
    }
 
169
  }
 
170
 
 
171
  $spaceRequired    = int($spaceRequired / 1024);
 
172
  $spaceRequired   += 1;
 
173
  return($spaceRequired);
 
174
}
 
175
 
 
176
sub ParseUserAgentShort()
 
177
{
 
178
  my($aUserAgent) = @_;
 
179
  my($aUserAgentShort);
 
180
 
 
181
  @spaceSplit = split(/ /, $aUserAgent);
 
182
  if($#spaceSplit >= 0)
 
183
  {
 
184
    $aUserAgentShort = $spaceSplit[0];
 
185
  }
 
186
 
 
187
  return($aUserAgentShort);
 
188
}
 
189
 
 
190
sub GetTopSrcDir
 
191
{
 
192
  my($rootDir) = dirname($0) . "/$DEPTH";
 
193
  my($savedCwdDir) = cwd();
 
194
 
 
195
  chdir($rootDir);
 
196
  $rootDir = cwd();
 
197
  chdir($savedCwdDir);
 
198
  return($rootDir);
 
199
}
 
200