def argTypeahead(output, sessionKey, namespace, user, bnf, search): try: commandAndArgs = utils.getLastCommand(search, None) if commandAndArgs != None: cmd, args = commandAndArgs typeahead = [] stanza = cmd + '-command' s = describer.cleanSyntax( describer.recurseSyntax( stanza, bnf, bnf[stanza], {}, True, 0, 1500)) # recurse syntax up to 1500 chars e = parser.getExp(s) tokens = {} hasFields = False parser.getTokens(e, tokens) getvalue = False for a, v in tokens.items(): if a == cmd: continue if a.startswith('<') and a.endswith( '>') and 'field' in a.lower() or v == '<field>': hasFields = True if args.endswith('='): args = args[:-1] getvalue = True b1, replacement, b2 = getReplacement(args, a) # only show keywords when we match because we have so low confidence about their correctness in any given spot of a search command if replacement != '': prev = len(replacement) + 1 if prev > len(args) or not args[-prev].isalpha(): #print "%s\t: %s ('%s')" % (a,v, replacement) if getvalue: if v == '<bool>': v = ['true', 'false'] a = v v = 'datatype' if isinstance(a, list): for val in a: typeahead.append((val, 'choice', replacement)) else: if isinstance(v, list): v = '<list>' typeahead.append((a, v, replacement)) output['has_field_args'] = hasFields output['arg_typeahead'] = typeahead except Exception, e: msg = str(e) + traceback.format_exc() output['notices'].insert(0, msg)
def getBNF(command, sessionKey, username, namespace): stanzas = utils.getStanzas("searchbnf", sessionKey, username, namespace) datatypes = utils.getStanzas("datatypesbnf", sessionKey, username, namespace) try: #print "stanzas:", stanzas.keys() stanza = stanzas[command+"-command"] except: # print "datatypes:", datatypes stanza = datatypes[command] datatypes = [] syntax = describer.recurseSyntax(command, stanzas, stanza, datatypes) printd("Original Syntax:" + str(stanza["syntax"])) printd("Recursed:" + syntax) return syntax
def argTypeahead(output, sessionKey, namespace, user, bnf, search): try: commandAndArgs = utils.getLastCommand(search, None) if commandAndArgs != None: cmd, args = commandAndArgs typeahead = [] stanza = cmd + '-command' s = describer.cleanSyntax(describer.recurseSyntax(stanza, bnf, bnf[stanza], {}, True, 0, 1500)) # recurse syntax up to 1500 chars e = parser.getExp(s) tokens = {} hasFields = False parser.getTokens(e, tokens) getvalue = False for a,v in tokens.items(): if a == cmd: continue if a.startswith('<') and a.endswith('>') and 'field' in a.lower() or v == '<field>': hasFields = True if args.endswith('='): args = args[:-1] getvalue = True b1, replacement, b2 = getReplacement(args, a) # only show keywords when we match because we have so low confidence about their correctness in any given spot of a search command if replacement != '': prev = len(replacement)+1 if prev > len(args) or not args[-prev].isalpha(): #print "%s\t: %s ('%s')" % (a,v, replacement) if getvalue: if v == '<bool>': v = ['true','false'] a = v v = 'datatype' if isinstance(a, list): for val in a: typeahead.append((val,'choice', replacement)) else: if isinstance(v, list): v = '<list>' typeahead.append((a,v, replacement)) output['has_field_args'] = hasFields output['arg_typeahead'] = typeahead except Exception, e: msg = str(e) + traceback.format_exc() output['notices'].insert(0,msg)
def getBNF(command, sessionKey, username, namespace): stanzas = utils.getStanzas("searchbnf", sessionKey, username, namespace) datatypes = utils.getStanzas("datatypesbnf", sessionKey, username, namespace) try: #print "stanzas:", stanzas.keys() stanza = stanzas[command + "-command"] except: # print "datatypes:", datatypes stanza = datatypes[command] datatypes = [] syntax = describer.recurseSyntax(command, stanzas, stanza, datatypes) printd("Original Syntax:" + str(stanza["syntax"])) printd("Recursed:" + syntax) return syntax