| 1 |
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas) |
| 2 |
# |
| 3 |
# This file is part of DeVeDe-NG |
| 4 |
# |
| 5 |
# DeVeDe-NG is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 3 |
| 7 |
# as published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# DeVeDe-NG is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 16 |
|
| 17 |
from gi.repository import Gio, GLib |
| 18 |
|
| 19 |
|
| 20 |
class shutdown: |
| 21 |
|
| 22 |
def __init__(self): |
| 23 |
|
| 24 |
# First, try with logind |
| 25 |
try: |
| 26 |
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) |
| 27 |
bus.call_sync("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", |
| 28 |
"PowerOff", GLib.Variant_boolean('(bb)', (False, False)), None, Gio.DBusCallFlags.NONE, -1, None) |
| 29 |
except: |
| 30 |
failure = True |
| 31 |
|
| 32 |
if (failure): |
| 33 |
failure = False |
| 34 |
|
| 35 |
# If it fails, try with ConsoleKit |
| 36 |
try: |
| 37 |
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) |
| 38 |
bus.call_sync("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", |
| 39 |
"Stop", None, None, Gio.DBusCallFlags.NONE, -1, None) |
| 40 |
except: |
| 41 |
failure = True |
| 42 |
|
| 43 |
if (failure): |
| 44 |
failure = False |
| 45 |
|
| 46 |
# If it fails, try with HAL |
| 47 |
try: |
| 48 |
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) |
| 49 |
bus.call_sync("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", |
| 50 |
"Shutdown", None, None, Gio.DBusCallFlags.NONE, -1, None) |
| 51 |
except: |
| 52 |
failure = True |