OLD | NEW |
1 #!/usr/bin/python2.6 | 1 #!/usr/bin/python2.6 |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """This module is responsible for generate a stateful update payload.""" | 7 """This module is responsible for generate a stateful update payload.""" |
8 | 8 |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 import subprocess | 12 import subprocess |
13 import tempfile | 13 import tempfile |
14 | 14 |
15 STATEFUL_FILE = 'stateful.tgz' | 15 STATEFUL_FILE = 'stateful.tgz' |
16 | 16 |
17 | 17 |
18 def GenerateStatefulPayload(image_path, output_directory, logger): | 18 def GenerateStatefulPayload(image_path, output_directory, logger): |
19 """Generates a stateful update payload given a full path to an image. | 19 """Generates a stateful update payload given a full path to an image. |
20 | 20 |
21 Args: | 21 Args: |
22 image_path: Full path to the image. | 22 image_path: Full path to the image. |
23 output_directory: Path to the directory to leave the resulting output. | 23 output_directory: Path to the directory to leave the resulting output. |
24 logger: logging instance. | 24 logger: logging instance. |
25 """ | 25 """ |
26 logger.info('Generating stateful update file.') | 26 logger.info('Generating stateful update file.') |
27 from_dir = os.path.dirname(image_path) | 27 from_dir = os.path.dirname(image_path) |
28 image = os.path.basename(image_path) | 28 image = os.path.basename(image_path) |
29 output_gz = os.path.join(output_directory, STATEFUL_FILE) | 29 output_gz = os.path.join(output_directory, STATEFUL_FILE) |
30 crosutils_dir = os.path.dirname(__file__) | 30 # TODO(zbehan): This is only used for mount_gpt_image.sh. That script also |
| 31 # needs to move away from src/scripts. |
| 32 crosutils_dir = '%s/src/scripts' % os.environ['CROS_WORKON_SRCROOT'] |
31 | 33 |
32 # Temporary directories for this function. | 34 # Temporary directories for this function. |
33 rootfs_dir = tempfile.mkdtemp(suffix='rootfs', prefix='tmp') | 35 rootfs_dir = tempfile.mkdtemp(suffix='rootfs', prefix='tmp') |
34 stateful_dir = tempfile.mkdtemp(suffix='stateful', prefix='tmp') | 36 stateful_dir = tempfile.mkdtemp(suffix='stateful', prefix='tmp') |
35 | 37 |
36 # Mount the image to pull out the important directories. | 38 # Mount the image to pull out the important directories. |
37 try: | 39 try: |
38 # Only need stateful partition, but this saves us having to manage our | 40 # Only need stateful partition, but this saves us having to manage our |
39 # own loopback device. | 41 # own loopback device. |
40 subprocess.check_call(['%s/mount_gpt_image.sh' % crosutils_dir, | 42 subprocess.check_call(['%s/mount_gpt_image.sh' % crosutils_dir, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 parser.error('Missing image for stateful payload generator') | 88 parser.error('Missing image for stateful payload generator') |
87 if not options.output_dir: | 89 if not options.output_dir: |
88 parser.error('Missing output directory for the payload generator') | 90 parser.error('Missing output directory for the payload generator') |
89 | 91 |
90 GenerateStatefulPayload(os.path.abspath(options.image_path), | 92 GenerateStatefulPayload(os.path.abspath(options.image_path), |
91 options.output_dir, logger) | 93 options.output_dir, logger) |
92 | 94 |
93 | 95 |
94 if __name__ == '__main__': | 96 if __name__ == '__main__': |
95 main() | 97 main() |
OLD | NEW |