4 # Copyright (c) 2006 crazy___cow@hotmail.com
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 def disable_sleep(myprogram
):
35 bus
= dbus
.Bus(dbus
.Bus
.TYPE_SESSION
)
36 devobj
= bus
.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')
37 dev
= dbus
.Interface(devobj
, "org.gnome.ScreenSaver")
38 cookie
= dev
.Inhibit(myprogram
, 'Disabled by DisableGSS Daemon')
39 print "DisableGSS: gnome screensaver stopped."
42 print "DisableGSS: could not send the dbus Inhibit signal: %s" % e
47 def allow_sleep(dev
, cookie
):
50 print "DisableGSS: gnome screensaver enabled."
53 print "DisableGSS: could not send the dbus UnInhibit signal: %s" % e
60 f
= os
.popen('ps aux', 'r')
61 for l
in f
.readlines():
62 fields
= string
.split(l
)
63 if fields
[10] == program
:
64 #print fields[1]+" "+fields[10]
72 f
=open(homedir
+'/.disablegss', 'r')
74 #print line.rstrip('\n')
75 __psaux
.append(line
.rstrip('\n'))
77 print "DisableGSS: config file read."
80 print "DisableGSS: config file ~/.disablegss doesn't exist! Write it by hand. Add applications name that could disable gnome screensaver: one app name for every line of file."
87 if __name__
== '__main__':
90 homedir
= os
.getenv('HOME')
95 last_last_time_modified
= ""
96 last_time_modified
= ""
99 last_time_modified
= os
.stat(homedir
+'/.disablegss')[ST_MTIME
]
100 last_last_time_modified
=last_time_modified
102 while condition
== True:
104 for i
in range(len(psaux
)):
105 #print "%s->%s" % (i,psaux[i])
107 if pids(program
) == True:
109 if program
!=old_program
:
110 print "DisableGSS: there is a program ("+program
+") in the config list that is currently running."
113 (dev
, cookie
) = disable_sleep(program
)
117 if found
== False and disabled
== True:
118 print "DisableGSS: there are no more programs that could stop gnome screensaver."
119 allow_sleep(dev
, cookie
)
122 last_time_modified
= os
.stat(homedir
+'/.disablegss')[ST_MTIME
]
123 if last_time_modified
!=last_last_time_modified
:
124 print "DisableGSS: config file modified."
126 last_time_modified
= os
.stat(homedir
+'/.disablegss')[ST_MTIME
]
127 last_last_time_modified
=last_time_modified