OLD | NEW |
1 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from buildutil import BuildObject | 5 from buildutil import BuildObject |
6 from xml.dom import minidom | 6 from xml.dom import minidom |
7 | 7 |
8 import cherrypy | 8 import cherrypy |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 vm: Set for VM images (doesn't patch kernel) | 56 vm: Set for VM images (doesn't patch kernel) |
57 board: board for the image. Needed for pre-generating of updates. | 57 board: board for the image. Needed for pre-generating of updates. |
58 copy_to_static_root: Copies images generated from the cache to | 58 copy_to_static_root: Copies images generated from the cache to |
59 ~/static. | 59 ~/static. |
60 """ | 60 """ |
61 | 61 |
62 def __init__(self, serve_only=None, test_image=False, urlbase=None, | 62 def __init__(self, serve_only=None, test_image=False, urlbase=None, |
63 factory_config_path=None, client_prefix=None, | 63 factory_config_path=None, client_prefix=None, |
64 forced_image=None, forced_payload=None, | 64 forced_image=None, forced_payload=None, |
65 port=8080, proxy_port=None, src_image='', vm=False, board=None, | 65 port=8080, proxy_port=None, src_image='', vm=False, board=None, |
66 copy_to_static_root=True, | 66 copy_to_static_root=True, private_key=None, |
67 *args, **kwargs): | 67 *args, **kwargs): |
68 super(Autoupdate, self).__init__(*args, **kwargs) | 68 super(Autoupdate, self).__init__(*args, **kwargs) |
69 self.serve_only = serve_only | 69 self.serve_only = serve_only |
70 self.factory_config = factory_config_path | 70 self.factory_config = factory_config_path |
71 self.use_test_image = test_image | 71 self.use_test_image = test_image |
72 if urlbase: | 72 if urlbase: |
73 self.urlbase = urlbase | 73 self.urlbase = urlbase |
74 else: | 74 else: |
75 self.urlbase = None | 75 self.urlbase = None |
76 | 76 |
77 self.client_prefix = client_prefix | 77 self.client_prefix = client_prefix |
78 self.forced_image = forced_image | 78 self.forced_image = forced_image |
79 self.forced_payload = forced_payload | 79 self.forced_payload = forced_payload |
80 self.src_image = src_image | 80 self.src_image = src_image |
81 self.proxy_port = proxy_port | 81 self.proxy_port = proxy_port |
82 self.vm = vm | 82 self.vm = vm |
83 self.board = board | 83 self.board = board |
84 self.copy_to_static_root = copy_to_static_root | 84 self.copy_to_static_root = copy_to_static_root |
| 85 self.private_key = private_key |
85 | 86 |
86 # Path to pre-generated file. | 87 # Path to pre-generated file. |
87 self.pregenerated_path = None | 88 self.pregenerated_path = None |
88 | 89 |
89 def _GetSecondsSinceMidnight(self): | 90 def _GetSecondsSinceMidnight(self): |
90 """Returns the seconds since midnight as a decimal value.""" | 91 """Returns the seconds since midnight as a decimal value.""" |
91 now = time.localtime() | 92 now = time.localtime() |
92 return now[3] * 3600 + now[4] * 60 + now[5] | 93 return now[3] * 3600 + now[4] * 60 + now[5] |
93 | 94 |
94 def _GetDefaultBoardID(self): | 95 def _GetDefaultBoardID(self): |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 233 |
233 def GenerateUpdateFile(self, src_image, image_path, output_dir): | 234 def GenerateUpdateFile(self, src_image, image_path, output_dir): |
234 """Generates an update gz given a full path to an image. | 235 """Generates an update gz given a full path to an image. |
235 | 236 |
236 Args: | 237 Args: |
237 image_path: Full path to image. | 238 image_path: Full path to image. |
238 Returns: | 239 Returns: |
239 Path to created update_payload or None on error. | 240 Path to created update_payload or None on error. |
240 """ | 241 """ |
241 update_path = os.path.join(output_dir, UPDATE_FILE) | 242 update_path = os.path.join(output_dir, UPDATE_FILE) |
242 patch_kernel_flag = '--patch_kernel' | |
243 _LogMessage('Generating update image %s' % update_path) | 243 _LogMessage('Generating update image %s' % update_path) |
244 | 244 |
245 # Don't patch the kernel for vm images as they don't need the patch. | 245 update_command = [ |
246 if self.vm: | 246 '%s/cros_generate_update_payload' % self.scripts_dir, |
247 patch_kernel_flag = '' | 247 '--image="%s"' % image_path, |
| 248 '--output="%s"' % update_path, |
| 249 '--noold_style', |
| 250 ] |
248 | 251 |
249 mkupdate_command = ( | 252 if src_image: update_command.append('--src_image="%s"' % src_image) |
250 '%s/cros_generate_update_payload --image="%s" --output="%s" ' | 253 if not self.vm: update_command.append('--patch_kernel') |
251 '%s --noold_style --src_image="%s"' % ( | 254 if self.private_key: update_command.append('--private_key="%s"' % |
252 self.scripts_dir, image_path, update_path, patch_kernel_flag, | 255 self.private_key) |
253 src_image)) | 256 |
254 _LogMessage(mkupdate_command) | 257 update_string = ' '.join(update_command) |
255 if os.system(mkupdate_command) != 0: | 258 _LogMessage('Running ' + update_string) |
| 259 if os.system(update_string) != 0: |
256 _LogMessage('Failed to create update payload') | 260 _LogMessage('Failed to create update payload') |
257 return None | 261 return None |
258 | 262 |
259 return UPDATE_FILE | 263 return UPDATE_FILE |
260 | 264 |
261 def GenerateStatefulFile(self, image_path, output_dir): | 265 def GenerateStatefulFile(self, image_path, output_dir): |
262 """Generates a stateful update payload given a full path to an image. | 266 """Generates a stateful update payload given a full path to an image. |
263 | 267 |
264 Args: | 268 Args: |
265 image_path: Full path to image. | 269 image_path: Full path to image. |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 is_delta_format = self._IsDeltaFormatFile(filename) | 661 is_delta_format = self._IsDeltaFormatFile(filename) |
658 if label: | 662 if label: |
659 url = '%s/%s/%s' % (static_urlbase, label, payload_path) | 663 url = '%s/%s/%s' % (static_urlbase, label, payload_path) |
660 else: | 664 else: |
661 url = '%s/%s' % (static_urlbase, payload_path) | 665 url = '%s/%s' % (static_urlbase, payload_path) |
662 | 666 |
663 _LogMessage('Responding to client to use url %s to get image.' % url) | 667 _LogMessage('Responding to client to use url %s to get image.' % url) |
664 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) | 668 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) |
665 else: | 669 else: |
666 return self.GetNoUpdatePayload() | 670 return self.GetNoUpdatePayload() |
OLD | NEW |