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

Side by Side Diff: src/platform/dev/autoupdate.py

Issue 661005: Fix autoupdate to be backwards compatible with previous releases. (Closed)
Patch Set: fix syntax Created 10 years, 9 months 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
« no previous file with comments | « no previous file | 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
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 web 9 import web
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 # Removes the portage build prefix. 51 # Removes the portage build prefix.
52 latest_version = latest_version.lstrip("g-") 52 latest_version = latest_version.lstrip("g-")
53 return latest_version.split('-')[0] 53 return latest_version.split('-')[0]
54 54
55 def CanUpdate(self, client_version, latest_version): 55 def CanUpdate(self, client_version, latest_version):
56 """ 56 """
57 Returns true iff the latest_version is greater than the client_version. 57 Returns true iff the latest_version is greater than the client_version.
58 """ 58 """
59 client_tokens = client_version.split('.') 59 client_tokens = client_version.split('.')
60 latest_tokens = latest_version.split('.') 60 latest_tokens = latest_version.split('.')
61 web.debug("client version %s latest version %s" % (client_version, latest_ve rsion)) 61 web.debug("client version %s latest version %s" \
62 % (client_version, latest_version))
62 for i in range(0,4): 63 for i in range(0,4):
63 if int(latest_tokens[i]) == int(client_tokens[i]): 64 if int(latest_tokens[i]) == int(client_tokens[i]):
64 continue 65 continue
65 return int(latest_tokens[i]) > int(client_tokens[i]) 66 return int(latest_tokens[i]) > int(client_tokens[i])
66 return False 67 return False
67 68
68 def BuildUpdateImage(self, image_path): 69 def BuildUpdateImage(self, image_path):
69 image_file = "%s/rootfs.image" % image_path 70 image_file = "%s/rootfs.image" % image_path
70 web.debug("checking image file %s/update.gz" % image_path) 71 web.debug("checking image file %s/update.gz" % image_path)
71 if not os.path.exists("%s/update.gz" % image_path): 72 if not os.path.exists("%s/update.gz" % image_path):
72 mkupdate = "%s/mk_memento_images.sh %s" % (self.scripts_dir, image_file) 73 mkupdate = "%s/mk_memento_images.sh %s" % (self.scripts_dir, image_file)
73 web.debug(mkupdate) 74 web.debug(mkupdate)
74 err = os.system(mkupdate) 75 err = os.system(mkupdate)
75 if err != 0: 76 if err != 0:
76 web.debug("failed to create update image") 77 web.debug("failed to create update image")
77 return False 78 return False
78 79
79 web.debug("Found an image, copying it to static") 80 web.debug("Found an image, copying it to static")
80 err = os.system("cp %s/update.gz %s" % (image_path, self.static_dir)) 81 err = os.system("cp %s/update.gz %s" % (image_path, self.static_dir))
81 if err != 0: 82 if err != 0:
82 web.debug("Unable to move update.gz from %s to %s" % (image_path, self.sta tic_dir)) 83 web.debug("Unable to move update.gz from %s to %s" \
84 % (image_path, self.static_dir))
83 return False 85 return False
84 return True 86 return True
85 87
86 def GetSize(self, update_path): 88 def GetSize(self, update_path):
87 return os.path.getsize(update_path) 89 return os.path.getsize(update_path)
88 90
89 def GetHash(self, update_path): 91 def GetHash(self, update_path):
90 cmd = "cat %s | openssl sha1 -binary | openssl base64 | tr \'\\n\' \' \';" % update_path 92 cmd = "cat %s | openssl sha1 -binary | openssl base64 | tr \'\\n\' \' \';" \
93 % update_path
91 web.debug(cmd) 94 web.debug(cmd)
92 return os.popen(cmd).read() 95 return os.popen(cmd).read()
93 96
94 def HandleUpdatePing(self, data): 97 def HandleUpdatePing(self, data):
95 update_dom = minidom.parseString(data) 98 update_dom = minidom.parseString(data)
96 root = update_dom.firstChild 99 root = update_dom.firstChild
97 query = root.getElementsByTagName("o:app")[0] 100 query = root.getElementsByTagName("o:app")[0]
98 client_version = query.attributes['version'].value 101 client_version = query.getAttribute('version')
99 board_id = query.attributes['board'].value 102 board_id = query.hasAttribute('board') and query.getAttribute('board') \
100 latest_image_path = self.GetLatestImagePath(board_id); 103 or "x86-generic"
101 latest_version = self.GetLatestVersion(latest_image_path); 104 latest_image_path = self.GetLatestImagePath(board_id)
102 if client_version != "ForcedUpdate" and not self.CanUpdate(client_version, l atest_version): 105 latest_version = self.GetLatestVersion(latest_image_path)
106 if client_version != "ForcedUpdate" \
107 and not self.CanUpdate(client_version, latest_version):
103 web.debug("no update") 108 web.debug("no update")
104 return self.GetNoUpdatePayload() 109 return self.GetNoUpdatePayload()
105 110
106 web.debug("update found %s " % latest_version) 111 web.debug("update found %s " % latest_version)
107 ok = self.BuildUpdateImage(latest_image_path) 112 ok = self.BuildUpdateImage(latest_image_path)
108 if ok != True: 113 if ok != True:
109 web.debug("Failed to build an update image") 114 web.debug("Failed to build an update image")
110 return self.GetNoUpdatePayload() 115 return self.GetNoUpdatePayload()
111 116
112 hash = self.GetHash("%s/update.gz" % self.static_dir) 117 hash = self.GetHash("%s/update.gz" % self.static_dir)
113 size = self.GetSize("%s/update.gz" % self.static_dir) 118 size = self.GetSize("%s/update.gz" % self.static_dir)
114 hostname = web.ctx.host 119 hostname = web.ctx.host
115 url = "http://%s/static/update.gz" % hostname 120 url = "http://%s/static/update.gz" % hostname
116 return self.GetUpdatePayload(hash, size, url) 121 return self.GetUpdatePayload(hash, size, url)
117 122
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698