| 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 shutil |
| 10 import web | 10 import web |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 client_tokens = client_version.split('.') | 78 client_tokens = client_version.split('.') |
| 79 latest_tokens = latest_version.split('.') | 79 latest_tokens = latest_version.split('.') |
| 80 web.debug('client version %s latest version %s' \ | 80 web.debug('client version %s latest version %s' \ |
| 81 % (client_version, latest_version)) | 81 % (client_version, latest_version)) |
| 82 for i in range(0,4): | 82 for i in range(0,4): |
| 83 if int(latest_tokens[i]) == int(client_tokens[i]): | 83 if int(latest_tokens[i]) == int(client_tokens[i]): |
| 84 continue | 84 continue |
| 85 return int(latest_tokens[i]) > int(client_tokens[i]) | 85 return int(latest_tokens[i]) > int(client_tokens[i]) |
| 86 return False | 86 return False |
| 87 | 87 |
| 88 def UnpackRootfs(self, image_path, rootfs_file): | 88 def UnpackImage(self, image_path, kernel_file, rootfs_file): |
| 89 if os.path.exists(rootfs_file): | 89 if os.path.exists(rootfs_file) and os.path.exists(kernel_file): |
| 90 return True | 90 return True |
| 91 if self.test_image: | 91 if self.test_image: |
| 92 image_file = 'chromiumos_test_image.bin' | 92 image_file = 'chromiumos_test_image.bin' |
| 93 else: | 93 else: |
| 94 image_file = 'chromiumos_image.bin' | 94 image_file = 'chromiumos_image.bin' |
| 95 if self.serve_only: | 95 if self.serve_only: |
| 96 os.system('cd %s && unzip -o image.zip && unpack_partitions.sh %s' % | 96 os.system('cd %s && unzip -o image.zip' % |
| 97 (image_path, image_file)) | 97 (image_path, image_file)) |
| 98 os.system('rm -f %s/part_*' % image_path) | 98 os.system('rm -f %s/part_*' % image_path) |
| 99 os.system('cd %s && ./unpack_partitions.sh %s' % (image_path, image_file)) | 99 os.system('cd %s && ./unpack_partitions.sh %s' % (image_path, image_file)) |
| 100 shutil.move(os.path.join(image_path, 'part_2'), kernel_file) |
| 100 shutil.move(os.path.join(image_path, 'part_3'), rootfs_file) | 101 shutil.move(os.path.join(image_path, 'part_3'), rootfs_file) |
| 101 os.system('rm -f %s/part_*' % image_path) | 102 os.system('rm -f %s/part_*' % image_path) |
| 102 return True | 103 return True |
| 103 | 104 |
| 104 def BuildUpdateImage(self, image_path): | 105 def BuildUpdateImage(self, image_path): |
| 105 if self.test_image: | 106 kernel_file = '%s/kernel.image' % image_path |
| 106 image_file = '%s/rootfs_test.image' % image_path | 107 rootfs_file = '%s/rootfs.image' % image_path |
| 107 else: | |
| 108 image_file = '%s/rootfs.image' % image_path | |
| 109 | 108 |
| 110 if not self.UnpackRootfs(image_path, image_file): | 109 if not self.UnpackImage(image_path, kernel_file, rootfs_file): |
| 111 web.debug('failed to unpack rootfs.') | 110 web.debug('failed to unpack image.') |
| 112 return False | 111 return False |
| 113 | 112 |
| 114 update_file = '%s/update.gz' % image_path | 113 update_file = '%s/update.gz' % image_path |
| 115 if (os.path.exists(update_file) and | 114 if (os.path.exists(update_file) and |
| 116 os.path.getmtime(update_file) >= os.path.getmtime(image_file)): | 115 os.path.getmtime(update_file) >= os.path.getmtime(rootfs_file)): |
| 117 web.debug('Found cached update image %s/update.gz' % image_path) | 116 web.debug('Found cached update image %s/update.gz' % image_path) |
| 118 else: | 117 else: |
| 119 web.debug('generating update image %s' % update_file) | 118 web.debug('generating update image %s' % update_file) |
| 120 mkupdate = '%s/mk_memento_images.sh %s' % (self.scripts_dir, image_file) | 119 mkupdate = ('%s/mk_memento_images.sh %s %s' % |
| 120 (self.scripts_dir, kernel_file, rootfs_file)) |
| 121 web.debug(mkupdate) | 121 web.debug(mkupdate) |
| 122 err = os.system(mkupdate) | 122 err = os.system(mkupdate) |
| 123 if err != 0: | 123 if err != 0: |
| 124 web.debug('failed to create update image') | 124 web.debug('failed to create update image') |
| 125 return False | 125 return False |
| 126 if not self.serve_only: | 126 if not self.serve_only: |
| 127 web.debug('Found an image, copying it to static') | 127 web.debug('Found an image, copying it to static') |
| 128 try: | 128 try: |
| 129 shutil.copy(update_file, self.static_dir) | 129 shutil.copy(update_file, self.static_dir) |
| 130 except Exception, e: | 130 except Exception, e: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ok = self.BuildUpdateImage(latest_image_path) | 187 ok = self.BuildUpdateImage(latest_image_path) |
| 188 if ok != True: | 188 if ok != True: |
| 189 web.debug('Failed to build an update image') | 189 web.debug('Failed to build an update image') |
| 190 return self.GetNoUpdatePayload() | 190 return self.GetNoUpdatePayload() |
| 191 | 191 |
| 192 hash = self.GetHash('%s/update.gz' % self.static_dir) | 192 hash = self.GetHash('%s/update.gz' % self.static_dir) |
| 193 size = self.GetSize('%s/update.gz' % self.static_dir) | 193 size = self.GetSize('%s/update.gz' % self.static_dir) |
| 194 | 194 |
| 195 url = 'http://%s/static/update.gz' % hostname | 195 url = 'http://%s/static/update.gz' % hostname |
| 196 return self.GetUpdatePayload(hash, size, url) | 196 return self.GetUpdatePayload(hash, size, url) |
| OLD | NEW |