printrun-src/printrun/power/__init__.py

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
37 import dbus 37 import dbus
38 inhibit_sleep_handler = None 38 inhibit_sleep_handler = None
39 inhibit_sleep_token = None 39 inhibit_sleep_token = None
40 bus = dbus.SessionBus() 40 bus = dbus.SessionBus()
41 try: 41 try:
42 # GNOME uses the right object path, try it first 42 if os.environ.get('DESKTOP_SESSION') == "mate":
43 service_name = "org.freedesktop.ScreenSaver" 43 # Mate uses a special service
44 proxy = bus.get_object(service_name, 44 service_name = "org.mate.ScreenSaver"
45 "/org/freedesktop/ScreenSaver") 45 object_path = "/org/mate/ScreenSaver"
46 else:
47 # standard service name
48 service_name = "org.freedesktop.ScreenSaver"
49 object_path = "/org/freedesktop/ScreenSaver"
50 # GNOME and Mate use the right object path, try it first
51 proxy = bus.get_object(service_name, object_path)
46 inhibit_sleep_handler = dbus.Interface(proxy, service_name) 52 inhibit_sleep_handler = dbus.Interface(proxy, service_name)
47 # Do a test run 53 # Do a test run
48 token = inhibit_sleep_handler.Inhibit("printrun", "test") 54 token = inhibit_sleep_handler.Inhibit("printrun", "test")
49 inhibit_sleep_handler.UnInhibit(token) 55 inhibit_sleep_handler.UnInhibit(token)
50 except dbus.DBusException: 56 except dbus.DBusException:
63 global inhibit_sleep_handler, inhibit_sleep_token 69 global inhibit_sleep_handler, inhibit_sleep_token
64 if inhibit_sleep_handler is None or inhibit_sleep_token is None: 70 if inhibit_sleep_handler is None or inhibit_sleep_token is None:
65 return 71 return
66 inhibit_sleep_handler.UnInhibit(inhibit_sleep_token) 72 inhibit_sleep_handler.UnInhibit(inhibit_sleep_token)
67 inhibit_sleep_token = None 73 inhibit_sleep_token = None
68 except Exception, e: 74 except Exception as e:
69 logging.warning("Could not setup DBus for sleep inhibition: %s" % e) 75 logging.warning("Could not setup DBus for sleep inhibition: %s" % e)
70 76
71 def inhibit_sleep(reason): 77 def inhibit_sleep(reason):
72 return 78 return
73 79
105 for i in range(-20, 0): 111 for i in range(-20, 0):
106 try: 112 try:
107 set_nice(i, p) 113 set_nice(i, p)
108 high_priority_nice = i 114 high_priority_nice = i
109 break 115 break
110 except psutil.AccessDenied, e: 116 except psutil.AccessDenied as e:
111 pass 117 pass
112 set_nice(orig_nice, p) 118 set_nice(orig_nice, p)
113 119
114 def set_priority(): 120 def set_priority():
115 if platform.system() == "Windows": 121 if platform.system() == "Windows":
130 inhibit_sleep(reason) 136 inhibit_sleep(reason)
131 137
132 def powerset_print_stop(): 138 def powerset_print_stop():
133 reset_priority() 139 reset_priority()
134 deinhibit_sleep() 140 deinhibit_sleep()
135 except ImportError, e: 141 except ImportError as e:
136 logging.warning("psutil unavailable, could not import power utils:" + str(e)) 142 logging.warning("psutil unavailable, could not import power utils:" + str(e))
137 143
138 def powerset_print_start(reason): 144 def powerset_print_start(reason):
139 pass 145 pass
140 146

mercurial