OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
4 # for details. All rights reserved. Use of this source code is governed by a | |
5 # BSD-style license that can be found in the LICENSE file. | |
6 | |
7 import hashlib | |
8 import imp | |
9 import os | |
10 import subprocess | |
11 import sys | |
12 | |
13 DART_DIR = os.path.abspath( | |
14 os.path.normpath(os.path.join(__file__, '..', '..', '..'))) | |
15 | |
16 def GetUtils(): | |
17 '''Dynamically load the tools/utils.py python module.''' | |
18 return imp.load_source('utils', os.path.join(DART_DIR, 'tools', 'utils.py')) | |
19 | |
20 utils = GetUtils() | |
21 | |
22 SYSTEM_RENAMES = { | |
23 'win32': 'windows', | |
24 'windows': 'windows', | |
25 'win': 'windows', | |
26 | |
27 'linux': 'linux', | |
28 'linux2': 'linux', | |
29 'lucid32': 'linux', | |
30 'lucid64': 'linux', | |
31 | |
32 'darwin': 'macos', | |
33 'mac': 'macos', | |
34 'macos': 'macos', | |
35 } | |
36 | |
37 ARCH_RENAMES = { | |
38 '32': 'ia32', | |
39 'ia32': 'ia32', | |
40 | |
41 '64': 'x64', | |
42 'x64': 'x64', | |
43 } | |
44 | |
45 class Channel(object): | |
46 BLEEDING_EDGE = 'be' | |
47 DEV = 'dev' | |
48 STABLE = 'stable' | |
49 ALL_CHANNELS = [BLEEDING_EDGE, DEV, STABLE] | |
50 | |
51 class ReleaseType(object): | |
ricow1
2013/09/16 11:51:30
To be consistent, should we make a Mode class as w
kustermann
2013/09/16 14:15:54
Done.
| |
52 RAW = 'raw' | |
53 SIGNED = 'signed' | |
54 RELEASE = 'release' | |
55 ALL_TYPES = [RAW, SIGNED, RELEASE] | |
56 | |
57 class GCSNamer(object): | |
58 def __init__(self, channel=Channel.BLEEDING_EDGE, | |
59 release_type=ReleaseType.RAW): | |
60 assert channel in Channel.ALL_CHANNELS | |
61 assert release_type in ReleaseType.ALL_TYPES | |
62 | |
63 self.channel = channel | |
64 self.release_type = release_type | |
65 self.bucket = 'gs://dart-archive' | |
66 | |
67 def dartium_directory(self, revision): | |
68 return self._variant_directory('dartium', revision) | |
69 | |
70 def sdk_directory(self, revision): | |
71 return self._variant_directory('sdk', revision) | |
72 | |
73 def editor_directory(self, revision): | |
74 return self._variant_directory('editor', revision) | |
75 | |
76 def editor_eclipse_update_directory(self, revision): | |
77 return self._variant_directory('editor-eclipse-update', revision) | |
78 | |
79 def apidocs_directory(self, revision): | |
80 return self._variant_directory('api-docs', revision) | |
81 | |
82 def misc_directory(self, revision): | |
83 return self._variant_directory('misc', revision) | |
84 | |
85 def version_file(self, revision): | |
86 return '%s/channels/%s/%s/%s/VERSION' % (self.bucket, self.channel, self.rel ease_type, | |
87 revision) | |
88 | |
89 def _variant_directory(self, name, revision): | |
90 return '%s/channels/%s/%s/%s/%s' % (self.bucket, self.channel, self.release_ type, | |
91 revision, name) | |
92 | |
93 def apidocs_zipfile(self): | |
ricow1
2013/09/16 11:51:30
we use zipfilename in other functions
kustermann
2013/09/16 14:15:54
Done.
| |
94 return 'dart-api-docs.zip' | |
95 | |
96 def editor_zipfilename(self, system, arch): | |
97 return 'darteditor-%s-%s.zip' % ( | |
98 SYSTEM_RENAMES[system], ARCH_RENAMES[arch]) | |
99 | |
100 def sdk_zipfilename(self, system, arch, mode): | |
101 assert mode in ['release', 'debug'] | |
ricow1
2013/09/16 11:51:30
if you create a Mode class, then use it here for t
kustermann
2013/09/16 14:15:54
Done.
| |
102 return 'dartsdk-%s-%s-%s.zip' % ( | |
103 SYSTEM_RENAMES[system], ARCH_RENAMES[arch], mode) | |
104 | |
105 def dartium_zipfilename(self, system, arch, mode): | |
106 return self._dartium_variant_zipfilename('dartium', system, arch, mode) | |
107 | |
108 def content_shell_zipfilename(self, system, arch, mode): | |
109 return self._dartium_variant_zipfilename( | |
110 'content_shell', system, arch, mode) | |
111 | |
112 def cromedriver_zipfilename(self, system, arch, mode): | |
113 return self.dartium_variant_zipfilename( | |
114 'chromedriver', system, arch, mode) | |
115 | |
116 def dartium_variant_zipfilename(self, name, system, arch, mode): | |
ricow1
2013/09/16 11:51:30
do we need the above functions if we have this?
kustermann
2013/09/16 14:15:54
Probably not. I started with this function to be p
| |
117 assert name in ['chromedriver', 'dartium', 'content_shell'] | |
118 assert mode in ['release', 'debug'] | |
119 return '%s-%s-%s-%s.zip' % ( | |
120 name, SYSTEM_RENAMES[system], ARCH_RENAMES[arch], mode) | |
121 | |
122 def run(command, env=None): | |
123 print "Running command: ", command | |
124 p = subprocess.Popen(command, stdout=subprocess.PIPE, | |
125 stderr=subprocess.PIPE, env=env) | |
126 (stdout, stderr) = p.communicate() | |
127 if p.returncode: | |
ricow1
2013/09/16 11:51:30
I would actually be specific here
if p.returncode
kustermann
2013/09/16 14:15:54
I changed it -- but that's not the "pythonic way"!
| |
128 print >> sys.stderr, "Failed to execute '%s'. Exit code: %s." % ( | |
129 command, p.returncode) | |
130 print >> sys.stderr, "stdout: ", stdout | |
131 print >> sys.stderr, "stderr: ", stderr | |
132 raise Exception("Failed to execute %s." % command) | |
133 | |
134 class GSUtil(object): | |
135 GSUTIL_PATH = os.path.join(DART_DIR, 'third_party', 'gsutil', 'gsutil') | |
ricow1
2013/09/16 11:51:30
this will probably not work on dartium, since we d
kustermann
2013/09/16 14:15:54
Good point. I've added more logic now to search fo
| |
136 assert os.path.exists(GSUTIL_PATH) | |
137 | |
138 def execute(self, gsutil_args): | |
139 env = dict(os.environ) | |
140 # If we're on the buildbot, we use a specific boto file. | |
141 if utils.GetUserName() == 'chrome-bot': | |
142 boto_config = { | |
143 'linux': '/mnt/data/b/build/site_config/.boto', | |
144 'macos': '/Volumes/data/b/build/site_config/.boto', | |
145 'win32': r'e:\b\build\site_config\.boto', | |
146 }[utils.GuessOS()] | |
147 env['AWS_CREDENTIAL_FILE'] = boto_config | |
ricow1
2013/09/16 11:51:30
do we need to specify this at this point?
This wil
kustermann
2013/09/16 14:15:54
We probably don't need it. But BB contains it in i
| |
148 env['BOTO_CONFIG'] = boto_config | |
149 run([sys.executable, GSUtil.GSUTIL_PATH] + gsutil_args, | |
150 env=env) | |
151 | |
152 def CalculateChecksum(filename): | |
153 """Calculate the MD5 checksum for filename.""" | |
154 | |
155 md5 = hashlib.md5() | |
156 | |
157 with open(filename, 'rb') as f: | |
158 data = f.read(65536) | |
159 while len(data) > 0: | |
160 md5.update(data) | |
161 data = f.read(65536) | |
162 | |
163 return md5.hexdigest() | |
164 | |
165 def CreateChecksumFile(filename, mangled_filename=None): | |
166 """Create and upload an MD5 checksum file for filename.""" | |
167 if not mangled_filename: | |
168 mangled_filename = os.path.basename(filename) | |
169 | |
170 checksum = CalculateChecksum(filename) | |
171 checksum_filename = '%s.md5sum' % filename | |
172 | |
173 with open(checksum_filename, 'w') as f: | |
174 f.write('%s *%s' % (checksum, mangled_filename)) | |
175 | |
176 return checksum_filename | |
177 | |
OLD | NEW |