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

Side by Side Diff: autoupdate.py

Issue 4504001: Fix pre-generate logic to work with latest and fix other bug. (Closed) Base URL: http://git.chromium.org/git/dev-util.git@master
Patch Set: Nits 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 | « no previous file | devserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2009-2010 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 cherrypy 8 import cherrypy
9 import os 9 import os
10 import shutil 10 import shutil
(...skipping 13 matching lines...) Expand all
24 factory_config: Path to the factory config file if handling factory 24 factory_config: Path to the factory config file if handling factory
25 requests. 25 requests.
26 use_test_image: Use chromiumos_test_image.bin rather than the standard. 26 use_test_image: Use chromiumos_test_image.bin rather than the standard.
27 static_url_base: base URL, other than devserver, for update images. 27 static_url_base: base URL, other than devserver, for update images.
28 client_prefix: The prefix for the update engine client. 28 client_prefix: The prefix for the update engine client.
29 forced_image: Path to an image to use for all updates. 29 forced_image: Path to an image to use for all updates.
30 """ 30 """
31 31
32 def __init__(self, serve_only=None, test_image=False, urlbase=None, 32 def __init__(self, serve_only=None, test_image=False, urlbase=None,
33 factory_config_path=None, client_prefix=None, forced_image=None, 33 factory_config_path=None, client_prefix=None, forced_image=None,
34 use_cached=False, port=8080, src_image='', vm=False, *args, 34 use_cached=False, port=8080, src_image='', vm=False, board=None,
35 **kwargs): 35 *args, **kwargs):
36 super(Autoupdate, self).__init__(*args, **kwargs) 36 super(Autoupdate, self).__init__(*args, **kwargs)
37 self.serve_only = serve_only 37 self.serve_only = serve_only
38 self.factory_config = factory_config_path 38 self.factory_config = factory_config_path
39 self.use_test_image = test_image 39 self.use_test_image = test_image
40 if urlbase: 40 if urlbase:
41 self.urlbase = urlbase 41 self.urlbase = urlbase
42 else: 42 else:
43 self.urlbase = None 43 self.urlbase = None
44 44
45 self.client_prefix = client_prefix 45 self.client_prefix = client_prefix
46 self.forced_image = forced_image 46 self.forced_image = forced_image
47 self.use_cached = use_cached 47 self.use_cached = use_cached
48 self.src_image = src_image 48 self.src_image = src_image
49 self.vm = vm 49 self.vm = vm
50 self.board = board
50 51
51 def _GetSecondsSinceMidnight(self): 52 def _GetSecondsSinceMidnight(self):
52 """Returns the seconds since midnight as a decimal value.""" 53 """Returns the seconds since midnight as a decimal value."""
53 now = time.localtime() 54 now = time.localtime()
54 return now[3] * 3600 + now[4] * 60 + now[5] 55 return now[3] * 3600 + now[4] * 60 + now[5]
55 56
56 def _GetDefaultBoardID(self): 57 def _GetDefaultBoardID(self):
57 """Returns the default board id stored in .default_board.""" 58 """Returns the default board id stored in .default_board."""
58 board_file = '%s/.default_board' % (self.scripts_dir) 59 board_file = '%s/.default_board' % (self.scripts_dir)
59 try: 60 try:
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 290
290 Args: 291 Args:
291 image_path: full path to the image. 292 image_path: full path to the image.
292 move_to_static_dir: Moves the files from their dir to the static dir. 293 move_to_static_dir: Moves the files from their dir to the static dir.
293 static_image_dir: the directory to move images to after generating. 294 static_image_dir: the directory to move images to after generating.
294 Returns: 295 Returns:
295 True if the update payload was created successfully. 296 True if the update payload was created successfully.
296 """ 297 """
297 _LogMessage('Generating update for image %s' % image_path) 298 _LogMessage('Generating update for image %s' % image_path)
298 update_path = self.GenerateUpdateFile(image_path) 299 update_path = self.GenerateUpdateFile(image_path)
299 stateful_update_path = self.GenerateStatefulFile(image_path) 300 if update_path:
300 if not update_path or not stateful_update_path: 301 stateful_update_path = self.GenerateStatefulFile(image_path)
301 _LogMessage('Failed to generate update') 302 if stateful_update_path:
302 return False 303 if move_to_static_dir:
304 return self.MoveImagesToStaticDir(update_path, stateful_update_path,
305 static_image_dir)
303 306
304 if move_to_static_dir: 307 return True
305 return self.MoveImagesToStaticDir(update_path, stateful_update_path, 308
306 static_image_dir) 309 _LogMessage('Failed to generate update')
307 else: 310 return False
308 return True
309 311
310 def GenerateLatestUpdateImage(self, board_id, client_version, 312 def GenerateLatestUpdateImage(self, board_id, client_version,
311 static_image_dir=None): 313 static_image_dir=None):
312 """Generates an update using the latest image that has been built. 314 """Generates an update using the latest image that has been built.
313 315
314 This will only generate an update if the newest update is newer than that 316 This will only generate an update if the newest update is newer than that
315 on the client or client_version is 'ForcedUpdate'. 317 on the client or client_version is 'ForcedUpdate'.
316 318
317 Args: 319 Args:
318 board_id: Name of the board. 320 board_id: Name of the board.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 """Generates an update for non-factory and returns True on success.""" 468 """Generates an update for non-factory and returns True on success."""
467 if self.use_cached and os.path.exists(os.path.join(static_image_dir, 469 if self.use_cached and os.path.exists(os.path.join(static_image_dir,
468 'update.gz')): 470 'update.gz')):
469 _LogMessage('Using cached image regardless of timestamps.') 471 _LogMessage('Using cached image regardless of timestamps.')
470 return True 472 return True
471 else: 473 else:
472 if self.forced_image: 474 if self.forced_image:
473 has_built_image = self.GenerateUpdateImage( 475 has_built_image = self.GenerateUpdateImage(
474 self.forced_image, move_to_static_dir=True, 476 self.forced_image, move_to_static_dir=True,
475 static_image_dir=static_image_dir) 477 static_image_dir=static_image_dir)
476 # Now that we've generated it, force devserver to use it. 478 return has_built_image
477 self.use_cached = True
478 elif self.serve_only: 479 elif self.serve_only:
479 return self.GenerateImageFromZip(static_image_dir) 480 return self.GenerateImageFromZip(static_image_dir)
480 elif board_id and client_version:
481 return self.GenerateLatestUpdateImage(board_id,
482 client_version,
483 static_image_dir)
484 else: 481 else:
482 if board_id:
483 return self.GenerateLatestUpdateImage(board_id,
484 client_version,
485 static_image_dir)
486
487 _LogMessage('You must set --board for pre-generating latest update.')
485 return False 488 return False
486 489
487 def PreGenerateUpdate(self): 490 def PreGenerateUpdate(self):
488 """Pre-generates an update. Does not work for factory or label updates.""" 491 """Pre-generates an update. Returns True on success."""
489 # Does not work with factory config. 492 # Does not work with factory config.
490 assert(not self.factory_config) 493 assert(not self.factory_config)
491 _LogMessage('Pre-generating the update payload.') 494 _LogMessage('Pre-generating the update payload.')
492 # Does not work with labels so just use static dir. 495 # Does not work with labels so just use static dir.
493 if self.GenerateUpdatePayloadForNonFactory(None, None, self.static_dir): 496 if self.GenerateUpdatePayloadForNonFactory(self.board, '0.0.0.0',
497 self.static_dir):
494 # Force the devserver to use the pre-generated payload. 498 # Force the devserver to use the pre-generated payload.
495 self.use_cached = True 499 self.use_cached = True
500 _LogMessage('Pre-generated update successfully.')
501 return True
496 else: 502 else:
497 _LogMessage('Failed to pre-generate update.') 503 _LogMessage('Failed to pre-generate update.')
504 return False
498 505
499 def HandleUpdatePing(self, data, label=None): 506 def HandleUpdatePing(self, data, label=None):
500 """Handles an update ping from an update client. 507 """Handles an update ping from an update client.
501 508
502 Args: 509 Args:
503 data: xml blob from client. 510 data: xml blob from client.
504 label: optional label for the update. 511 label: optional label for the update.
505 Returns: 512 Returns:
506 Update payload message for client. 513 Update payload message for client.
507 """ 514 """
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 is_delta_format = self._IsDeltaFormatFile(filename) 567 is_delta_format = self._IsDeltaFormatFile(filename)
561 if label: 568 if label:
562 url = '%s/%s/update.gz' % (static_urlbase, label) 569 url = '%s/%s/update.gz' % (static_urlbase, label)
563 else: 570 else:
564 url = '%s/update.gz' % static_urlbase 571 url = '%s/update.gz' % static_urlbase
565 572
566 _LogMessage('Responding to client to use url %s to get image.' % url) 573 _LogMessage('Responding to client to use url %s to get image.' % url)
567 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format) 574 return self.GetUpdatePayload(hash, sha256, size, url, is_delta_format)
568 else: 575 else:
569 return self.GetNoUpdatePayload() 576 return self.GetNoUpdatePayload()
OLDNEW
« no previous file with comments | « no previous file | devserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698