| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 if filename is None: | 447 if filename is None: |
| 448 _LogMessage('unable to find image for board %s' % board_id) | 448 _LogMessage('unable to find image for board %s' % board_id) |
| 449 return self.GetNoUpdatePayload() | 449 return self.GetNoUpdatePayload() |
| 450 url = '%s/static/%s' % (self.hostname, filename) | 450 url = '%s/static/%s' % (self.hostname, filename) |
| 451 is_delta_format = self._IsDeltaFormatFile(filename) | 451 is_delta_format = self._IsDeltaFormatFile(filename) |
| 452 _LogMessage('returning update payload ' + url) | 452 _LogMessage('returning update payload ' + url) |
| 453 # Factory install is using memento updater which is using the sha-1 hash so | 453 # Factory install is using memento updater which is using the sha-1 hash so |
| 454 # setting sha-256 to an empty string. | 454 # setting sha-256 to an empty string. |
| 455 return self.GetUpdatePayload(checksum, '', size, url, is_delta_format) | 455 return self.GetUpdatePayload(checksum, '', size, url, is_delta_format) |
| 456 | 456 |
| 457 def GenerateUpdatePayloadForNonFactory(self, static_image_dir): |
| 458 """Generates an update for non-factory and returns True on success.""" |
| 459 if self.use_cached and os.path.exists(os.path.join(static_image_dir, |
| 460 'update.gz')): |
| 461 _LogMessage('Using cached image regardless of timestamps.') |
| 462 return True |
| 463 else: |
| 464 if self.forced_image: |
| 465 has_built_image = self.GenerateUpdateImage( |
| 466 self.forced_image, move_to_static_dir=True, |
| 467 static_image_dir=static_image_dir) |
| 468 # Now that we've generated it, force devserver to use it. |
| 469 self.use_cached = True |
| 470 elif self.serve_only: |
| 471 return self.GenerateImageFromZip(static_image_dir) |
| 472 else: |
| 473 return self.GenerateLatestUpdateImage(board_id, |
| 474 client_version, |
| 475 static_image_dir) |
| 476 |
| 477 def PreGenerateUpdate(self): |
| 478 """Pre-generates an update. Does not work for factory or label updates.""" |
| 479 # Does not work with factory config. |
| 480 assert(not self.factory_config) |
| 481 _LogMessage('Pre-generating the update payload.') |
| 482 # Does not work with labels so just use static dir. |
| 483 if self.GenerateUpdatePayloadForNonFactory(self.static_dir): |
| 484 # Force the devserver to use the pre-generated payload. |
| 485 self.use_cached = True |
| 486 else: |
| 487 _LogMessage('Failed to pre-generate update.') |
| 488 |
| 457 def HandleUpdatePing(self, data, label=None): | 489 def HandleUpdatePing(self, data, label=None): |
| 458 """Handles an update ping from an update client. | 490 """Handles an update ping from an update client. |
| 459 | 491 |
| 460 Args: | 492 Args: |
| 461 data: xml blob from client. | 493 data: xml blob from client. |
| 462 label: optional label for the update. | 494 label: optional label for the update. |
| 463 Returns: | 495 Returns: |
| 464 Update payload message for client. | 496 Update payload message for client. |
| 465 """ | 497 """ |
| 466 # Set hostname as the hostname that the client is calling to and set up | 498 # Set hostname as the hostname that the client is calling to and set up |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 534 |
| 503 # Separate logic as Factory requests have static url's that override | 535 # Separate logic as Factory requests have static url's that override |
| 504 # other options. | 536 # other options. |
| 505 if self.factory_config: | 537 if self.factory_config: |
| 506 return self.HandleFactoryRequest(board_id, channel) | 538 return self.HandleFactoryRequest(board_id, channel) |
| 507 else: | 539 else: |
| 508 static_image_dir = self.static_dir | 540 static_image_dir = self.static_dir |
| 509 if label: | 541 if label: |
| 510 static_image_dir = os.path.join(static_image_dir, label) | 542 static_image_dir = os.path.join(static_image_dir, label) |
| 511 | 543 |
| 512 # Prefer cached image if it exists. | 544 if self.GenerateUpdatePayloadForNonFactory(static_image_dir): |
| 513 if self.use_cached and os.path.exists(os.path.join(static_image_dir, | |
| 514 'update.gz')): | |
| 515 _LogMessage('Using cached image regardless of timestamps.') | |
| 516 has_built_image = True | |
| 517 else: | |
| 518 if self.forced_image: | |
| 519 has_built_image = self.GenerateUpdateImage( | |
| 520 self.forced_image, move_to_static_dir=True, | |
| 521 static_image_dir=static_image_dir) | |
| 522 # Now that we've generated it, clear out so that other pings of same | |
| 523 # devserver instance do not generate new images. | |
| 524 self.forced_image = None | |
| 525 elif self.serve_only: | |
| 526 has_built_image = self.GenerateImageFromZip(static_image_dir) | |
| 527 else: | |
| 528 has_built_image = self.GenerateLatestUpdateImage(board_id, | |
| 529 client_version, | |
| 530 static_image_dir) | |
| 531 | |
| 532 if has_built_image: | |
| 533 filename = os.path.join(static_image_dir, 'update.gz') | 545 filename = os.path.join(static_image_dir, 'update.gz') |
| 534 hash = self._GetHash(filename) | 546 hash = self._GetHash(filename) |
| 535 sha256 = self._GetSHA256(filename) | 547 sha256 = self._GetSHA256(filename) |
| 536 size = self._GetSize(filename) | 548 size = self._GetSize(filename) |
| 537 is_delta_format = self._IsDeltaFormatFile(filename) | 549 is_delta_format = self._IsDeltaFormatFile(filename) |
| 538 if label: | 550 if label: |
| 539 url = '%s/%s/update.gz' % (static_urlbase, label) | 551 url = '%s/%s/update.gz' % (static_urlbase, label) |
| 540 else: | 552 else: |
| 541 url = '%s/update.gz' % static_urlbase | 553 url = '%s/update.gz' % static_urlbase |
| 542 | 554 |
| 543 _LogMessage('Responding to client to use url %s to get image.' % url) | 555 _LogMessage('Responding to client to use url %s to get image.' % url) |
| 544 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) | 556 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) |
| 545 else: | 557 else: |
| 546 return self.GetNoUpdatePayload() | 558 return self.GetNoUpdatePayload() |
| OLD | NEW |