def extractSystemImage(archive, folder): try: ImageFilename = 'system.img' if not os.access(folder, os.W_OK): print "No access to destination folder" return None Package = tarfile.open(archive) buildName = re.sub(".tar.*$", '', re.sub('^fastboot-','', os.path.basename(Package.name))) #cut-off 'fastboot' world an extension to obtain package name systemRegexp = re.compile(".*" + ImageFilename + "$") systemImageArchivePathList = filter(systemRegexp.match, Package.getnames()) if len(systemImageArchivePathList)!=1: print "Too much system.img in " + Package.name return None if not buildName: buildName = dummy extractTo = folder + buildName + '/' os.mkdir(extractTo) print 'extracting ' + systemImageArchivePathList[0] + '\nfrom ' + archive Package.extract(systemImageArchivePathList[0], extractTo) return linux_like_find(extractTo, ImageFilename) except: print "Exception when were extracting" return None
def findNewestBuild(folder, template): #the addCTimeKey function in the next line is expected to return list of it's argument and hash-key (i.g. ctime) [x, hash(x)] FindedList = sorted([addCTimeKey(x) for x in linux_like_find (folder, template)], key=itemgetter(1), reverse=True) # print FindedList return FindedList[0][0]