OLD | NEW |
1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009 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 os | 8 import os |
| 9 import shutil |
9 import web | 10 import web |
10 | 11 |
11 class Autoupdate(BuildObject): | 12 class Autoupdate(BuildObject): |
12 # Basic functionality of handling ChromeOS autoupdate pings | 13 # Basic functionality of handling ChromeOS autoupdate pings |
13 # and building/serving update images. | 14 # and building/serving update images. |
14 # TODO(rtc): Clean this code up and write some tests. | 15 # TODO(rtc): Clean this code up and write some tests. |
15 | 16 |
16 def __init__(self, serve_only=None, test_image=False, *args, **kwargs): | 17 def __init__(self, serve_only=None, test_image=False, *args, **kwargs): |
17 self.serve_only = serve_only | 18 self.serve_only = serve_only |
18 if serve_only: | 19 if serve_only: |
19 web.debug('Autoupdate in "serve update images only" mode.') | 20 web.debug('Autoupdate in "serve update images only" mode.') |
20 self.test_image=test_image | 21 self.test_image=test_image |
21 super(Autoupdate, self).__init__(*args, **kwargs) | 22 super(Autoupdate, self).__init__(*args, **kwargs) |
22 | 23 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 web.debug('generating update image %s/update.gz' % image_path) | 86 web.debug('generating update image %s/update.gz' % image_path) |
86 mkupdate = '%s/mk_memento_images.sh %s' % (self.scripts_dir, image_file) | 87 mkupdate = '%s/mk_memento_images.sh %s' % (self.scripts_dir, image_file) |
87 web.debug(mkupdate) | 88 web.debug(mkupdate) |
88 err = os.system(mkupdate) | 89 err = os.system(mkupdate) |
89 if err != 0: | 90 if err != 0: |
90 web.debug('failed to create update image') | 91 web.debug('failed to create update image') |
91 return False | 92 return False |
92 if not self.serve_only: | 93 if not self.serve_only: |
93 web.debug('Found an image, copying it to static') | 94 web.debug('Found an image, copying it to static') |
94 try: | 95 try: |
95 shutil.copyfile('%s/update.gz' % image_path, self.static_dir) | 96 shutil.copy('%s/update.gz' % image_path, self.static_dir) |
96 except Exception, e: | 97 except Exception, e: |
97 web.debug('Unable to copy update.gz from %s to %s' \ | 98 web.debug('Unable to copy update.gz from %s to %s' \ |
98 % (image_path, self.static_dir)) | 99 % (image_path, self.static_dir)) |
99 return False | 100 return False |
100 return True | 101 return True |
101 | 102 |
102 def GetSize(self, update_path): | 103 def GetSize(self, update_path): |
103 return os.path.getsize(update_path) | 104 return os.path.getsize(update_path) |
104 | 105 |
105 def GetHash(self, update_path): | 106 def GetHash(self, update_path): |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 ok = self.BuildUpdateImage(latest_image_path) | 152 ok = self.BuildUpdateImage(latest_image_path) |
152 if ok != True: | 153 if ok != True: |
153 web.debug('Failed to build an update image') | 154 web.debug('Failed to build an update image') |
154 return self.GetNoUpdatePayload() | 155 return self.GetNoUpdatePayload() |
155 | 156 |
156 hash = self.GetHash('%s/update.gz' % self.static_dir) | 157 hash = self.GetHash('%s/update.gz' % self.static_dir) |
157 size = self.GetSize('%s/update.gz' % self.static_dir) | 158 size = self.GetSize('%s/update.gz' % self.static_dir) |
158 | 159 |
159 url = 'http://%s/static/update.gz' % hostname | 160 url = 'http://%s/static/update.gz' % hostname |
160 return self.GetUpdatePayload(hash, size, url) | 161 return self.GetUpdatePayload(hash, size, url) |
OLD | NEW |