def parseWords(self, string): #return(result(bool), complete(bool), value) if string == 'clear': return self.doClear() if self.curAttr: return self.doParseAttr(string) complete = False args = mysplit(string) for i in range(len(args)): if i % 2 == 0: if not self.doParseName(args[i]): print args[i] + ' name is error!' return (False, complete, None) else: (result, complete, data) = self.curAttr.parse(args[i]) if not result: print("%s not valid!" % args[i]) self.curAttr = None return (False, complete, None) self.data[self.curAttr.getName()] = data self.curAttr = None if self.curAttr and not self.curAttr.hasSubMode(): self.curAttr = None return (True, complete, self.data)
def tabSelf(self, text, line): if self.curAttr: return self.curAttr.tabSelf(text, line) args = mysplit(line) count = len(args) completions = [] (tabName, nameIdx) = self.isTabName(args, text) if tabName: completions = [ f for f in self.attrNames if f.startswith(text)] else: attr = self.makeAttr(args[nameIdx]) if attr: newLine = '' if nameIdx == -1 else args[-1] completions = attr.tabInContext(text, newLine) # if not text: # if count % 2 == 0: # completions = [ f for f in self.attrNames] # else: # attrName = args[-1] # attr = self.makeAttr(attrName) # if attr: # completions = attr.tabInContext(text, '') # else: # if count % 2 == 0: # attrName = args[-2] # attr = self.makeAttr(attrName) # if attr: # completions = attr.tabInContext(text, args[-1]) # else: # completions = [ f for f in self.attrNames if f.startswith(text)] return completions
def __init__(self, cookie = '/', transId = TransId(), line = '', lastWord = '', runNow = True): self.cookie = cookie self.transId = transId self.line = line self.lastWord = lastWord self.args = utils.mysplit(line) self.runNow = runNow
def tab_sub(self, text, line, begidx, endidx): completions = [] if line and line != text: args = mysplit(line) self.subCmd, line = self.__parseSubcmd(args[0], ' '.join(args[1:]), text) if self.subCmd != None: return self.subCmd.tab(text, line, begidx, endidx) commands = [cmd for cmd in self.commands] if not text: completions = commands else: completions = [f for f in commands if f.startswith(text)] return completions
def verify(self, value): value = str(value) if not value.startswith('[') or not value.endswith(']'): print 'SyntaxError: invalid syntax, must be list' return False value = value[1:-1].strip() ivalue = mysplit(value, ',') # try: # ivalue = eval(value) # except: # print 'eval %s error' % value # return False # if not isinstance(ivalue, list): # print 'expect a list' # return False if 'maxItems' in self.meta and len(ivalue) > int(self.meta['maxItems']): print 'length of list should be less than %s' % (int(self.meta['maxItems']) + 1) return False for i in ivalue: if not self.checkItemType(i) or not self.item.verify(str(i)): return False return True
def do_sub(self, line, terminal=False): args = mysplit(line) cmd = args[0] if cmd not in self.commands: print '%s is not in sub commands %s' % (cmd, self.commands) return None try: func = getattr(self, 'do_' + cmd) return func(' '.join(args[1:])) except AttributeError: args = args[1:] lastWord = args[-1] if args else '' context = CommandContext(self.cookie, self.transId, ' '.join(args), lastWord, runNow=True) self.subCmd = factory.create(cmd, context) if self.subCmd: return self.doSubLoop(line, terminal) else: print "create sub command %s fail" % cmd return None
def evalue(self, value): value = value[1:-1].strip() ivalue = mysplit(value, ',') import copy return map(lambda x: copy.deepcopy(self.item).evalue(str(x)), ivalue)