def __saveResult(self): ''' save the error information. ''' if DEBUG: print "[EXEC] %s.%s" % (self.__class__.__name__, self.__tools.getCurrentFunctionName()) self.__csvFile = CsvFile() self.__csvFile.write(CONFIG_FILE, self.__brokenApk)
class ApkFile(object): ''' The APK files operation class. ''' def __init__(self): ''' Constructor ''' self.__tools = Tools() self.__rootDirPath = None self.__csvFile = None self.__apkFileInfo = [] self.__subApkFileInfo = [] self.__brokenApk = [] self.__androidPackage = AndroidPackage() self.__operator = [self.__androidPackage.getPackageName, self.__androidPackage.getActivity, self.__androidPackage.getVersionName, self.__androidPackage.getName] def __getDirPathAndFileNames(self, path): ''' get the apk file name and its dir path. ''' if DEBUG: print "[EXEC] %s.%s" % (self.__class__.__name__, self.__tools.getCurrentFunctionName()) for tempTuple in os.walk(path): for tempStr in tempTuple[FILE_NAMES]: if tempStr.endswith(APK_FILE_NAME_SUFFIX): tempList = [[tempStr, BLACK_STATUS], [tempTuple[DIR_PATH], BLACK_STATUS]] self.__subApkFileInfo.append(tempList) if DEBUG: print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" for r in range(len(self.__subApkFileInfo)): for c in range(len(self.__subApkFileInfo[r])): print self.__subApkFileInfo[r][c] print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" def __getApkInfo(self, path, row): ''' get all package info of the apk from the apk file. ''' if DEBUG: print "[EXEC] %s.%s" % (self.__class__.__name__, self.__tools.getCurrentFunctionName()) for tempList in self.__operator: tempStr = tempList(path) if tempStr.upper().find(FAILURE_IDENTIFIER) >= 0: tempSubList = [tempStr, FAILURE_STATUS] else: tempSubList = [tempStr, SUCCESS_STATUS] row.append(tempSubList) if DEBUG: print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" for r in row: print r print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" def __saveResult(self): ''' save the error information. ''' if DEBUG: print "[EXEC] %s.%s" % (self.__class__.__name__, self.__tools.getCurrentFunctionName()) self.__csvFile = CsvFile() self.__csvFile.write(CONFIG_FILE, self.__brokenApk) def exportApkInfo(self, path, taskQueue, nonTaskQueue): ''' export APK information to the csv file. ''' if DEBUG: print "[EXEC] %s.%s" % (self.__class__.__name__, self.__tools.getCurrentFunctionName()) self.__getDirPathAndFileNames(path) for row in self.__subApkFileInfo: self.__getApkInfo(os.path.join(row[APK_FILE_PATH][VALUE], row[APK_FILE_NAME][VALUE]), row) isSuccessful = True for tempList in row: if ''.join(tempList).upper().find(FAILURE_IDENTIFIER) >= 0: isSuccessful = False nonTaskQueue.put(row, True) break if isSuccessful: taskQueue.put(row, True) sleep(0.1)