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

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeQuirks.py

  • Committer: Brian Murray
  • Date: 2016-04-16 00:06:22 UTC
  • Revision ID: brian@canonical.com-20160416000622-gw3frf6js3oavtxm
DistUpgradeQuirks.py: Fix the quirk which inhibits screensavers.
(LP: #1570947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        self.arch = get_arch()
61
61
        self.plugin_manager = PluginManager(self.controller, ["./plugins"])
62
62
        self._poke = None
63
 
        self._uid = os.environ['SUDO_UID']
 
63
        self._uid = ''
64
64
        self._user_env = {}
65
65
 
66
66
    # the quirk function have the name:
407
407
                if len(line):
408
408
                    env = line.split('=', 1)
409
409
                    self._user_env[env[0]] = env[1]
410
 
        except:
411
 
            logging.exception("failed to read user env")
 
410
        except subprocess.CalledProcessError as e:
 
411
            if e.returncode == 1:
 
412
                logging.debug("gnome-session not running for user")
 
413
            else:
 
414
                logging.exception("failed to read user env")
412
415
 
413
416
    def _inhibitIdle(self):
414
417
        if os.path.exists("/usr/bin/gnome-session-inhibit"):
 
418
            self._uid = os.environ.get('SUDO_UID', '')
 
419
            if not self._uid:
 
420
                self._uid = os.environ.get('PKEXEC_UID', '')
 
421
            if not self._uid:
 
422
                logging.debug("failed to determine user upgrading")
 
423
                logging.error("failed to inhibit gnome-session idle")
 
424
                return
415
425
            self._getUserEnv()
 
426
            if not self._user_env:
 
427
                return
416
428
            #seteuid so dbus user session can be accessed
417
429
            os.seteuid(int(self._uid))
418
 
        
 
430
 
419
431
            logging.debug("inhibit gnome-session idle")
420
432
            try:
421
 
                idle = subprocess.Popen(["gnome-session-inhibit","--inhibit", 
422
 
                                          "idle", "--inhibit-only"],
423
 
                                          env=self._user_env)
 
433
                xdg_desktop = self._user_env.get("XDG_CURRENT_DESKTOP", "")
 
434
                if not xdg_desktop:
 
435
                    logging.debug("failed to find XDG_CURRENT_DESKTOP")
 
436
                    logging.error("failed to inhibit gnome-session idle")
 
437
                    return
 
438
                xdg_desktop = xdg_desktop.split(':')
 
439
                idle = subprocess.Popen(["gnome-session-inhibit", "--inhibit",
 
440
                                         "idle", "--inhibit-only"],
 
441
                                        env=self._user_env)
424
442
                # leave the inhibitor in place on Ubuntu GNOME, since the
425
 
                # lock screen will be broken after upgrade (LP :#1565178)
426
 
                xdg_desktop = self._user_env["XDG_CURRENT_DESKTOP"].split(':')
 
443
                # lock screen will be broken after upgrade (LP: #1565178)
427
444
                for desktop in xdg_desktop:
428
445
                    if "GNOME" not in desktop:
429
 
                        atexit.register(idle.terminate);
 
446
                        atexit.register(idle.terminate)
430
447
            except:
431
448
                logging.exception("failed to inhibit gnome-session idle")
432
449
            os.seteuid(os.getuid())