1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is the Mozilla build system
16 # The Initial Developer of the Original Code is Mozilla.
17 # Portions created by the Initial Developer are Copyright (C) 2009
18 # the Initial Developer. All Rights Reserved.
21 # Armen Zambrano Gasparnian <armenzg@mozilla.com>
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the GPL or the LGPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
35 # ***** END LICENSE BLOCK *****
38 This script generates the complete snippet for a given locale or en-US
39 Most of the parameters received are to generate the MAR's download URL
40 and determine the MAR's filename
42 import sys
, os
, platform
, sha
43 from optparse
import OptionParser
44 from ConfigParser
import ConfigParser
45 from stat
import ST_SIZE
49 parser
= OptionParser(
50 usage
="%prog [options]")
51 parser
.add_option("--mar-path",
54 help="[Required] Specify the absolute path where the MAR file is found.")
55 parser
.add_option("--application-ini-file",
57 dest
="applicationIniFile",
58 help="[Required] Specify the absolute path to the application.ini file.")
59 parser
.add_option("-l",
63 help="[Required] Specify which locale we are generating the snippet for.")
64 parser
.add_option("-p",
68 help="[Required] This option is used to generate the URL to download the MAR file.")
69 parser
.add_option("--platform",
72 help="[Required] This option is used to indicate which target platform.")
73 parser
.add_option("--branch",
76 help="This option is used to indicate which branch name to use for FTP file names.")
77 parser
.add_option("--download-base-URL",
79 dest
="downloadBaseURL",
80 help="This option indicates under which.")
81 parser
.add_option("-v",
86 help="This option increases the output of the script.")
87 (options
, args
) = parser
.parse_args()
88 for req
, msg
in (('marPath', "the absolute path to the where the MAR file is"),
89 ('applicationIniFile', "the absolute path to the application.ini file."),
90 ('locale', "a locale."),
91 ('product', "specify a product."),
92 ('platform', "specify the platform.")):
93 if not hasattr(options
, req
):
94 parser
.error('You must specify %s' % msg
)
96 if not options
.downloadBaseURL
or options
.downloadBaseURL
== '':
97 options
.downloadBaseURL
= 'http://ftp.mozilla.org/pub/mozilla.org/%s/nightly' % options
.product
99 if not options
.branch
or options
.branch
== '':
100 options
.branch
= None
102 snippet
= generateSnippet(options
.marPath
,
103 options
.applicationIniFile
,
105 options
.downloadBaseURL
,
109 f
= open(os
.path
.join(options
.marPath
, 'complete.update.snippet'), 'wb')
114 # Show in our logs what the contents of the snippet are
117 def generateSnippet(abstDistDir
, applicationIniFile
, locale
,
118 downloadBaseURL
, product
, platform
, branch
):
119 # Let's extract information from application.ini
122 c
.readfp(open(applicationIniFile
))
123 except IOError, (stderror
):
125 buildid
= c
.get("App", "BuildID")
126 appVersion
= c
.get("App", "Version")
127 branchName
= branch
or c
.get("App", "SourceRepository").split('/')[-1]
129 marFileName
= '%s-%s.%s.%s.complete.mar' % (
134 # Let's determine the hash and the size of the MAR file
135 # This function exits the script if the file does not exist
136 (completeMarHash
, completeMarSize
) = getFileHashAndSize(
137 os
.path
.join(abstDistDir
, marFileName
))
138 # Construct the URL to where the MAR file will exist
140 if locale
== 'en-US':
144 marDownloadURL
= "%s/%s%s/%s" % (downloadBaseURL
,
145 datedDirPath(buildid
, branchName
),
149 snippet
= """complete
157 """ % dict( marDownloadURL
=marDownloadURL
,
158 completeMarHash
=completeMarHash
,
159 completeMarSize
=completeMarSize
,
161 appVersion
=appVersion
)
165 def getFileHashAndSize(filepath
):
170 # open in binary mode to make sure we get consistent results
171 # across all platforms
172 f
= open(filepath
, "rb")
173 shaObj
= sha
.new(f
.read())
174 sha1Hash
= shaObj
.hexdigest()
175 size
= os
.stat(filepath
)[ST_SIZE
]
176 except IOError, (stderror
):
179 return (sha1Hash
, size
)
181 def datedDirPath(buildid
, milestone
):
183 Returns a string that will look like:
184 2009/12/2009-12-31-09-mozilla-central
190 datedDir
= "%s-%s-%s-%s-%s" % (year
,
195 return "%s/%s/%s" % (year
, month
, datedDir
)
197 if __name__
== '__main__':