def saveNameToMap(tmp_path, imgPreFix): global sourceMap imageName = tmp_path.split('/')[-1].split('.')[0] newImgName = imgPreFix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() sourceMap[imageName] = newImgName return (imageName, newImgName)
def getFunNameMap(line, funNamePrefix): global _sysFun line = line.replace('\n', '').replace(': (', ':(').replace('*) ', '*)') line = line.lstrip() funName = None line_new = line.replace(' ', '') if line_new.startswith('+(') or line_new.startswith('-('): fun_list = getFunList(line) start_index = line.find(')') + 1 end_index = line.find(';') if ':(' in line: end_index = line.find(':(') + 1 funName = fun_list[0] if not igFil.isIgnoreFun(funName): repName = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() + 'Fun' if ':' in funName: repName += ':' if len(fun_list) > 1: funName = ':'.join(fun_list) repName = funName.replace(fun_list[0], repName) repName = funNamePrefix + repName if funName in _sysFun: return return {funName: repName} else: return
def searchXcodeprojPath(file_dir): global _createFilePath global _createFolderCode global _createFolderName global _createFolderUDID global _projectPbxprojPath fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if tmp_path.endswith('.xcodeproj'): if '/Pods/' not in tmp_path: _createFolderName = zfjTools.getWordFromLexicon().capitalize( ) + zfjTools.getWordFromLexicon().capitalize() tmp_path_list = tmp_path.split('/') tmp_path_list[-1] = _createFolderName _createFilePath = '/'.join(tmp_path_list) if not os.path.exists(_createFilePath): os.makedirs(_createFilePath) _createFolderUDID = addRandomCode.getMyUIID() _createFolderCode = _createFolderUDID + ' /* ' + _createFolderName + ' */,' if tmp_path.endswith('project.pbxproj'): if '/Pods/' not in tmp_path: _projectPbxprojPath = tmp_path if _createFilePath != None: if _projectPbxprojPath != None: break if not os.path.isdir(tmp_path): continue searchXcodeprojPath(tmp_path)
def getHeadCode(objectName): headCode = '//\n' headCode += '// ' + objectName + '\n' headCode += '// ' + zfjTools.getWordFromLexicon().upper() + '\n' headCode += '//\n' headCode += '// Created by ' + zfjTools.getWordFromLexicon().upper( ) + ' on ' + zfjTools.getTimeStr() + '.\n' headCode += '// Copyright 2019 ' + zfjTools.getWordFromLexicon().upper( ) + '. All rights reserved.\n' headCode += '//\n\n\n' return headCode
def getNewRubbishCode(oldRubCode, choseMap): replaceCode = '' if len(choseMap) >= 1: index = random.randint(0, len(choseMap.keys()) - 1) objName = list(choseMap.keys())[index] newProName = zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize( ) + objName[:3].capitalize() replaceCode += objName + ' *' + newProName + ' = [[' + objName + ' alloc] init];' + '\n' replaceCode += ' [' + newProName + ' ' + choseMap[ objName] + '];' + '\n' oldRubCode = oldRubCode.replace('//ZFJ_OTHER', replaceCode) else: replaceCode = oldRubCode return oldRubCode + '\n'
def getPropertyNameTup(line, propertyPrefix): line = line.replace('\n', '').strip() line = line[:line.find(';')] if '@property' in line: propertyName = None newLine = ''.join(line.split()) if '(^' in newLine: propertyName = newLine[newLine.find('(^') + 2:newLine.find(')(')] else: propertyName = line.split()[-1].replace('*', '').replace(')', '') if len(propertyPrefix) > 0: propertyMissName = propertyPrefix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() else: propertyMissName = zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() return (propertyName, propertyMissName) else: return
def confusionAt_Swift_Obj(file_path, funNamePrefix): global method_list_map object_name = file_path.split('/')[-1].split('.')[0] method_list = [] bracketsCount = 0 file_data = '' Ropen = open(file_path, 'r') for line in Ropen: if bracketsCount == 1: if 'func ' in line: pass if '{' in line: if 'override' not in line: funcName = line[line.find('func ') + 5:line.find('{')].replace('_ ', '').replace(' ', '') main_funcName = funcName[:funcName.find('(')] if main_funcName not in _sysFun: parameter = funcName[funcName.find('(') + 1:funcName.find(')')] missFunName = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() + 'Fun' funcName = main_funcName if len(parameter) > 0: funcName += '(' for item in parameter.split(','): funcName += item.split(':')[0] if parameter.split(',').index(item) != len(parameter.split(',')) - 1: funcName += ',' funcName += ')' line = line.replace(main_funcName, missFunName) missFunName = funcName.replace(main_funcName, missFunName) method_list.append({funcName: missFunName}) if '{' in line: bracketsCount += 1 else: if '}' in line: bracketsCount -= 1 file_data += line if len(method_list) > 0: method_list_map[object_name] = method_list Ropen.close() Wopen = open(file_path, 'w') Wopen.write(file_data) Wopen.close()
def getUILabel(): line = '- (UILabel *)' + getRandomRubFunName('UILabel') + '{\n' labelName = zfjTools.getWordFromLexicon() + 'Label' line += ' UILabel *' + labelName + ' = [[UILabel alloc] init];' + '\n' line += ' ' + labelName + '.frame = CGRectMake(' + str(getRandomNum(0, 300)) + ', ' + str(getRandomNum(0, 300)) + ', ' + str(getRandomNum(0, 300)) + ', ' + str(getRandomNum(0, 300)) + ');' + '\n' line += ' ' + labelName + '.backgroundColor = [UIColor groupTableViewBackgroundColor];' + '\n' line += ' ' + labelName + '.text = @"' + getRandomStr(15, 40) + '";' + '\n' line += ' ' + labelName + '.font = [UIFont systemFontOfSize:16];' + '\n' line += ' ' + labelName + '.textColor = [UIColor blackColor];' + '\n' line += ' ' + labelName + '.numberOfLines = ' + str(getRandomNum(0, 12)) + ';' + '\n' line += ' return ' + labelName + ';' + '\n}' + '\n\n' return line
def getRandomRubFunName(className): if className in ('NSString', 'NSArray', 'NSDictionary'): return 'get' + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() + className[2:] if className in ('UILabel', 'UIView'): return 'create' + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() + className[2:] if className in ('void', ): return zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() + 'Function'
def getPropertyNameAtSwiftAndMiss(file_path, propertyPrefix): global propertyMisMap file_data = '' object_name = file_path.split('/')[-1].split('.')[0] partMap = {} bracketsCount = 0 Ropen = open(file_path, 'r') for line in Ropen: propertyName = '' if 'var ' in line or 'let ' in line: if bracketsCount == 1: startIndex = line.find( 'var ') + 4 if 'var ' in line else line.find('let ') + 4 endIndex = line.find('=') if '=' in line else line.find(':') propertyName = ''.join(line[startIndex:endIndex].split()) if ':' in propertyName: propertyName = propertyName[:propertyName.find(':')] propertyMissName = propertyPrefix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() partMap[propertyName] = propertyMissName line = line.replace(propertyName, propertyMissName) if '{' in line: bracketsCount += 1 else: if '}' in line: bracketsCount -= 1 for propertyName in list(partMap.keys()): if propertyName in line: line = replaceForSwift(True, propertyName, partMap[propertyName], line) file_data += line if len(partMap.keys()) > 0: propertyMisMap[object_name] = partMap Ropen.close() Wopen = open(file_path, 'w') Wopen.write(file_data) Wopen.close()
def getMissObjName(old_objName): title_str = zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() if old_objName.endswith('View') or old_objName.endswith('view'): return title_str + 'View' elif old_objName.endswith('Controller') or old_objName.endswith('controller') or old_objName.endswith('Controll') or old_objName.endswith('controll') or old_objName.endswith('Control') or old_objName.endswith('control'): return title_str + 'Controller' elif old_objName.endswith('Cell') or old_objName.endswith('cell'): return title_str + 'Cell' elif old_objName.endswith('Model') or old_objName.endswith('model'): return title_str + 'Model' elif 'Tool' in old_objName or 'tool' in old_objName: return title_str + 'Tools' elif old_objName.endswith('Label') or old_objName.endswith('label'): return title_str + 'Label' elif old_objName.endswith('Button') or old_objName.endswith('button') or old_objName.endswith('Btn') or old_objName.endswith('btn'): return title_str + 'Button' elif old_objName.endswith('Manager') or old_objName.endswith('manager'): return title_str + 'Manager' elif old_objName.endswith('Handler') or old_objName.endswith('handler'): return title_str + 'Handler' elif old_objName.endswith('Operation') or old_objName.endswith('operation'): return title_str + 'Operation' else: return title_str + 'Obj'
def getMyProjectName(file_dir): global _projectNameTup fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if os.path.isdir(tmp_path): if not igFil.isIgnoreFiles(tmp_path): if tmp_path.endswith('.xcodeproj'): _projectName = tmp_path.split('/')[-1].split('.')[0] personinfo = ZFJPersoninfo() projectNamePreFix = personinfo.prefixMap['projectNamePreFix'] if len(projectNamePreFix) == 0: projectNamePreFix = zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() _projectNameTup = (_projectName, projectNamePreFix) break else: getMyProjectName(tmp_path)
def PBXGroupOneRow(row): global PBXGroupMap global _folderPreFix UDID = '' name = '' missName = '' isa = '' children = '' childrenNames = '' path = '' sourceTree = '' row = row.replace('\n', '').split() row = ''.join(row) UDID_Name = row[:row.find('=')] if '/*' in UDID_Name: if '*/' in UDID_Name: UDID = UDID_Name[:UDID_Name.find('/*')] name = UDID_Name[UDID_Name.find('/*') + 2:UDID_Name.find('*/')] UDID = UDID_Name if len(name) > 0: value_arr = row[row.find('={') + 2:row.find('};')].split(';') for value in value_arr: if 'isa=' in value: isa = value.split('isa=')[-1] elif 'children=' in value: children = value.split('children=')[-1][1:-2] children_name_list = [] for item in children.split(','): children_name = item[item.find('/*') + 2:item.find('*/')] children_name_list.append(children_name) childrenNames = ','.join(children_name_list) elif 'path=' in value: path = value.split('path=')[-1] elif 'sourceTree=' in value: sourceTree = value.split('sourceTree=')[-1] lower_name = name.lower() else: return if 'view' in lower_name: missName = zfjTools.getWordFromLexicon().capitalize() + 'Views' else: if 'control' in lower_name: missName = zfjTools.getWordFromLexicon().capitalize( ) + 'Controllers' else: if 'cell' in lower_name: missName = zfjTools.getWordFromLexicon().capitalize() + 'Cells' else: if 'model' in lower_name: missName = zfjTools.getWordFromLexicon().capitalize( ) + 'Models' else: if 'tool' in lower_name: missName = zfjTools.getWordFromLexicon().capitalize( ) + 'Tools' else: if 'label' in lower_name: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Labels' else: if 'vendor' in lower_name: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Vendor' else: if 'resources' in lower_name: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Resources' else: if 'util' in lower_name: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Util' else: if 'category' in lower_name: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Category' else: missName = zfjTools.getWordFromLexicon( ).capitalize() + 'Folder' missName = _folderPreFix + missName part_map = {} part_map['UDID'] = UDID part_map['name'] = name part_map['missName'] = missName part_map['isa'] = isa part_map['children'] = children part_map['path'] = path part_map['sourceTree'] = sourceTree PBXGroupMap[childrenNames] = part_map
def getRubbishFun(rubPrefix=''): global _choseMap global funHeadList createObjList = [] index = random.randint(0, len(funHeadList) - 1) funHeadName = funHeadList[index] funHeadType = funHeadName if index <= 4 else funHeadName + ' *' funCode = '- (' + funHeadType + ')' + rubPrefix + zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() parameterList = [] for x in range(0, random.randint(1, 4)): indexPra = random.randint(1, len(funHeadList) - 1) praObjName = funHeadList[indexPra] praType = praObjName if indexPra <= 4 else praObjName + ' *' if praObjName not in createObjList: createObjList.append(praObjName) praName = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() if x == 0: funCode += ':(' + praType + ')' + praName + ' ' else: funCode += praName + ':(' + praType + ')' + praName + ' ' praType = praType.strip() parameterList.append(praType + '==' + praName) funCode = funCode.strip() funCode += '{\n\n' isAddNSDate = False for item in parameterList: notesStr = '//' + zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() praType = item.split('==')[-1] if item.startswith('UI'): if 'UIFont' not in item: pass if 'UIColor' not in item: if 'UIImage' not in item: if 'UIViewController' not in item: funCode += ' if(' + praType + ' != nil){' + '\n' funCode += ' ' + praType + '.backgroundColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1];\n' funCode += ' }\n' if item.startswith('UI'): if 'UIViewController' in item: funCode += ' ' + praType + '.title = @"' + zfjTools.getWordFromLexicon().capitalize() + '";\n' if item.startswith('NS'): if 'NSInteger' not in item: if isAddNSDate == False: isAddNSDate = True zfjDate = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() aTimeInteger = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() funCode += ' NSDate *' + zfjDate + ' = [NSDate dateWithTimeIntervalSinceNow:0];\n' funCode += ' NSInteger ' + aTimeInteger + ' = [' + zfjDate + ' timeIntervalSince1970];\n\n' funCode += ' if (' + praType + '.hash != ' + aTimeInteger + '){\n' funCode += ' ' + notesStr + '\n' if 'NSString' in item: funCode += ' ' + praType + ' = [NSString stringWithFormat:@"%ld",' + aTimeInteger + '];\n' else: funCode += ' ' + praType + ' = nil;\n' funCode += ' }else{\n' if 'NSDictionary' in item: funCode += ' [' + praType + ' setValue:@"' + zfjTools.getWordFromLexicon() + '" forKey:@"' + zfjTools.getWordFromLexicon() + '"];\n' funCode += ' NSLog(@"' + praType + '.hash != %ld",' + praType + '.hash);\n' funCode += ' }\n' if item.startswith('NS'): if 'NSInteger' in item: funCode += ' ' + praType + ' = ' + str(random.randint(30, 500)) + ';\n' funCode += '\n' funCode += ' //ZFJ_OTHER\n' if len(_choseMap) >= 1: index = random.randint(0, len(_choseMap.keys()) - 1) objName = list(_choseMap.keys())[index] newProName = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() + objName[:3].capitalize() funCode += ' ' + objName + ' *' + newProName + ' = [[' + objName + ' alloc] init];' + '\n' funCode += ' [' + newProName + ' ' + _choseMap[objName] + '];' + '\n' funCode += '\n' returnName = zfjTools.getWordFromLexicon() + funHeadName[2:] if 'void' not in funHeadType: pass if '*' in funHeadType: if 'UICollectionView' != funHeadName: funCode += ' ' + funHeadName + ' *' + returnName + ' = [[' + funHeadName + ' ' + 'alloc] init];' + '\n' funCode += ' return ' + returnName + ';\n' if 'void' not in funHeadType: pass if '*' in funHeadType: if 'UICollectionView' == funHeadName: flowLayoutName = zfjTools.getWordFromLexicon() funCode += ' UICollectionViewFlowLayout *' + flowLayoutName + ' = [[UICollectionViewFlowLayout alloc] init];\n' funCode += ' ' + flowLayoutName + '.itemSize = CGSizeMake(' + str(random.randint(0, 300)) + ', ' + str(random.randint(0, 300)) + ');\n' funCode += ' ' + flowLayoutName + '.minimumInteritemSpacing = ' + str(random.randint(1, 30)) + ';\n' funCode += ' ' + flowLayoutName + '.minimumLineSpacing = ' + str(random.randint(1, 30)) + ';\n' funCode += ' ' + flowLayoutName + '.scrollDirection = UICollectionViewScrollDirectionVertical;\n\n' funCode += ' ' + funHeadName + ' *' + returnName + ' = [[' + funHeadName + ' ' + 'alloc] initWithFrame:CGRectMake(' + str(random.randint(0, 300)) + ', ' + str(random.randint(0, 300)) + ', ' + str(random.randint(0, 300)) + ', ' + str(random.randint(0, 300)) + ') collectionViewLayout:' + flowLayoutName + '];' + '\n' funCode += ' return ' + returnName + ';\n' if 'BOOL' in funHeadType: parameterListPart = parameterList[random.randint(0, len(parameterList) - 1)] if '*' not in parameterListPart: funCode += ' ' + funHeadName + ' ' + returnName + ' = arc4random_uniform(100)%2 == 0 ? YES : NO;' + '\n' funCode += ' return ' + returnName + ';\n' else: par_name = parameterListPart.split('==')[-1] funCode += ' if(' + par_name + ' == nil){\n' funCode += ' return NO;\n' funCode += ' }else{\n' funCode += ' return YES;\n' funCode += ' }\n' else: if 'CGFloat' in funHeadType or 'NSInteger' in funHeadType: funCode += ' ' + funHeadName + ' ' + returnName + ' = arc4random_uniform(100);' + '\n' funCode += ' return ' + returnName + ';\n' else: if 'CGRect' in funHeadType: x = random.randint(0, 200) y = random.randint(0, 200) width = random.randint(0, 200) height = random.randint(0, 200) funCode += ' ' + funHeadName + ' ' + returnName + ' = CGRectMake(' + str(x) + ', ' + str(y) + ', ' + str(width) + ', ' + str(height) + ');\n' funCode += ' return ' + returnName + ';\n' funCode += '}\n\n' return (funCode, createObjList)
def searchXcassets(file_dir, imgPreFix): global sourceTypeMap global xcassetsMap fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if os.path.isdir(tmp_path): pass if tmp_path.endswith('.imageset'): try: if not igFil.isIgnoreFiles(tmp_path): imgArr = saveNameToMap(tmp_path, imgPreFix) new_path = tmp_path.replace(imgArr[0] + '.imageset', imgArr[1] + '.imageset') if tmp_path != new_path: os.rename(tmp_path, new_path) conLog.info('[SeaXcas Scu] ' + tmp_path) searchXcassets(new_path, imgPreFix) except Exception as e: try: conLog.error('[SeaXcas Fail] ' + str(e)) searchXcassets(tmp_path, imgPreFix) finally: e = None del e elif not os.path.isdir(tmp_path): if '.xcassets' in tmp_path: if isImage(tmp_path): imageType = '.' + tmp_path.split('.')[-1] fatherPath = '/'.join(tmp_path.split('/')[:-1]) imageName = tmp_path.split('/')[-1].split('.')[0] newImgName = imgPreFix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() new_path = tmp_path.replace('/' + imageName + imageType, '/' + newImgName + imageType) os.rename(tmp_path, new_path) partMap = {} if fatherPath in xcassetsMap.keys(): partMap = xcassetsMap[fatherPath] partMap[imageName] = newImgName xcassetsMap[fatherPath] = partMap elif not os.path.isdir(tmp_path): if isNeedMissImg(tmp_path): if not igFil.isIgnoreFiles(tmp_path): imageName = tmp_path.strip().split('/')[-1] imageType = '' if '@' in imageName: nameList = imageName.split('@') imageName = nameList[0] imageType = '@' + nameList[-1] else: nameList = imageName.split('.') imageName = nameList[0] imageType = '.' + nameList[-1] if imageName not in sourceMap.keys(): newImgName = imgPreFix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() sourceMap[imageName] = newImgName else: newImgName = sourceMap[imageName] if imageName in sourceTypeMap.keys(): old_imageType = sourceTypeMap[imageName] if old_imageType != imageType: old_imageType += ',' + imageType sourceTypeMap[imageName] = old_imageType else: sourceTypeMap[imageName] = imageType new_path = tmp_path.replace(imageName, newImgName) os.rename(tmp_path, new_path) conLog.info('[SeaXcas Scu] ' + tmp_path) else: if os.path.isdir(tmp_path): searchXcassets(tmp_path, imgPreFix)
def createOCFile(filePath, amount=5, rubPrefix=''): global _PBXBuildFileList global _PBXFileReferenceCodeList global _PBXSourcesBuildPhaseList global _createFolderchildrenList global _importList global _sportObjList rubCodeTuple = addRandomCode.addRandomClass(amount, rubPrefix) index = random.randint(0, 2) objClass = _sportObjList[index] importName = _importList[index] objectName = addRandomCode.getMissObjName(objClass) h_filePath = filePath + '/' + objectName + '.h' m_filePath = filePath + '/' + objectName + '.m' hFileCode = getHeadCode(objectName + '.h') hFileCode += importName + '\n\n' hFileCode += '@interface ' + objectName + ' : ' + objClass + '\n' hFileCode += '\n' hFileCode += rubCodeTuple[0] hFileCode += '\n' hFileCode += '@end\n' Wopen = open(h_filePath, 'w') Wopen.write(hFileCode) Wopen.close() conLog.info('[CreateRubFile OK] ' + h_filePath) h_file_udid = addRandomCode.getMyUIID() h_file_code = h_file_udid + ' /* ' + objectName + '.h' + ' */,' _createFolderchildrenList.append(h_file_code) h_PBXFileRef_code = h_file_udid + ' /* ' + objectName + '.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ' + objectName + '.h; sourceTree = "<group>"; };' + '\n' _PBXFileReferenceCodeList.append(h_PBXFileRef_code) mFileCode = getHeadCode(objectName + '.m') mFileCode += '#import "' + objectName + '.h"\n' choseMap = {} if len(_createFileMap.keys()) > 3: random.seed(len(_createFileMap.keys())) keyList = random.sample(list(_createFileMap.keys()), 3) for key in keyList: choseMap[key] = _createFileMap[key] else: choseMap = _createFileMap createProMap = {} for objClassName in choseMap: mFileCode += '#import "' + objClassName + '.h"\n' createProMap[objClassName] = zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize( ) + objClassName[:3].capitalize() mFileCode += '\n' mFileCode += '@interface ' + objectName + ' ()\n\n' for proObjName in createProMap: mFileCode += '@property(nonatomic,strong) ' + proObjName + ' *' + createProMap[ proObjName] + ';' + '\n' interfaceProFunName = '' if len(createProMap) > 0: mFileCode += '\n' interfaceProFunName = zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() + 'Fun' mFileCode += '@end\n\n' mFileCode += '@implementation ' + objectName + '\n\n' if objClass == 'UIViewController': mFileCode += '- (void)viewDidLoad {\n' mFileCode += ' [super viewDidLoad];\n' mFileCode += ' // Do any additional setup after loading the view from its nib.\n' for key in rubCodeTuple[3]: mFileCode += ' [self ' + rubCodeTuple[3][key] + '];' + '\n' if len(interfaceProFunName) > 0: mFileCode += ' [self ' + interfaceProFunName + '];' + '\n' mFileCode += '}\n\n' else: mFileCode += createInitFun(rubCodeTuple[3], interfaceProFunName) if len(interfaceProFunName) > 0: mFileCode += realizePropertyRubClass(createProMap, interfaceProFunName) mFileCode += getNewRubbishCode(rubCodeTuple[1], choseMap) mFileCode += '@end\n' Wopen = open(m_filePath, 'w') Wopen.write(mFileCode) Wopen.close() conLog.info('[CreateRubFile OK] ' + m_filePath) m_file_udid = addRandomCode.getMyUIID() m_file_udid_1 = addRandomCode.getMyUIID() m_file_code = m_file_udid + ' /* ' + objectName + '.m' + ' */,' _createFolderchildrenList.append(m_file_code) m_PBXFileRef_code = m_file_udid + ' /* ' + objectName + '.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ' + objectName + '.m; sourceTree = "<group>"; };' + '\n' _PBXFileReferenceCodeList.append(m_PBXFileRef_code) m_PBXSources_code = m_file_udid_1 + ' /* ' + objectName + '.m in Sources */,' + '\n' _PBXSourcesBuildPhaseList.append(m_PBXSources_code) m_PBXBuildFile_code = m_file_udid_1 + ' /* ' + objectName + '.m in Sources */ = {isa = PBXBuildFile; fileRef = ' + m_file_udid + ' /* ' + objectName + '.m */; };' + '\n' _PBXBuildFileList.append(m_PBXBuildFile_code) _createFileMap[objectName] = rubCodeTuple[2]
def addRandomClass(amount=1, rubPrefix=''): global assignList global copyList funNameMap = {} rubFunCode = '' interfaceRubProCode = '' rubbishProMap = {} createObjList = [] importCode = getImportCode() for x in range(amount): rubbishTuple = getRubbishFun(rubPrefix) funName = rubbishTuple[0] createObjList.extend(rubbishTuple[1]) funName_0 = funName[:funName.find('{')] + ';' funName_1 = funName[funName.find(')') + 1:funName.find('{')] rubFunCode += funName funNameMap[funName_0] = funName_1 interfaceRubProCode += '\n//Start\n' for objName in createObjList: rubbishProName = zfjTools.getWordFromLexicon() + zfjTools.getWordFromLexicon().capitalize() propertyTypeWord = ' copy' asterisk = ' *' if objName in assignList: propertyTypeWord = 'assign' asterisk = ' ' else: if objName in copyList: propertyTypeWord = ' copy' asterisk = ' *' else: if objName not in assignList: if objName not in copyList: propertyTypeWord = 'strong' asterisk = ' *' interfaceRubProCode += '\n@property(nonatomic,' + propertyTypeWord + ') ' + objName + asterisk + rubbishProName + ';\n' rubbishProMap[objName] = rubbishProName interfaceRubProCode += '\n//End\n' interfaceRubProCode += '\n\n//Start\n\n' callProCode_FFile = interfaceRubProCode for funKey in funNameMap: callProCode_FFile += funKey + '\n' callFunName = funNameMap[funKey] new_callFunName = '' callFunNameList = callFunName.split(':') for index in range(0, len(callFunNameList)): callFunNameListItem = callFunNameList[index] if '(' in callFunNameListItem: if ')' in callFunNameListItem: objName = callFunNameListItem.strip().replace('(', '') objName = objName[:objName.find(')')].replace('*', '').strip() rubbishProName = rubbishProMap[objName] new_callFunNameListItem = '_' + rubbishProName if ' ' in callFunNameListItem: secondPra = callFunNameListItem.split(' ')[-1] if '*' not in secondPra: new_callFunNameListItem += ' ' + secondPra callFunNameList[index] = new_callFunNameListItem new_callFunName = ':'.join(callFunNameList) funNameMap[funKey] = new_callFunName masterFunName = rubPrefix + 'master' + zfjTools.getWordFromLexicon().capitalize() + zfjTools.getWordFromLexicon().capitalize() rubFunCode += '- (void)' + masterFunName + '{\n' for key in funNameMap: rubFunCode += ' [self ' + funNameMap[key] + '];' + '\n' rubFunCode += '}\n' callProCode_FFile += '\n- (void)' + masterFunName + ';\n' callProCode_FFile += '\n//End\n\n' return ( callProCode_FFile, rubFunCode, masterFunName, funNameMap, importCode)