| 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 sys | 10 import sys |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 client_tokens = client_version.replace('_','').split('.') | 83 client_tokens = client_version.replace('_','').split('.') |
| 84 latest_tokens = latest_version.replace('_','').split('.') | 84 latest_tokens = latest_version.replace('_','').split('.') |
| 85 web.debug('client version %s latest version %s' \ | 85 web.debug('client version %s latest version %s' \ |
| 86 % (client_version, latest_version)) | 86 % (client_version, latest_version)) |
| 87 for i in range(4): | 87 for i in range(4): |
| 88 if int(latest_tokens[i]) == int(client_tokens[i]): | 88 if int(latest_tokens[i]) == int(client_tokens[i]): |
| 89 continue | 89 continue |
| 90 return int(latest_tokens[i]) > int(client_tokens[i]) | 90 return int(latest_tokens[i]) > int(client_tokens[i]) |
| 91 return False | 91 return False |
| 92 | 92 |
| 93 def UnpackImage(self, image_path, image_file, stateful_file, kernel_file, root
fs_file): | 93 def UnpackImage(self, image_path, image_file, stateful_file, |
| 94 kernel_file, rootfs_file): |
| 94 unpack_command = 'cd %s && ./unpack_partitions.sh %s' % \ | 95 unpack_command = 'cd %s && ./unpack_partitions.sh %s' % \ |
| 95 (image_path, image_file) | 96 (image_path, image_file) |
| 96 if os.system(unpack_command) == 0: | 97 if os.system(unpack_command) == 0: |
| 97 shutil.move(os.path.join(image_path, 'part_1'), stateful_file) | 98 shutil.move(os.path.join(image_path, 'part_1'), stateful_file) |
| 98 shutil.move(os.path.join(image_path, 'part_2'), kernel_file) | 99 shutil.move(os.path.join(image_path, 'part_2'), kernel_file) |
| 99 shutil.move(os.path.join(image_path, 'part_3'), rootfs_file) | 100 shutil.move(os.path.join(image_path, 'part_3'), rootfs_file) |
| 100 os.system('cd %s && rm part_*' % image_path) | 101 os.system('cd %s && rm part_*' % image_path) |
| 101 return True | 102 return True |
| 102 return False | 103 return False |
| 103 | 104 |
| 104 def UnpackZip(self, image_path, image_file): | 105 def UnpackZip(self, image_path, image_file): |
| 105 return os.system('cd %s && unzip -o image.zip %s unpack_partitions.sh' % \ | 106 image = os.path.join(image_path, image_file) |
| 106 (image_path, image_file)) == 0 | 107 if os.path.exists(image): |
| 108 return True |
| 109 else: |
| 110 return os.system('cd %s && unzip -o image.zip %s unpack_partitions.sh' % |
| 111 (image_path, image_file)) == 0 |
| 107 | 112 |
| 108 def GetImageBinPath(self, image_path): | 113 def GetImageBinPath(self, image_path): |
| 109 if self.test_image: | 114 if self.test_image: |
| 110 image_file = 'chromiumos_test_image.bin' | 115 image_file = 'chromiumos_test_image.bin' |
| 111 else: | 116 else: |
| 112 image_file = 'chromiumos_image.bin' | 117 image_file = 'chromiumos_image.bin' |
| 113 return image_file | 118 return image_file |
| 114 | 119 |
| 115 def BuildUpdateImage(self, image_path): | 120 def BuildUpdateImage(self, image_path): |
| 116 stateful_file = '%s/stateful.image' % image_path | 121 stateful_file = '%s/stateful.image' % image_path |
| 117 kernel_file = '%s/kernel.image' % image_path | 122 kernel_file = '%s/kernel.image' % image_path |
| 118 rootfs_file = '%s/rootfs.image' % image_path | 123 rootfs_file = '%s/rootfs.image' % image_path |
| 119 | 124 |
| 120 image_file = self.GetImageBinPath(image_path) | 125 image_file = self.GetImageBinPath(image_path) |
| 121 bin_path = os.path.join(image_path, image_file) | 126 bin_path = os.path.join(image_path, image_file) |
| 122 | 127 |
| 123 # Get appropriate update.gz to compare timestamps. | 128 # Get appropriate update.gz to compare timestamps. |
| 124 if self.serve_only: | 129 if self.serve_only: |
| 125 cached_update_file = os.path.join(image_path, 'update.gz') | 130 cached_update_file = os.path.join(image_path, 'update.gz') |
| 126 else: | 131 else: |
| 127 cached_update_file = os.path.join(self.static_dir, 'update.gz') | 132 cached_update_file = os.path.join(self.static_dir, 'update.gz') |
| 128 | 133 |
| 129 # Check whether we need to re-create if the original image is newer. | 134 # If the rootfs image is newer, re-create everything. |
| 130 if (os.path.exists(cached_update_file) and | 135 if (os.path.exists(cached_update_file) and |
| 131 os.path.getmtime(cached_update_file) >= os.path.getmtime(bin_path)): | 136 os.path.getmtime(cached_update_file) >= os.path.getmtime(bin_path)): |
| 132 web.debug('Using cached update image at %s instead of %s' % | 137 web.debug('Using cached update image at %s instead of %s' % |
| 133 (cached_update_file, bin_path)) | 138 (cached_update_file, bin_path)) |
| 134 else: | 139 else: |
| 135 # Unpack zip file if we are serving from a directory. | 140 # Unpack zip file if we are serving from a directory. |
| 136 if self.serve_only and not self.UnpackZip(image_path, image_file): | 141 if self.serve_only and not self.UnpackZip(image_path, image_file): |
| 137 web.debug('unzip image.zip failed.') | 142 web.debug('unzip image.zip failed.') |
| 138 return False | 143 return False |
| 139 | 144 |
| 140 if not self.UnpackImage(image_path, image_file, stateful_file, | 145 if not self.UnpackImage(image_path, image_file, stateful_file, |
| 141 kernel_file, rootfs_file): | 146 kernel_file, rootfs_file): |
| 142 web.debug('Failed to unpack image.') | 147 web.debug('Failed to unpack image.') |
| 143 return False | 148 return False |
| 144 | 149 |
| 145 update_file = os.path.join(image_path, 'update.gz') | 150 update_file = os.path.join(image_path, 'update.gz') |
| 146 web.debug('Generating update image %s' % update_file) | 151 web.debug('Generating update image %s' % update_file) |
| 147 mkupdate_command = '%s/mk_memento_images.sh %s %s' % \ | 152 mkupdate_command = '%s/mk_memento_images.sh %s %s' % \ |
| 148 (self.scripts_dir, kernel_file, rootfs_file) | 153 (self.scripts_dir, kernel_file, rootfs_file) |
| 149 if os.system(mkupdate_command) != 0: | 154 if os.system(mkupdate_command) != 0: |
| 150 web.debug('Failed to create update image') | 155 web.debug('Failed to create update image') |
| 151 return False | 156 return False |
| 152 | 157 |
| 153 mkstatefulupdate_command = 'gzip %s' % stateful_file | 158 mkstatefulupdate_command = 'gzip -f %s' % stateful_file |
| 154 if os.system(mkstatefulupdate_command) != 0: | 159 if os.system(mkstatefulupdate_command) != 0: |
| 155 web.debug('Failed to create stateful update image') | 160 web.debug('Failed to create stateful update image') |
| 156 return False | 161 return False |
| 157 | 162 |
| 158 # Add gz suffix | 163 # Add gz suffix |
| 159 stateful_file = '%s.gz' % stateful_file | 164 stateful_file = '%s.gz' % stateful_file |
| 160 | 165 |
| 161 # Cleanup of image files | 166 # Cleanup of image files |
| 162 os.remove(kernel_file) | 167 os.remove(kernel_file) |
| 163 os.remove(rootfs_file) | 168 os.remove(rootfs_file) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 ok = self.BuildUpdateImage(latest_image_path) | 331 ok = self.BuildUpdateImage(latest_image_path) |
| 327 if ok != True: | 332 if ok != True: |
| 328 web.debug('Failed to build an update image') | 333 web.debug('Failed to build an update image') |
| 329 return self.GetNoUpdatePayload() | 334 return self.GetNoUpdatePayload() |
| 330 | 335 |
| 331 hash = self.GetHash('%s/update.gz' % self.static_dir) | 336 hash = self.GetHash('%s/update.gz' % self.static_dir) |
| 332 size = self.GetSize('%s/update.gz' % self.static_dir) | 337 size = self.GetSize('%s/update.gz' % self.static_dir) |
| 333 | 338 |
| 334 url = 'http://%s/static/update.gz' % hostname | 339 url = 'http://%s/static/update.gz' % hostname |
| 335 return self.GetUpdatePayload(hash, size, url) | 340 return self.GetUpdatePayload(hash, size, url) |
| OLD | NEW |