| 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 |
| 11 import subprocess | 11 import subprocess |
| 12 import time | 12 import time |
| 13 import urlparse |
| 13 | 14 |
| 14 | 15 |
| 15 def _LogMessage(message): | 16 def _LogMessage(message): |
| 16 cherrypy.log(message, 'UPDATE') | 17 cherrypy.log(message, 'UPDATE') |
| 17 | 18 |
| 18 UPDATE_FILE='update.gz' | 19 UPDATE_FILE='update.gz' |
| 19 STATEFUL_FILE='stateful.tgz' | 20 STATEFUL_FILE='stateful.tgz' |
| 20 | 21 |
| 22 |
| 23 def _ChangeUrlPort(url, new_port): |
| 24 """Return the URL passed in with a different port""" |
| 25 scheme, netloc, path, query, fragment = urlparse.urlsplit(url) |
| 26 host_port = netloc.split(':') |
| 27 |
| 28 if len(host_port) == 1: |
| 29 host_port.append(new_port) |
| 30 else: |
| 31 host_port[1] = new_port |
| 32 |
| 33 print host_port |
| 34 netloc = "%s:%s" % tuple(host_port) |
| 35 |
| 36 return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) |
| 37 |
| 38 |
| 21 class Autoupdate(BuildObject): | 39 class Autoupdate(BuildObject): |
| 22 """Class that contains functionality that handles Chrome OS update pings. | 40 """Class that contains functionality that handles Chrome OS update pings. |
| 23 | 41 |
| 24 Members: | 42 Members: |
| 25 serve_only: Serve only pre-built updates. static_dir must contain update.gz | 43 serve_only: Serve only pre-built updates. static_dir must contain update.gz |
| 26 and stateful.tgz. | 44 and stateful.tgz. |
| 27 factory_config: Path to the factory config file if handling factory | 45 factory_config: Path to the factory config file if handling factory |
| 28 requests. | 46 requests. |
| 29 use_test_image: Use chromiumos_test_image.bin rather than the standard. | 47 use_test_image: Use chromiumos_test_image.bin rather than the standard. |
| 30 static_url_base: base URL, other than devserver, for update images. | 48 static_url_base: base URL, other than devserver, for update images. |
| 31 client_prefix: The prefix for the update engine client. | 49 client_prefix: The prefix for the update engine client. |
| 32 forced_image: Path to an image to use for all updates. | 50 forced_image: Path to an image to use for all updates. |
| 33 """ | 51 """ |
| 34 | 52 |
| 35 def __init__(self, serve_only=None, test_image=False, urlbase=None, | 53 def __init__(self, serve_only=None, test_image=False, urlbase=None, |
| 36 factory_config_path=None, client_prefix=None, | 54 factory_config_path=None, client_prefix=None, |
| 37 forced_image=None, forced_payload=None, | 55 forced_image=None, forced_payload=None, |
| 38 port=8080, src_image='', vm=False, board=None, | 56 port=8080, proxy_port=None, src_image='', vm=False, board=None, |
| 39 *args, **kwargs): | 57 *args, **kwargs): |
| 40 super(Autoupdate, self).__init__(*args, **kwargs) | 58 super(Autoupdate, self).__init__(*args, **kwargs) |
| 41 self.serve_only = serve_only | 59 self.serve_only = serve_only |
| 42 self.factory_config = factory_config_path | 60 self.factory_config = factory_config_path |
| 43 self.use_test_image = test_image | 61 self.use_test_image = test_image |
| 44 if urlbase: | 62 if urlbase: |
| 45 self.urlbase = urlbase | 63 self.urlbase = urlbase |
| 46 else: | 64 else: |
| 47 self.urlbase = None | 65 self.urlbase = None |
| 48 | 66 |
| 49 self.client_prefix = client_prefix | 67 self.client_prefix = client_prefix |
| 50 self.forced_image = forced_image | 68 self.forced_image = forced_image |
| 51 self.forced_payload = forced_payload | 69 self.forced_payload = forced_payload |
| 52 self.src_image = src_image | 70 self.src_image = src_image |
| 71 self.proxy_port = proxy_port |
| 53 self.vm = vm | 72 self.vm = vm |
| 54 self.board = board | 73 self.board = board |
| 55 | 74 |
| 56 # Track update pregeneration, so we don't recopy if not needed. | 75 # Track update pregeneration, so we don't recopy if not needed. |
| 57 self.pregenerated = False | 76 self.pregenerated = False |
| 58 | 77 |
| 59 def _GetSecondsSinceMidnight(self): | 78 def _GetSecondsSinceMidnight(self): |
| 60 """Returns the seconds since midnight as a decimal value.""" | 79 """Returns the seconds since midnight as a decimal value.""" |
| 61 now = time.localtime() | 80 now = time.localtime() |
| 62 return now[3] * 3600 + now[4] * 60 + now[5] | 81 return now[3] * 3600 + now[4] * 60 + now[5] |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 # Set hostname as the hostname that the client is calling to and set up | 587 # Set hostname as the hostname that the client is calling to and set up |
| 569 # the url base. | 588 # the url base. |
| 570 self.hostname = cherrypy.request.base | 589 self.hostname = cherrypy.request.base |
| 571 if self.urlbase: | 590 if self.urlbase: |
| 572 static_urlbase = self.urlbase | 591 static_urlbase = self.urlbase |
| 573 elif self.serve_only: | 592 elif self.serve_only: |
| 574 static_urlbase = '%s/static/archive' % self.hostname | 593 static_urlbase = '%s/static/archive' % self.hostname |
| 575 else: | 594 else: |
| 576 static_urlbase = '%s/static' % self.hostname | 595 static_urlbase = '%s/static' % self.hostname |
| 577 | 596 |
| 597 # If we have a proxy port, adjust the URL we instruct the client to |
| 598 # use to go through the proxy. |
| 599 if self.proxy_port: |
| 600 static_urlbase = _ChangeUrlPort(static_urlbase, self.proxy_port) |
| 601 |
| 578 _LogMessage('Using static url base %s' % static_urlbase) | 602 _LogMessage('Using static url base %s' % static_urlbase) |
| 579 _LogMessage('Handling update ping as %s: %s' % (self.hostname, data)) | 603 _LogMessage('Handling update ping as %s: %s' % (self.hostname, data)) |
| 580 | 604 |
| 581 # Check the client prefix to make sure you can support this type of update. | 605 # Check the client prefix to make sure you can support this type of update. |
| 582 update_dom = minidom.parseString(data) | 606 update_dom = minidom.parseString(data) |
| 583 root = update_dom.firstChild | 607 root = update_dom.firstChild |
| 584 if (root.hasAttribute('updaterversion') and | 608 if (root.hasAttribute('updaterversion') and |
| 585 not root.getAttribute('updaterversion').startswith(self.client_prefix)): | 609 not root.getAttribute('updaterversion').startswith(self.client_prefix)): |
| 586 _LogMessage('Got update from unsupported updater:' + | 610 _LogMessage('Got update from unsupported updater:' + |
| 587 root.getAttribute('updaterversion')) | 611 root.getAttribute('updaterversion')) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 is_delta_format = self._IsDeltaFormatFile(filename) | 646 is_delta_format = self._IsDeltaFormatFile(filename) |
| 623 if label: | 647 if label: |
| 624 url = '%s/%s/%s' % (static_urlbase, label, payload_path) | 648 url = '%s/%s/%s' % (static_urlbase, label, payload_path) |
| 625 else: | 649 else: |
| 626 url = '%s/%s' % (static_urlbase, payload_path) | 650 url = '%s/%s' % (static_urlbase, payload_path) |
| 627 | 651 |
| 628 _LogMessage('Responding to client to use url %s to get image.' % url) | 652 _LogMessage('Responding to client to use url %s to get image.' % url) |
| 629 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) | 653 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) |
| 630 else: | 654 else: |
| 631 return self.GetNoUpdatePayload() | 655 return self.GetNoUpdatePayload() |
| OLD | NEW |