#!/usr/bin/python # A Museek banned and ignored users listing script # Requires: Python, xmessage # Credit: thanks for the help with the xml parser, Hyriand import commands, os, sys, getopt from xml.dom.minidom import parse doc = parse(os.path.expanduser('~/.museekd/config.xml')) root = doc.firstChild domains = root.getElementsByTagName("domain") x = 0 # Default options config_opt = "xmessage" #config_opt = "shell" mode = "ignored" def usage(): print ("""Ignored, Buddied & Banned Users output for Museek Author: Daelstorm Option: museek-users.py [OPTION]... Default options: -x -i -x, --xmessage Display with Xmessage -s --shell Display message in shell -i, --ignored Display ignored users -b, --banned Display banned users -u, --buddies Display buddies -h, --help Display this help and exit """) sys.exit(2) try: opts, args = getopt.getopt(sys.argv[1:], "hibusx", ["help", "shell", "xmessage", "ignored", "buddies", "banned"]) except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) for opts, args in opts: if opts in ("-h", "--help"): usage() sys.exit() if opts in ("-s", "--shell"): config_opt = "shell" if opts in ("-b", "--banned"): mode = "banned" if opts in ("-u", "--buddies"): mode = "buddies" if opts in ("-i", "--ignored"): mode = "ignored" if opts in ("-x", "--xmessage"): config_opt = "xmessage" if mode == "banned": extraoutput = "Banned:\n" elif mode == "ignored": extraoutput = "Ignored:\n" elif mode == "buddies": extraoutput = "Buddies:\n" else: print "You messed up my script, JERK. :|" sys.exit(0) tmp_file = str(os.path.expanduser('~/tmp/tmpfile')) tmp_file_w = file(tmp_file, 'w') for domain in domains: #print domain.getAttribute('id') if domain.getAttribute('id') == mode: x = 1 print >> tmp_file_w, extraoutput for key in domain.getElementsByTagName("key"): print >> tmp_file_w, key.getAttribute("id") #print key.getAttribute("id") if x ==1: tmp_file_w.close() if config_opt == "shell": print file(tmp_file, 'r').read() elif config_opt == "xmessage": os.system('xmessage -file ' + tmp_file) os.unlink(tmp_file) sys.exit()