All pastes #1908006 Raw Edit

David A. Chapman

public python v1 · immutable
#1908006 ·published 2010-07-25 14:03 UTC
rendered paste body
#!/usr/bin/python"""    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 3 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."""__author__ = "David A. Chapman" # WEBSITE: http://dchapman.servehttp.com/__module_name__ = "Simple Shutdown Conformation"__module_version__ = "1.0"__module_description__ = "A simple shutdown conformation script for the Ubuntu/Debian Linux operating system. This program requires that /sbin/shutdown's permissions be set to chmod u+s, or shutdown as root."# For an example in which one can use this, consider the fact that I run fluxbox, the graphical X11 # windows manager for Ubuntu/Debian Linux. When you edit /etc/X11/fluxbox/fluxbox-menu to include an # executable shutdown option this script comes in handy. To have this exectuable option work # correctly, I would suggest running 'sudo chmod u+s /sbin/shutdown' so that everyone has the option# of restarting or shutting down the computer. Considering this, one might click the added shutdown # option by  mistake and instantly find their computer going down for the count... # The solution: Simple Shutdown Conformation 1.0# From the example, one would add something like this to: /etc/X11/fluxbox/fluxbox-menu: # [exec] (Shutdown) { /PATH/TO/COMMAND } < /PATH/TO/ICON >## In my case I use the Simple Shutdown Conformation program like this:# [exec] (Shutdown) {/usr/bin/xterm -e python ~/.fluxbox/scripts/shutdown.py} <># It launches xterm, telling it to instantly launch a command following the -e flag.import os, string# Set XTerm's title to the program's name via an escape sequence represented by octalsprint "\033]2;Simple Shutdown Conformation v1.0\007";# Ask the user if they really want to shutdown their computer,# and store the user's choice in a variable for conforamtion.ask = "Are you sure you want to shutdown the computer [Y/n]? "confirm = raw_input(ask)# Use deduction to see if the user really wants to shutdown their machine.if confirm == "Y" or confirm == "y":	print string.upper("Shutting the machine down!")	os.system("/sbin/shutdown -h now Shutting down the machine!")	# To run as root use:	"""os.system("sudo /sbin/shutdown -h now Shutting down the machine!")"""else:	os.system("exit")#EOF