1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# dontzap.py -- utility to set the DontZap option in xorg.conf
#
# Copyright 2008 Alberto Milone <albertomilone@alice.it>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import sys
import getopt
from DontZap import dontzap
def usage():
instructionsList = ['The only accepted parameters are:'
'\n -e, --enable', '\tSet "DontZap" to "True" (Ctrl+Alt+Backspace does not restart the xserver).',
'\n -d, --disable', '\tSet "DontZap" to "False" (Ctrl+Alt+Backspace restarts the xserver).',
'\n -h, --help', '\tShow the help page.',
]
# Hidden option:
# '\n -i, --is-enabled', '\treturns the value assigned to DontZap.'
print ''.join(instructionsList)
def main():
err = 'Error: parameters not recognised'
try:
opts, args = getopt.getopt(sys.argv[1:], 'iedh', ['is-enabled', 'enable', 'disable', 'help'])
except getopt.GetoptError, err:
# print help information and exit:
sys.stderr.write(str(err)+"\n") # will print something like 'option -a not recognized'
usage()
sys.exit(2)
zap = dontzap.DontZap()
# If called with no args, show the help page
if not opts:
usage()
sys.exit()
for o, a in opts:
if o in ('-i', '--is-enabled'):
sys.exit(zap.isDontZapEnabled())
elif o in ('-e', '--enable'):
try:
zap.setDontZap(True)
except IOError, err:
sys.stderr.write("Error: Couldn't enable dontzap (are you running as root?)\n")
sys.exit(2)
sys.exit()
elif o in ('-d', '--disable'):
try:
zap.setDontZap(False)
except IOError, err:
sys.stderr.write("Error: Couldn't disable dontzap (are you running as root?)\n")
sys.exit(2)
sys.exit()
elif o in ('-h', '--help'):
usage()
sys.exit()
else:
assert False, 'unhandled option'
if __name__ == '__main__':
main()
|