Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: cros_generate_stateful_update_payload.py

Issue 4688006: Add new stateful upload payload generator to crosutils. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: nit Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cros_generate_stateful_update_payload ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2.6
2
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
5 # found in the LICENSE file.
6
7 """This module is responsible for generate a stateful update payload."""
8
9 import logging
10 import optparse
11 import os
12 import subprocess
13 import tempfile
14
15 STATEFUL_FILE = 'stateful.tgz'
16
17
18 def GenerateStatefulPayload(image_path, output_directory, logger):
19 """Generates a stateful update payload given a full path to an image.
20
21 Args:
22 image_path: Path to the image.
23 output_directory: Path to the directory to leave the resulting output.
24 logger: logging instance.
25 """
26 logger.info('Generating stateful update file.')
27 from_dir = os.path.dirname(image_path)
DaleCurtis 2010/11/11 00:03:46 This won't work if image is in the same directory
sosa 2010/11/11 00:18:58 Done.
28 image = os.path.basename(image_path)
29 output_gz = os.path.join(output_directory, STATEFUL_FILE)
30 crosutils_dir = os.path.dirname(__file__)
31
32 # Temporary directories for this function.
33 rootfs_dir = tempfile.mkdtemp(suffix='rootfs', prefix='tmp')
34 stateful_dir = tempfile.mkdtemp(suffix='stateful', prefix='tmp')
35
36 # Mount the image to pull out the important directories.
37 try:
38 # Only need stateful partition, but this saves us having to manage our
39 # own loopback device.
40 subprocess.check_call(['%s/mount_gpt_image.sh' % crosutils_dir,
41 '--from=%s' % from_dir,
42 '--image=%s' % image,
43 '--read_only',
44 '--rootfs_mountpt=%s' % rootfs_dir,
45 '--stateful_mountpt=%s' % stateful_dir,
46 ])
47 logger.info('Tarring up /usr/local and /var!')
48 subprocess.check_call(['sudo',
49 'tar',
50 '-czf',
51 output_gz,
52 '--directory=%s' % stateful_dir,
53 '--transform=s,^dev_image,dev_image_new,',
54 '--transform=s,^var,var_new,',
55 'dev_image',
56 'var',
57 ])
58 except:
59 logger.error('Failed to create stateful update file')
60 raise
61 finally:
62 # Unmount best effort regardless.
63 subprocess.call(['%s/mount_gpt_image.sh' % crosutils_dir,
64 '--unmount',
65 '--rootfs_mountpt=%s' % rootfs_dir,
66 '--stateful_mountpt=%s' % stateful_dir,
67 ])
68 # Clean up our directories.
69 os.rmdir(rootfs_dir)
70 os.rmdir(stateful_dir)
71
72 logger.info('Successfully generated %s' % output_gz)
73
74
75 def main():
76 logging.basicConfig(level=logging.INFO)
77 logger = logging.getLogger(os.path.basename(__file__))
78 parser = optparse.OptionParser()
79 parser.add_option('-i', '--image_path',
80 help='The image to generate the stateful update for.')
81 parser.add_option('-o', '--output_dir',
82 help='The path to the directory to output the update file.')
83 options, unused_args = parser.parse_args()
84 if not options.image_path:
85 parser.error('Missing image for stateful payload generator')
86 if not options.output_dir:
87 parser.error('Missing output directory for the payload generator')
88
89 GenerateStatefulPayload(options.image_path, options.output_dir, logger)
90
91
92 if __name__ == '__main__':
93 main()
OLDNEW
« no previous file with comments | « cros_generate_stateful_update_payload ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698