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

Unified 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: Remove ws 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 side-by-side diff with in-line comments
Download patch
Index: cros_generate_stateful_update_payload.py
diff --git a/cros_generate_stateful_update_payload.py b/cros_generate_stateful_update_payload.py
new file mode 100755
index 0000000000000000000000000000000000000000..87e9837af81beac8d2d582362b51b30c96674c6c
--- /dev/null
+++ b/cros_generate_stateful_update_payload.py
@@ -0,0 +1,94 @@
+#!/usr/bin/python2.6
+
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""This module is responsible for generate a stateful update payload."""
+
+import logging
+import optparse
+import os
+import subprocess
+import tempfile
+
+STATEFUL_FILE = 'stateful.tgz'
+
+
+def GenerateStatefulPayload(image_path, output_directory, logger):
+ """Generates a stateful update payload given a full path to an image.
+
+ Args:
+ image_path: Path to the image.
+ output_directory: Path to the directory to leave the resulting output.
+ logger: logging instance.
+ """
+ logger.info('Generating stateful update file.')
+ from_dir = os.path.dirname(image_path)
+ image = os.path.basename(image_path)
+ output_gz = os.path.join(output_directory, STATEFUL_FILE)
+ crosutils_dir = os.path.dirname(__file__)
+
+ # Temporary directories for this function.
+ rootfs_dir = tempfile.mkdtemp(suffix='rootfs', prefix='tmp')
+ stateful_dir = tempfile.mkdtemp(suffix='stateful', prefix='tmp')
+
+ # Mount the image to pull out the important directories.
+ try:
+ # Only need stateful partition, but this saves us having to manage our
+ # own loopback device.
+ subprocess.check_call(['%s/mount_gpt_image.sh' % crosutils_dir,
DaleCurtis 2010/11/10 22:41:18 Will this take in stateful.image or just chromiumo
sosa 2010/11/10 23:31:30 This requires the image. This is probably the bes
+ '--from=%s' % from_dir,
+ '--image=%s' % image,
+ '--read_only',
+ '--rootfs_mountpt=%s' % rootfs_dir,
+ '--stateful_mountpt=%s' % stateful_dir,
+ ])
+ logger.info('Tarring up /usr/local and /var!')
+ subprocess.check_call(['sudo',
DaleCurtis 2010/11/10 22:41:18 Why /var?
sosa 2010/11/10 23:31:30 Gmerge / portage On 2010/11/10 22:41:18, dalec wr
+ 'tar',
+ '-czf',
+ output_gz,
+ '--directory=%s' % stateful_dir,
+ '--transform=s,^dev_image,dev_image_new,',
+ '--transform=s,^var,var_new,',
+ 'dev_image',
+ 'var',
+ ])
+ except:
+ logger.error('Failed to create stateful update file')
+ raise
+ finally:
+ # Unmount best effort regardless.
+ subprocess.call(['%s/mount_gpt_image.sh' % crosutils_dir,
+ '--unmount',
+ '--rootfs_mountpt=%s' % rootfs_dir,
+ '--stateful_mountpt=%s' % stateful_dir,
+ ])
+ # Clean up our directories.
+ os.rmdir(rootfs_dir)
+ os.rmdir(stateful_dir)
+
+ logger.info('Successfully generated %s' % output_gz)
+
+
+def main():
+ logging.basicConfig(level=logging.INFO)
+ logger = logging.getLogger(os.path.basename(__file__))
+ parser = optparse.OptionParser()
+ parser.add_option('-i', '--image_path',
DaleCurtis 2010/11/10 22:41:18 Nit. Sync option names with cros_generate_update_p
sosa 2010/11/10 23:31:30 I'd like the ability to change the type of the pay
DaleCurtis 2010/11/11 00:03:46 Can you elaborate more? I don't understand how let
+ help='The image to generate the stateful update for.')
+ parser.add_option('-o', '--output_dir',
+ help='The path to the directory to output the update file.')
+ parser.set_usage(parser.format_help())
+ (options, unused_args) = parser.parse_args()
DaleCurtis 2010/11/10 22:41:18 Extra parens.
sosa 2010/11/10 23:31:30 Done.
+ if not options.image_path:
+ parser.error('Missing image for stateful payload generator')
+ if not options.output_dir:
+ parser.error('Missing output directory for the payload generator')
+
+ GenerateStatefulPayload(options.image_path, options.output_dir, logger)
+
+
+if __name__ == '__main__':
+ main()
« cros_generate_stateful_update_payload ('K') | « cros_generate_stateful_update_payload ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698