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

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeQuirks.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:
263
263
        if not os.path.exists(cpuinfo_path):
264
264
            logging.error("cannot open %s ?!?" % cpuinfo_path)
265
265
            return True
266
 
        cpuinfo = open(cpuinfo_path).read()
 
266
        with open(cpuinfo_path) as f:
 
267
            cpuinfo = f.read()
267
268
        # check family
268
269
        if re.search("^cpu family\s*:\s*[345]\s*", cpuinfo, re.MULTILINE):
269
270
            logging.debug("found cpu family [345], no i686+")
304
305
        try:
305
306
            os.kill(1, 0)
306
307
        except:
307
 
            logging.warn("no init found")
 
308
            logging.warning("no init found")
308
309
            res = self._view.askYesNoQuestion(
309
310
                _("No init available"),
310
311
                _("Your system appears to be a virtualised environment "
325
326
        if not os.path.exists("/proc/cpuinfo"):
326
327
            logging.error("cannot open /proc/cpuinfo ?!?")
327
328
            return False
328
 
        cpuinfo = open("/proc/cpuinfo")
329
 
        if re.search("^Processor\s*:\s*ARMv[45]", cpuinfo.read(),
 
329
        with open("/proc/cpuinfo") as f:
 
330
            cpuinfo = f.read()
 
331
        if re.search("^Processor\s*:\s*ARMv[45]", cpuinfo,
330
332
                     re.MULTILINE):
331
333
            return False
332
334
        return True
401
403
        # upgrade from Precise will fail if PAE is not in cpu flags
402
404
        logging.debug("_checkPae")
403
405
        pae = 0
404
 
        cpuinfo = open('/proc/cpuinfo').read()
 
406
        with open('/proc/cpuinfo') as f:
 
407
            cpuinfo = f.read()
405
408
        if re.search("^flags\s+:.* pae ", cpuinfo, re.MULTILINE):
406
409
            pae = 1
407
410
        if not pae:
420
423
        XORG = "/etc/X11/xorg.conf"
421
424
        if not os.path.exists(XORG):
422
425
            return False
423
 
        for line in open(XORG):
 
426
        with open(XORG) as f:
 
427
            lines = f.readlines()
 
428
        for line in lines:
424
429
            s = line.split("#")[0].strip()
425
430
            # check for fglrx driver entry
426
431
            if (s.lower().startswith("driver") and
464
469
                logging.debug("already at target hash, skipping '%s'" % path)
465
470
                continue
466
471
            elif md5.hexdigest() != md5sum:
467
 
                logging.warn("unexpected target md5sum, skipping: '%s'" % path)
 
472
                logging.warning("unexpected target md5sum, skipping: '%s'" % path)
468
473
                continue
469
474
            # patchable, do it
470
475
            from .DistUpgradePatcher import patch
488
493
        # get pkg
489
494
        if (pkgname not in self.controller.cache or
490
495
                not self.controller.cache[pkgname].candidate):
491
 
            logging.warn("can not find '%s' in cache")
 
496
            logging.warning("can not find '%s' in cache")
492
497
            return False
493
498
        pkg = self.controller.cache[pkgname]
494
499
        for (module, pciid_list) in \
570
575
                os.makedirs("/etc/dpkg/dpkg.cfg.d/")
571
576
            except OSError:
572
577
                pass
573
 
            open(cfg, "w").write("foreign-architecture %s\n" % foreign_arch)
 
578
            with open(cfg, "w") as f:
 
579
                f.write("foreign-architecture %s\n" % foreign_arch)
574
580
 
575
581
    def ensure_recommends_are_installed_on_desktops(self):
576
582
        """ ensure that on a desktop install recommends are installed
580
586
            if not apt.apt_pkg.config.find_b("Apt::Install-Recommends"):
581
587
                msg = "Apt::Install-Recommends was disabled,"
582
588
                msg += " enabling it just for the upgrade"
583
 
                logging.warn(msg)
 
589
                logging.warning(msg)
584
590
                apt.apt_pkg.config.set("Apt::Install-Recommends", "1")