#!/usr/bin/python DESCRIPTION="Script to retreive info about local cell" USAGE='''Usage: cellinfo #usage/help cellinfo shortname #m1/m2/m3/... cellinfo name #pareto,infrae,... cellinfo group #pareto,infrae,... cellinfo fqdn #zopedev.pareto.nl, infrae.com, ... ''' NEEDS='''This Script needs: /etc/cell/shortname #with for example: m4 /etc/cell/name #with for example: infrae /etc/cell/group #with for example: infrae ''' import string,re,sys,os DEBUG=0 BASEDIR='/etc/cell' # FUNCTIONS: def main(): REQUEST=getcommands() debug('REQUEST='+REQUEST) if REQUEST == "shortname": cat(REQUEST) elif REQUEST == "name": cat(REQUEST) elif REQUEST == "fqdn": cat(REQUEST) elif REQUEST == "group": cat(REQUEST) elif REQUEST == "": sys.stdout.write(DESCRIPTION + '\n\n' + USAGE+ '\n') sys.exit(0) def cat(FILENAME): #simple way if os.access(BASEDIR+'/'+FILENAME,os.F_OK): print open(BASEDIR+'/'+FILENAME).read().strip() def debug(STRING): if DEBUG: sys.stderr.write('DEBUG: '+STRING+'\n') def getcommands(): REQUEST="" global DEBUG sys.argv.pop(0) #den ersten eintrag weg, nur die nachfolgenden enthalten optionen while 1: try: arg=sys.argv.pop(0) except IndexError: break if arg == '-d' or arg == '--debug' or arg == '-debug': DEBUG=1 else: REQUEST=arg return REQUEST # START POINT: if __name__ == "__main__": main()