Changeset 919:2ce8ca39525b for src/mlx/update.py
- Timestamp:
- 03/24/19 08:15:59 (5 years ago)
- Branch:
- python3
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/update.py
r788 r919 1 1 2 from config import Config3 from util import utf2unicode2 from .config import Config 3 from .util import utf2unicode 4 4 5 5 import os 6 6 import sys 7 import urllib 27 import urllib.request, urllib.error, urllib.parse 8 8 import tempfile 9 9 import socket … … 57 57 58 58 Each file is returned as a 3-tuple with items as in the file.""" 59 for (path, (size, sum)) in self._files.ite ritems():59 for (path, (size, sum)) in self._files.items(): 60 60 yield (path, size, sum) 61 61 … … 99 99 def writeInto(self, file): 100 100 """Write the manifest into the file at the given path.""" 101 for (path, (size, sum)) in self._files.ite ritems():101 for (path, (size, sum)) in self._files.items(): 102 102 file.write("%s\t%d\t%s\n" % (path, size, sum)) 103 103 … … 207 207 with open(manifestPath, "rt") as f: 208 208 manifest.readFrom(f) 209 except Exception ,e:210 print "Error reading the manifest, ignoring:", utf2unicode(str(e))209 except Exception as e: 210 print("Error reading the manifest, ignoring:", utf2unicode(str(e))) 211 211 manifest = Manifest() 212 212 … … 226 226 try: 227 227 updateManifest = Manifest() 228 f= urllib 2.urlopen(updateURL + "/" + manifestName)228 f= urllib.request.urlopen(updateURL + "/" + manifestName) 229 229 updateManifest.readFrom(f) 230 230 231 except Exception ,e:231 except Exception as e: 232 232 error = utf2unicode(str(e)) 233 print >> sys.stderr, "Error downloading manifest:", error233 print("Error downloading manifest:", error, file=sys.stderr) 234 234 listener.failed(error) 235 235 return None … … 298 298 pass 299 299 os.rename(path, targetPath) 300 except Exception ,e:301 print "Cannot remove file " + path + ": " + utf2unicode(str(e))300 except Exception as e: 301 print("Cannot remove file " + path + ": " + utf2unicode(str(e))) 302 302 303 303 #------------------------------------------------------------------------------ … … 359 359 360 360 with open(targetFile, "wb") as fout: 361 fin = urllib 2.urlopen(updateURL + "/" + path)361 fin = urllib.request.urlopen(updateURL + "/" + path) 362 362 while True: 363 363 data = fin.read(4096) … … 391 391 392 392 listener.done() 393 except Exception ,e:393 except Exception as e: 394 394 exc = traceback.format_exc() 395 print >> sys.stderr, utf2unicode(exc)395 print(utf2unicode(exc), file=sys.stderr) 396 396 397 397 error = utf2unicode(str(e)) 398 print >> sys.stderr, "Error:", error398 print("Error:", error, file=sys.stderr) 399 399 400 400 listener.failed(error) … … 409 409 f.close() 410 410 return True 411 except Exception ,e:411 except Exception as e: 412 412 return False 413 413 finally: … … 439 439 listener.downloadedManifest() 440 440 elif command=="setTotalSize": 441 listener.setTotalSize(int(words[1]), long(words[2]),441 listener.setTotalSize(int(words[1]), int(words[2]), 442 442 int(words[3]), int(words[4])) 443 443 elif command=="setDownloaded": 444 listener.setDownloaded( long(words[1]))444 listener.setDownloaded(int(words[1])) 445 445 elif command=="startRenaming": 446 446 listener.startRenaming() … … 457 457 elif command=="failed": 458 458 listener.failed(words[1]) 459 except Exception ,e:460 print >> sys.stderr,"Failed to parse line '%s': %s" % \461 (line, utf2unicode(str(e))) 459 except Exception as e: 460 print("Failed to parse line '%s': %s" % \ 461 (line, utf2unicode(str(e))), file=sys.stderr) 462 462 463 463 return buffer … … 514 514 process.wait() 515 515 516 except Exception ,e:516 except Exception as e: 517 517 error = utf2unicode(str(e)) 518 print >> sys.stderr, "Failed updating:", error518 print("Failed updating:", error, file=sys.stderr) 519 519 listener.failed(error) 520 520 finally: … … 563 563 updateFiles(directory, updateURL, listener, updateManifest, 564 564 modifiedAndNew, removed, localRemoved) 565 except Exception ,e:565 except Exception as e: 566 566 exc = traceback.format_exc() 567 print >> sys.stderr, utf2unicode(exc)567 print(utf2unicode(exc), file=sys.stderr) 568 568 569 569 error = utf2unicode(str(e)) 570 print >> sys.stderr, "Update error:", error570 print("Update error:", error, file=sys.stderr) 571 571 572 572 listener.failed(error) … … 596 596 except: 597 597 exc = traceback.format_exc() 598 print >> sys.stderr, utf2unicode(exc)598 print(utf2unicode(exc), file=sys.stderr) 599 599 600 600 #------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.