#!/usr/bin/python import sys import commands import string try: arg = sys.argv[1] path = "/apps/modest/accounts/" + arg + "ID" except: print "\nPlease choose an account from the following list:" print "(alternatively, pass an account name from below as a parameter to toggle it)\n" data = commands.getoutput("gconftool-2 --all-dirs /apps/modest/accounts") accounts = string.split(data, '\n') i = 0 for acct in accounts: # path: /apps/modest/accounts/xxxID pathParts = string.split(acct, '/') theId = pathParts[4] # theId = xxxID nameParts = string.split(theId, 'ID') # ['xxx', ''] name = nameParts[0] status = commands.getoutput("gconftool-2 -g " + acct + "/enabled") if status == "true": statusText = "enabled" elif status == "false": statusText = "disabled" else: statusText = "state unknown" print "[" + str(i) + "] " + name + ": " + statusText i = i + 1 try: id = int(raw_input("\n\tSelection [0-" + str(i) + "]: ")) if id > i: print "Invalid selection." sys.exit(1) if id < 0: print "Invalid selection." sys.exit(1) except: sys.exit(0) path = accounts[id] path = string.rstrip(path) status = commands.getoutput("gconftool-2 -g " + path + "/enabled") if status == "true": exitState = commands.getstatusoutput("gconftool-2 -s " + path + "/enabled --type bool false") if exitState[0] > 0: print "The account could not be disabled." sys.exit(exitState) print "The account has been disabled." sys.exit(0) elif status == "false": exitState = commands.getstatusoutput("gconftool-2 -s " + path + "/enabled --type bool true") if exitState[0] > 0: print "The account could not be enabled." sys.exit(exitState) print "The account has been enabled." sys.exit(0) else: print "The specified account could not be found." sys.exit(1)