def getPymelEnums(self, enumDict): """remove all common prefixes from list of enum values""" if len(enumDict) > 1: enumList = enumDict.keys() splitEnums = [ [ y for y in re.split( '([A-Z0-9][a-z0-9]*)', x ) if y ] for x in enumList ] splitEnumsCopy = splitEnums[:] for partList in zip( *splitEnumsCopy ): if tuple([partList[0]]*len(partList)) == partList: [ x.pop(0) for x in splitEnums ] else: break joinedEnums = [ util.uncapitalize(''.join(x), preserveAcronymns=True ) for x in splitEnums] for i, enum in enumerate(joinedEnums): if _iskeyword(enum): joinedEnums[i] = enum+'_' self.xprint( "bad enum", enum ) elif enum[0].isdigit(): joinedEnums[i] = 'k' + enum self.xprint( "bad enum", enum ) #print joinedEnums #print enumList #break pymelEnumDict = dict( [ (k2,enumDict[k1]) for k1, k2 in zip( enumList, joinedEnums ) ] ) #print "enums", joinedEnums return pymelEnumDict return enumDict
def getPymelMethodNames(self): setReg = re.compile('set([A-Z].*)') allFnMembers = self.methods.keys() pymelNames = {} pairs = {} pairsList = [] def addSetGetPair(setmethod, getMethod): pairsList.append( (setMethod,getMethod) ) # pair 'set' with 'is/get' pairs[setMethod] = getMethod for info in self.methods[setMethod]: info['inverse'] = (getMethod, True) # pair 'is/get' with 'set' pairs[getMethod] = setMethod for info in self.methods[getMethod]: info['inverse'] = (setMethod, False) for member in allFnMembers: m = setReg.match(member) if m: # MFn api naming convention usually uses setValue(), value() convention for its set and get methods, respectively # setSomething() & something() becomes setSomething() & getSomething() # setIsSomething() & isSomething() becomes setSomething() & isSomething() basename = m.group(1) origGetMethod = util.uncapitalize(basename) setMethod = member # for name clarity if origGetMethod in allFnMembers: # fix set if re.match( 'is[A-Z].*', origGetMethod): newSetMethod = 'set' + origGetMethod[2:] # remove 'is' #member[5:] pymelNames[setMethod] = newSetMethod for info in self.methods[setMethod]: info['pymelName'] = newSetMethod addSetGetPair( setMethod, origGetMethod) # fix get else: newGetMethod = 'g' + setMethod[1:] # remove 's' pymelNames[origGetMethod] = newGetMethod for info in self.methods[origGetMethod]: info['pymelName'] = newGetMethod addSetGetPair( setMethod, origGetMethod) else: getMethod = 'get' + basename isMethod = 'is' + basename if getMethod in allFnMembers: addSetGetPair( setMethod, getMethod ) elif isMethod in allFnMembers: addSetGetPair( setMethod, isMethod ) return pymelNames, pairsList
def getPymelEnums(self, enumDict): """remove all common prefixes from list of enum values""" if len(enumDict) > 1: enumList = enumDict.keys() capitalizedRe = re.compile('([A-Z0-9][a-z0-9]*)') # We first aim to remove all similar 'camel-case-group' prefixes, ie: # if our enums look like: # kFooBar # kFooSomeThing # kFooBunnies # we want to get Bar, SomeThing, Bunnies # {'kFooBar':0, 'kFooSomeThing':1} # => [['k', 'Foo', 'Some', 'Thing'], ['k', 'Foo', 'Bar']] splitEnums = [[y for y in capitalizedRe.split(x) if y] for x in enumList] # [['k', 'Invalid'], ['k', 'Pre', 'Transform']] # => [('k', 'k'), ('Foo', 'Foo'), ('Some', 'Bar')] splitZip = zip(*splitEnums) for partList in splitZip: if tuple([partList[0]] * len(partList)) == partList: [x.pop(0) for x in splitEnums] else: break # splitEnums == [['Some', 'Thing'], ['Bar']] joinedEnums = [ util.uncapitalize(''.join(x), preserveAcronymns=True) for x in splitEnums ] for i, enum in enumerate(joinedEnums): if _iskeyword(enum): joinedEnums[i] = enum + '_' self.xprint("bad enum", enum) elif enum[0].isdigit(): joinedEnums[i] = 'k' + enum self.xprint("bad enum", enum) #print joinedEnums #print enumList #break pymelEnumDict = dict((new, enumDict[orig]) for orig, new in zip(enumList, joinedEnums)) #print "enums", joinedEnums return pymelEnumDict return enumDict
def getPymelEnums(self, enumDict): """remove all common prefixes from list of enum values""" if len(enumDict) > 1: enumList = enumDict.keys() capitalizedRe = re.compile('([A-Z0-9][a-z0-9]*)') # We first aim to remove all similar 'camel-case-group' prefixes, ie: # if our enums look like: # kFooBar # kFooSomeThing # kFooBunnies # we want to get Bar, SomeThing, Bunnies # {'kFooBar':0, 'kFooSomeThing':1} # => [['k', 'Foo', 'Some', 'Thing'], ['k', 'Foo', 'Bar']] splitEnums = [ [ y for y in capitalizedRe.split( x ) if y ] for x in enumList ] # [['k', 'Invalid'], ['k', 'Pre', 'Transform']] # => [('k', 'k'), ('Foo', 'Foo'), ('Some', 'Bar')] splitZip = zip( *splitEnums ) for partList in splitZip: if tuple([partList[0]]*len(partList)) == partList: [ x.pop(0) for x in splitEnums ] else: break # splitEnums == [['Some', 'Thing'], ['Bar']] joinedEnums = [ util.uncapitalize(''.join(x), preserveAcronymns=True ) for x in splitEnums] for i, enum in enumerate(joinedEnums): if _iskeyword(enum): joinedEnums[i] = enum+'_' self.xprint( "bad enum", enum ) elif enum[0].isdigit(): joinedEnums[i] = 'k' + enum self.xprint( "bad enum", enum ) #print joinedEnums #print enumList #break pymelEnumDict = dict( (new,enumDict[orig]) for orig, new in zip( enumList, joinedEnums ) ) #print "enums", joinedEnums return pymelEnumDict return enumDict
def _apiEnumNamesToPymelEnumNames(self, apiEnumNames): """remove all common prefixes from list of enum values""" if isinstance(apiEnumNames, util.Enum): apiEnumNames = apiEnumNames._keys.keys() if len(apiEnumNames) > 1: # We first aim to remove all similar 'camel-case-group' prefixes, ie: # if our enums look like: # kFooBar # kFooSomeThing # kFooBunnies # we want to get Bar, SomeThing, Bunnies # {'kFooBar':0, 'kFooSomeThing':1} # => [['k', 'Foo', 'Some', 'Thing'], ['k', 'Foo', 'Bar']] splitEnums = [ [ y for y in self._capitalizedRe.split( x ) if y ] for x in apiEnumNames ] # [['k', 'Invalid'], ['k', 'Pre', 'Transform']] # => [('k', 'k'), ('Foo', 'Foo'), ('Some', 'Bar')] splitZip = zip( *splitEnums ) for partList in splitZip: if tuple([partList[0]]*len(partList)) == partList: [ x.pop(0) for x in splitEnums ] else: break # splitEnums == [['Some', 'Thing'], ['Bar']] joinedEnums = [ util.uncapitalize(''.join(x), preserveAcronymns=True ) for x in splitEnums] for i, enum in enumerate(joinedEnums): if _iskeyword(enum): joinedEnums[i] = enum+'_' self.xprint( "bad enum", enum ) elif enum[0].isdigit(): joinedEnums[i] = 'k' + enum self.xprint( "bad enum", enum ) #print joinedEnums #print enumList #break return dict(zip(apiEnumNames, joinedEnums)) else: # if only 1 name or less, name is unaltered return dict((name, name) for name in apiEnumNames)
def getCmdInfoBasic( command ): typemap = { 'string' : unicode, 'length' : float, 'float' : float, 'angle' : float, 'int' : int, 'unsignedint' : int, 'on|off' : bool, 'script' : callable, 'name' : 'PyNode' } flags = {} shortFlags = {} removedFlags = {} try: lines = cmds.help( command ).split('\n') except RuntimeError: pass else: synopsis = lines.pop(0) # certain commands on certain platforms have an empty first line if not synopsis: synopsis = lines.pop(0) #_logger.debug(synopsis) if lines: lines.pop(0) # 'Flags' #_logger.debug(lines) for line in lines: line = line.replace( '(Query Arg Mandatory)', '' ) line = line.replace( '(Query Arg Optional)', '' ) tokens = line.split() try: tokens.remove('(multi-use)') multiuse = True except ValueError: multiuse = False #_logger.debug(tokens) if len(tokens) > 1 and tokens[0].startswith('-'): args = [ typemap.get(x.lower(), util.uncapitalize(x) ) for x in tokens[2:] ] numArgs = len(args) # lags with no args in mel require a boolean val in python if numArgs == 0: args = bool # numArgs will stay at 0, which is the number of mel arguments. # this flag should be renamed to numMelArgs #numArgs = 1 elif numArgs == 1: args = args[0] longname = str(tokens[1][1:]) shortname = str(tokens[0][1:]) if longname in keyword.kwlist: removedFlags[ longname ] = shortname longname = shortname elif shortname in keyword.kwlist: removedFlags[ shortname ] = longname shortname = longname #sometimes the longname is empty, so we'll use the shortname for both elif longname == '': longname = shortname flags[longname] = { 'longname' : longname, 'shortname' : shortname, 'args' : args, 'numArgs' : numArgs, 'docstring' : '' } if multiuse: flags[longname].setdefault('modes', []).append('multiuse') shortFlags[shortname] = longname #except: # pass #_logger.debug("could not retrieve command info for", command) res = { 'flags': flags, 'shortFlags': shortFlags, 'description' : '', 'example': '', 'type' : 'other' } if removedFlags: res['removedFlags'] = removedFlags return res