~ubuntu-core-dev/ubuntu/xenial/ubuntu-release-upgrader/xenial

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradePatcher.py

  • Committer: Dimitri John Ledkov
  • Date: 2015-01-20 22:30:06 UTC
  • mto: This revision was merged to the branch mainline in revision 2859.
  • Revision ID: dimitri.j.ledkov@intel.com-20150120223006-ba30fbqtp4x2n0og
Fix resource warnings & logging.warn deprecation warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
     STATE_EXPECT_DATA) = range(2)
40
40
 
41
41
    # this is inefficient for big files
42
 
    orig_lines = open(orig, encoding="UTF-8").readlines()
 
42
    with open(orig, encoding="UTF-8") as f:
 
43
        orig_lines = f.readlines()
43
44
    start = end = 0
44
45
 
45
46
    # we start in wait-for-commend state
46
47
    state = STATE_EXPECT_COMMAND
47
 
    for line in open(edpatch, encoding="UTF-8"):
 
48
    with open(edpatch, encoding="UTF-8") as f:
 
49
        lines = f.readlines()
 
50
    for line in lines:
48
51
        if state == STATE_EXPECT_COMMAND:
49
52
            # in commands get rid of whitespace, 
50
53
            line = line.strip()
102
105
        md5.update(result.encode("UTF-8"))
103
106
        if md5.hexdigest() != result_md5sum:
104
107
            raise PatchError("the md5sum after patching is not correct")
105
 
    open(orig, "w", encoding="UTF-8").write(result)
 
108
    with open(orig, "w", encoding="UTF-8") as f:
 
109
        f.write(result)
106
110
    return True