Script de exemplo

O seguinte script é fornecido como um exemplo do Plug-in Pesquisa de script. Ele é escrito em Python 2.6. A finalidade desse script é fornecer um exemplo de funcionamento básico para gravar scripts no Python que podem ser usados para os plug-ins Pesquisa de script.
Esse script contém a chave do parâmetro de pesquisa
date-sent
e retorna o "valor do script" para o atributo personalizado
Script-attribute
.
Como o Python é rígido em relação aos requisitos de recuo, se você copiar/colar este script do exemplo, provavelmente precisará reformatá-lo de modo que ele apareça exatamente como exibido aqui.
__name__="__main__" import sys, os, traceback import commands # Switch this to 0 when in production mode. debugMode = 1 def main(args): try: attributeMap = parseInput(args) # This is the lookup parameter key. # Comment-out this line for testing the script standalone. dateSent = attributeMap["date-sent"] # "Script-attribute" is the custom attribute. # "script value" is the return value. # You cannot have a space between the custom attribute and the # attribute value. For example, "Script-attribute = script value" # Does not work for Script Lookup Plugins. print "Script-attribute=script value" return except: error() print "something went wrong!" return "something went wrong!" def parseInput(args): # Input data is a list of key value pairs seperated by carraige return # Create a python dictionary to create the attribute map attributeMap = {} delimiter = "=" for item in args: if delimiter in item: tuple = item.split(delimiter) attributeMap[tuple[0]] = tuple[1] return attributeMap def error(): # "SCRIPT PROCESSING ERROR" if(debugMode): #print "Script Processing Error" traceback.print_exc(file=sys.stdout) return "" #----------------------------------------------------------------- # DOS-style shells (for DOS, NT, OS/2): #----------------------------------------------------------------- def getstatusoutput(cmd): """ Return (status, output) of executing cmd in a shell.""" pipe = os.popen(cmd + ' 2>&1', 'r') text = pipe.read() sts = pipe.close() if sts is None: sts = 0 if text[-1:] == '\n': text = text[:-1] return sts, text #----------------------------------------------------------------- # Entry Point #----------------------------------------------------------------- if __name__ == "__main__": if(len(sys.argv) == 0): error() else: main(sys.argv)