| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 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 """Create and copy update image to target host. | 7 """Create and copy update image to target host. |
| 8 | 8 |
| 9 auto-update and devserver change out from beneath us often enough | 9 auto-update and devserver change out from beneath us often enough |
| 10 that despite having to duplicate a litte code, it seems that the | 10 that despite having to duplicate a litte code, it seems that the |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 def GetSize(self, filename): | 213 def GetSize(self, filename): |
| 214 return os.path.getsize(filename) | 214 return os.path.getsize(filename) |
| 215 | 215 |
| 216 def GetHash(self, filename): | 216 def GetHash(self, filename): |
| 217 return self.cmd.RunPipe([['openssl', 'sha1', '-binary'], | 217 return self.cmd.RunPipe([['openssl', 'sha1', '-binary'], |
| 218 ['openssl', 'base64']], | 218 ['openssl', 'base64']], |
| 219 infile=filename, | 219 infile=filename, |
| 220 capture=True, oneline=True) | 220 capture=True, oneline=True) |
| 221 | 221 |
| 222 def GetSha256(self, filename): |
| 223 return self.cmd.RunPipe([['openssl', 'dgst', '-sha256', '-binary'], |
| 224 ['openssl', 'base64']], |
| 225 infile=filename, |
| 226 capture=True, oneline=True) |
| 227 |
| 222 def GetDefaultBoard(self): | 228 def GetDefaultBoard(self): |
| 223 def_board_file = self.CrosUtilsPath('.default_board') | 229 def_board_file = self.CrosUtilsPath('.default_board') |
| 224 if not os.path.exists(def_board_file): | 230 if not os.path.exists(def_board_file): |
| 225 return None | 231 return None |
| 226 return self.FileOneLine(def_board_file) | 232 return self.FileOneLine(def_board_file) |
| 227 | 233 |
| 228 def SetRemote(self, remote): | 234 def SetRemote(self, remote): |
| 229 self.ssh_cmd = SSHCommand(self, remote) | 235 self.ssh_cmd = SSHCommand(self, remote) |
| 230 | 236 |
| 231 def ParseShVars(self, string): | 237 def ParseShVars(self, string): |
| (...skipping 11 matching lines...) Expand all Loading... |
| 243 def GetRemoteRelease(self): | 249 def GetRemoteRelease(self): |
| 244 lsb_release = self.ssh_cmd.Output('cat', '/etc/lsb-release') | 250 lsb_release = self.ssh_cmd.Output('cat', '/etc/lsb-release') |
| 245 if not lsb_release: | 251 if not lsb_release: |
| 246 return None | 252 return None |
| 247 return self.ParseShVars(lsb_release) | 253 return self.ParseShVars(lsb_release) |
| 248 | 254 |
| 249 def CreateServer(self, port, update_file, stateful_file): | 255 def CreateServer(self, port, update_file, stateful_file): |
| 250 """Start the devserver clone.""" | 256 """Start the devserver clone.""" |
| 251 | 257 |
| 252 PingUpdateResponse.Setup(self.GetHash(update_file), | 258 PingUpdateResponse.Setup(self.GetHash(update_file), |
| 259 self.GetSha256(update_file), |
| 253 self.GetSize(update_file)) | 260 self.GetSize(update_file)) |
| 254 | 261 |
| 255 UpdateHandler.SetupUrl('/update', PingUpdateResponse()) | 262 UpdateHandler.SetupUrl('/update', PingUpdateResponse()) |
| 256 UpdateHandler.SetupUrl('/%s' % UPDATE_FILENAME, | 263 UpdateHandler.SetupUrl('/%s' % UPDATE_FILENAME, |
| 257 FileUpdateResponse(update_file, | 264 FileUpdateResponse(update_file, |
| 258 verbose=self.verbose)) | 265 verbose=self.verbose)) |
| 259 UpdateHandler.SetupUrl('/%s' % STATEFUL_FILENAME, | 266 UpdateHandler.SetupUrl('/%s' % STATEFUL_FILENAME, |
| 260 FileUpdateResponse(stateful_file, | 267 FileUpdateResponse(stateful_file, |
| 261 verbose=self.verbose)) | 268 verbose=self.verbose)) |
| 262 | 269 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 app_id = '87efface-864d-49a5-9bb3-4b050a7c227a' | 423 app_id = '87efface-864d-49a5-9bb3-4b050a7c227a' |
| 417 xmlns = 'http://www.google.com/update2/response' | 424 xmlns = 'http://www.google.com/update2/response' |
| 418 payload_success_template = """<?xml version="1.0" encoding="UTF-8"?> | 425 payload_success_template = """<?xml version="1.0" encoding="UTF-8"?> |
| 419 <gupdate xmlns="%s" protocol="2.0"> | 426 <gupdate xmlns="%s" protocol="2.0"> |
| 420 <daystart elapsed_seconds="%s"/> | 427 <daystart elapsed_seconds="%s"/> |
| 421 <app appid="{%s}" status="ok"> | 428 <app appid="{%s}" status="ok"> |
| 422 <ping status="ok"/> | 429 <ping status="ok"/> |
| 423 <updatecheck | 430 <updatecheck |
| 424 codebase="%s" | 431 codebase="%s" |
| 425 hash="%s" | 432 hash="%s" |
| 433 sha256="%s" |
| 426 needsadmin="false" | 434 needsadmin="false" |
| 427 size="%s" | 435 size="%s" |
| 428 status="ok"/> | 436 status="ok"/> |
| 429 </app> | 437 </app> |
| 430 </gupdate> | 438 </gupdate> |
| 431 """ | 439 """ |
| 432 payload_failure_template = """<?xml version="1.0" encoding="UTF-8"?> | 440 payload_failure_template = """<?xml version="1.0" encoding="UTF-8"?> |
| 433 <gupdate xmlns="%s" protocol="2.0"> | 441 <gupdate xmlns="%s" protocol="2.0"> |
| 434 <daystart elapsed_seconds="%s"/> | 442 <daystart elapsed_seconds="%s"/> |
| 435 <app appid="{%s}" status="ok"> | 443 <app appid="{%s}" status="ok"> |
| 436 <ping status="ok"/> | 444 <ping status="ok"/> |
| 437 <updatecheck status="noupdate"/> | 445 <updatecheck status="noupdate"/> |
| 438 </app> | 446 </app> |
| 439 </gupdate> | 447 </gupdate> |
| 440 """ | 448 """ |
| 441 | 449 |
| 442 def __init__(self): | 450 def __init__(self): |
| 443 self.content_type = 'text/xml' | 451 self.content_type = 'text/xml' |
| 444 | 452 |
| 445 @staticmethod | 453 @staticmethod |
| 446 def Setup(filehash, filesize): | 454 def Setup(filehash, filesha256, filesize): |
| 447 PingUpdateResponse.file_hash = filehash | 455 PingUpdateResponse.file_hash = filehash |
| 456 PingUpdateResponse.file_sha256 = filesha256 |
| 448 PingUpdateResponse.file_size = filesize | 457 PingUpdateResponse.file_size = filesize |
| 449 | 458 |
| 450 def Reply(self, handler, send_content=True, post_data=None): | 459 def Reply(self, handler, send_content=True, post_data=None): |
| 451 """Return (using StringResponse) an XML reply to ForcedUpdate clients.""" | 460 """Return (using StringResponse) an XML reply to ForcedUpdate clients.""" |
| 452 | 461 |
| 453 if not post_data: | 462 if not post_data: |
| 454 return UpdateResponse.Reply(self, handler) | 463 return UpdateResponse.Reply(self, handler) |
| 455 | 464 |
| 456 request_version = (minidom.parseString(post_data).firstChild. | 465 request_version = (minidom.parseString(post_data).firstChild. |
| 457 getElementsByTagName('o:app')[0]. | 466 getElementsByTagName('o:app')[0]. |
| 458 getAttribute('version')) | 467 getAttribute('version')) |
| 459 | 468 |
| 460 if request_version == 'ForcedUpdate': | 469 if request_version == 'ForcedUpdate': |
| 461 host, pdict = cgi.parse_header(handler.headers.getheader('Host')) | 470 host, pdict = cgi.parse_header(handler.headers.getheader('Host')) |
| 462 self.string = (self.payload_success_template % | 471 self.string = (self.payload_success_template % |
| 463 (self.xmlns, self.SecondsSinceMidnight(), | 472 (self.xmlns, self.SecondsSinceMidnight(), |
| 464 self.app_id, 'http://%s/%s' % (host, UPDATE_FILENAME), | 473 self.app_id, 'http://%s/%s' % (host, UPDATE_FILENAME), |
| 465 self.file_hash, self.file_size)) | 474 self.file_hash, self.file_sha256, self.file_size)) |
| 466 else: | 475 else: |
| 467 self.string = (self.payload_failure_template % | 476 self.string = (self.payload_failure_template % |
| 468 (self.xmlns, self.SecondsSinceMidnight(), self.app_id)) | 477 (self.xmlns, self.SecondsSinceMidnight(), self.app_id)) |
| 469 | 478 |
| 470 StringUpdateResponse.Reply(self, handler, send_content) | 479 StringUpdateResponse.Reply(self, handler, send_content) |
| 471 | 480 |
| 472 def SecondsSinceMidnight(self): | 481 def SecondsSinceMidnight(self): |
| 473 now = time.localtime() | 482 now = time.localtime() |
| 474 return now[3] * 3600 + now[4] * 60 + now[5] | 483 return now[3] * 3600 + now[4] * 60 + now[5] |
| 475 | 484 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 657 |
| 649 if child: | 658 if child: |
| 650 os.kill(child, 15) | 659 os.kill(child, 15) |
| 651 | 660 |
| 652 cros_env.Info('Server exiting with status %d' % exit_status) | 661 cros_env.Info('Server exiting with status %d' % exit_status) |
| 653 sys.exit(exit_status) | 662 sys.exit(exit_status) |
| 654 | 663 |
| 655 | 664 |
| 656 if __name__ == '__main__': | 665 if __name__ == '__main__': |
| 657 main(sys.argv) | 666 main(sys.argv) |
| OLD | NEW |