Ignore:
Timestamp:
03/24/19 08:15:59 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Ran 2to3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/update.py

    r788 r919  
    11
    2 from config import Config
    3 from util import utf2unicode
     2from .config import Config
     3from .util import utf2unicode
    44
    55import os
    66import sys
    7 import urllib2
     7import urllib.request, urllib.error, urllib.parse
    88import tempfile
    99import socket
     
    5757
    5858        Each file is returned as a 3-tuple with items as in the file."""
    59         for (path, (size, sum)) in self._files.iteritems():
     59        for (path, (size, sum)) in self._files.items():
    6060            yield (path, size, sum)
    6161
     
    9999    def writeInto(self, file):
    100100        """Write the manifest into the file at the given path."""
    101         for (path, (size, sum)) in self._files.iteritems():
     101        for (path, (size, sum)) in self._files.items():
    102102            file.write("%s\t%d\t%s\n" % (path, size, sum))
    103103
     
    207207        with open(manifestPath, "rt") as f:
    208208            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)))
    211211        manifest = Manifest()
    212212
     
    226226    try:
    227227        updateManifest = Manifest()
    228         f= urllib2.urlopen(updateURL + "/" + manifestName)
     228        f= urllib.request.urlopen(updateURL + "/" + manifestName)
    229229        updateManifest.readFrom(f)
    230230
    231     except Exception, e:
     231    except Exception as e:
    232232        error = utf2unicode(str(e))
    233         print >> sys.stderr, "Error downloading manifest:", error
     233        print("Error downloading manifest:", error, file=sys.stderr)
    234234        listener.failed(error)
    235235        return None
     
    298298                pass
    299299            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)))
    302302
    303303#------------------------------------------------------------------------------
     
    359359               
    360360            with open(targetFile, "wb") as fout:
    361                 fin = urllib2.urlopen(updateURL + "/" + path)
     361                fin = urllib.request.urlopen(updateURL + "/" + path)
    362362                while True:
    363363                    data = fin.read(4096)
     
    391391       
    392392        listener.done()
    393     except Exception, e:
     393    except Exception as e:
    394394        exc = traceback.format_exc()
    395         print >> sys.stderr, utf2unicode(exc)
     395        print(utf2unicode(exc), file=sys.stderr)
    396396       
    397397        error = utf2unicode(str(e))
    398         print >> sys.stderr, "Error:", error
     398        print("Error:", error, file=sys.stderr)
    399399
    400400        listener.failed(error)
     
    409409        f.close()
    410410        return True
    411     except Exception, e:
     411    except Exception as e:
    412412        return False
    413413    finally:
     
    439439                listener.downloadedManifest()
    440440            elif command=="setTotalSize":
    441                 listener.setTotalSize(int(words[1]), long(words[2]),
     441                listener.setTotalSize(int(words[1]), int(words[2]),
    442442                                      int(words[3]), int(words[4]))
    443443            elif command=="setDownloaded":
    444                 listener.setDownloaded(long(words[1]))
     444                listener.setDownloaded(int(words[1]))
    445445            elif command=="startRenaming":
    446446                listener.startRenaming()
     
    457457            elif command=="failed":
    458458                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)
    462462
    463463    return buffer
     
    514514            process.wait()
    515515       
    516     except Exception, e:
     516    except Exception as e:
    517517        error = utf2unicode(str(e))
    518         print >> sys.stderr, "Failed updating:", error
     518        print("Failed updating:", error, file=sys.stderr)
    519519        listener.failed(error)
    520520    finally:
     
    563563            updateFiles(directory, updateURL, listener, updateManifest,
    564564                        modifiedAndNew, removed, localRemoved)
    565     except Exception, e:
     565    except Exception as e:
    566566        exc = traceback.format_exc()
    567         print >> sys.stderr, utf2unicode(exc)
     567        print(utf2unicode(exc), file=sys.stderr)
    568568       
    569569        error = utf2unicode(str(e))
    570         print >> sys.stderr, "Update error:", error
     570        print("Update error:", error, file=sys.stderr)
    571571       
    572572        listener.failed(error)
     
    596596    except:
    597597        exc = traceback.format_exc()
    598         print >> sys.stderr, utf2unicode(exc)
     598        print(utf2unicode(exc), file=sys.stderr)
    599599
    600600#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.