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

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeController.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:
363
363
        logging.debug("_pythonSymlinkCheck run")
364
364
        if os.path.exists('/usr/share/python/debian_defaults'):
365
365
            config = SafeConfigParser()
366
 
            config.readfp(open('/usr/share/python/debian_defaults'))
 
366
            with open('/usr/share/python/debian_defaults') as f:
 
367
                config.readfp(f)
367
368
            try:
368
369
                expected_default = config.get('DEFAULT', 'default-version')
369
370
            except NoOptionError:
552
553
                        s += "deb http://archive.ubuntu.com/ubuntu %s main restricted" % self.toDist
553
554
                        s += "deb http://archive.ubuntu.com/ubuntu %s-updates main restricted" % self.toDist
554
555
                        s += "deb http://security.ubuntu.com/ubuntu %s-security main restricted" % self.toDist
555
 
                        open("/etc/apt/sources.list","w").write(s)
 
556
                        with open("/etc/apt/sources.list","w") as f:
 
557
                            f.write(s)
556
558
                    break
557
559
 
558
560
        # this must map, i.e. second in "from" must be the second in "to"
1140
1142
                # the previous release, no packages have been installed
1141
1143
                # yet (LP: #328655, #356781)
1142
1144
                if os.path.exists("/var/run/ubuntu-release-upgrader-apt-exception"):
1143
 
                    e = open("/var/run/ubuntu-release-upgrader-apt-exception").read()
 
1145
                    with open("/var/run/ubuntu-release-upgrader-apt-exception") as f:
 
1146
                        e = f.read()
1144
1147
                    logging.error("found exception: '%s'" % e)
1145
1148
                    # if its a ordering bug we can cleanly revert but we need to write
1146
1149
                    # a marker for the parent process to know its this kind of error
1486
1489
        # go over the sources.list and try to find a valid mirror
1487
1490
        # that we can use to add the backports dir
1488
1491
        logging.debug("writing prerequists sources.list at: '%s' " % out)
1489
 
        outfile = open(out, "w")
1490
1492
        mirrorlines = self._getPreReqMirrorLines(dumb)
1491
 
        for line in open(template):
1492
 
            template = Template(line)
1493
 
            outline = template.safe_substitute(mirror=mirrorlines)
1494
 
            outfile.write(outline)
1495
 
            logging.debug("adding '%s' prerequists" % outline)
1496
 
        outfile.close()
 
1493
        with open(out, "w") as outfile, open(template) as infile:
 
1494
            for line in infile:
 
1495
                template = Template(line)
 
1496
                outline = template.safe_substitute(mirror=mirrorlines)
 
1497
                outfile.write(outline)
 
1498
                logging.debug("adding '%s' prerequists" % outline)
1497
1499
        return True
1498
1500
 
1499
1501
    def getRequiredBackports(self):