def extractFromFileAndCrc(self, crc, dest): if not gotLib7z: writeError("Sorry, You cannot use 7z file") return False writeInfo("Extract 7Z file") fp = open(self.file, "rb") archive = Archive7z(fp) for name in archive.getnames(): fd = archive.getmember(name) crcFd = getCRCFromBuffer(fd.read()) if crc == crcFd: writeInfo("On extracte un 7z %s" % file) fd.reset() data = fd.read() nameDest = os.path.basename(name) writeInfo("On extract du 7z " + nameDest) fdest = NamedTemporaryFile() # fdest = open("tmp" + "/" + nameDest, 'w+b', os.O_SYNC) fdest.write(data) fdest.flush() # fdest.close() print "Utilisation du fichier temporaire %s" % fdest.name # truncateRomFile("tmp" + "/" + nameDest, dest + "/" + nameDest) truncateRomFile(fdest.name, dest + "/" + nameDest) fdest.close() # os.remove("tmp" + "/" + nameDest) fp.close() writeInfo("Ecriture Finie")
def extractFromFileAndCrc(self, crc, dest): if not gotLib7z: writeError("Sorry, You cannot use 7z file") return False writeInfo("Extract 7Z file") fp = open(self.file, 'rb') archive = Archive7z(fp) for name in archive.getnames(): fd = archive.getmember(name) crcFd = getCRCFromBuffer(fd.read()) if crc == crcFd: writeInfo("On extracte un 7z %s" % file) fd.reset() data = fd.read() nameDest = os.path.basename(name) writeInfo("On extract du 7z " + nameDest) fdest = NamedTemporaryFile() #fdest = open("tmp" + "/" + nameDest, 'w+b', os.O_SYNC) fdest.write(data) fdest.flush() #fdest.close() print "Utilisation du fichier temporaire %s" % fdest.name #truncateRomFile("tmp" + "/" + nameDest, dest + "/" + nameDest) truncateRomFile(fdest.name, dest + "/" + nameDest) fdest.close() #os.remove("tmp" + "/" + nameDest) fp.close() writeInfo("Ecriture Finie")
def updateImgsOnlyNecessary(games, repDestination, configuration, imagesValidees,stoper): g = WebGrabber() for game in games: #rearde si j'ai le droit de fonctionner if stoper.isDoStop(): writeInfo("Je dois partir") return [] numberInt = int(game.imageNumber) numberString = game.imageNumber fileDestA = repDestination+"/"+numberString+"a.png" fileDestB = repDestination+"/"+numberString+"b.png" webURLA = configuration.newDat.imURL+getURL500(numberInt)+"/"+numberString+"a.png" webURLB = configuration.newDat.imURL+"/"+getURL500(numberInt)+"/"+numberString+"b.png" #on ne rescan pas les images si on a deja fait et que c'est bon if not imagesValidees.contientImage(repDestination+"/"+numberString+"a.png"): crcAreel = getCRC(repDestination+"/"+numberString+"a.png") else: crcAreel = game.im1CRC crcAattendu = game.im1CRC #pareil pour la b if not imagesValidees.contientImage(repDestination+"/"+numberString+"b.png"): crcBreel = getCRC(repDestination+"/"+numberString+"b.png") else: crcBreel = game.im2CRC crcBattendu = game.im2CRC #Si le fichier A a deja le bon CRC, on quitte if crcAreel == crcAattendu : imagesValidees.ajouterImage(repDestination+"/"+numberString+"a.png") else : #on get le fichier print webURLA, fileDestA g.getWebFile(webURLA,fileDestA) crcAreel = getCRC(repDestination+"/"+numberString+"a.png") if getCRC(repDestination+"/"+numberString+"a.png") == game.im1CRC : imagesValidees.ajouterImage(repDestination+"/"+numberString+"a.png") else : writeError("%s CRC ERROR!" % (numberString+"b.png")) if crcBreel == crcBattendu : imagesValidees.ajouterImage(repDestination+"/"+numberString+"b.png") else : g.getWebFile(webURLB,fileDestB) crcBreel = getCRC(repDestination+"/"+numberString+"b.png") if getCRC(repDestination+"/"+numberString+"b.png") == game.im2CRC : imagesValidees.ajouterImage(repDestination+"/"+numberString+"b.png") else : writeError("%s CRC ERROR!" % (numberString+"b.png")) if not os.path.exists(repDestination+"/"+getNumberStringFourCaract(numberInt) + ".png") : writeInfo("Get web File %s" % "http://www.advanscene.com/offline/imgs/NDSicon/"+getURL500(numberInt)+"/"+getNumberStringFourCaract(numberInt) + ".png") g.getWebFile("http://www.advanscene.com/offline/imgs/NDSicon/"+getURL500(numberInt)+"/"+getNumberStringFourCaract(numberInt) + ".png",repDestination+"/"+getNumberStringFourCaract(numberInt) + ".png") return imagesValidees
def getRomInfoListFromFile(self): if not gotLib7z: writeError("Sorry, You cannot use 7z file") return [] listCrc = [] writeInfo("Open 7Z file") fp = open(self.file, 'rb') archive = Archive7z(fp) for name in archive.getnames(): crc = getCRCFromBuffer(archive.getmember(name).read()) listCrc.append(crc) fp.close() return listCrc
def getFileHandler(self, file): #Attention, tar.gz avant gz tout cours associator = [('.zip', ZipHandler), ('tar.gz', TarGzHandler), ('.gz', GzHandler), ('.7z', SevenZHandler), ('.nds', NdsHandler)] for (extention, classe) in associator: if file.endswith(extention): return classe(file) writeError("File format not reconized") return VoidHandler(file)
def getRomInfoListFromFile(self): if not gotLib7z: writeError("Sorry, You cannot use 7z file") return [] listCrc = [] writeInfo("Open 7Z file") fp = open(self.file, "rb") archive = Archive7z(fp) for name in archive.getnames(): crc = getCRCFromBuffer(archive.getmember(name).read()) listCrc.append(crc) fp.close() return listCrc
def __init__(self, config={}): self.gotLibUrlGrabber = False try: from urlgrabber.grabber import URLGrabber except: writeError('This script is better with URLBrabber.') writeError('See http://linux.duke.edu/projects/urlgrabber/') self.gotLibUrlGrabber = False if not self.gotLibUrlGrabber: return if config.has_key('proxy'): writeInfo("URLGrabberWithProxy : %s" % config['proxy']) self.g = URLGrabber(proxies={'http': config['proxy']}) else: writeInfo("URLGrabbersansProxy") self.g = URLGrabber()
def __init__(self,config = {}): self.gotLibUrlGrabber = False try: from urlgrabber.grabber import URLGrabber except: writeError('This script is better with URLBrabber.') writeError('See http://linux.duke.edu/projects/urlgrabber/') self.gotLibUrlGrabber = False if not self.gotLibUrlGrabber: return if config.has_key('proxy'): writeInfo("URLGrabberWithProxy : %s" % config['proxy']) self.g = URLGrabber(proxies= {'http' : config['proxy']}) else: writeInfo("URLGrabbersansProxy") self.g = URLGrabber()
def getFileHandler(self, file): # Attention, tar.gz avant gz tout cours associator = [ (".zip", ZipHandler), ("tar.gz", TarGzHandler), (".gz", GzHandler), (".7z", SevenZHandler), (".nds", NdsHandler), ] for (extention, classe) in associator: if file.endswith(extention): return classe(file) writeError("File format not reconized") return VoidHandler(file)
def updateImgsForced(games, repDestination, configuration): g = WebGrabber() for game in games.values(): #print type(game) numberInt = int(game.imageNumber) numberString = game.imageNumber g.getWebFile(configuration.newDat.imURL+"/"+getURL500(numberInt)+"/"+numberString+"a.png",repDestination+"/"+numberString+"a.png") crcAreel = getCRC(repDestination+"/"+numberString+"a.png") crcAattendu = game.im1CRC #print "%s : CRC reel %s, CRC attendu %s" % (numberString+"a",crcAreel,crcAattendu) crcBreel = getCRC(repDestination+"/"+numberString+"b.png") crcBattendu = game.im2CRC g.getWebFile(configuration.newDat.imURL+"/"+getURL500(numberInt)+"/"+numberString+"b.png",repDestination+"/"+numberString+"b.png") #print "%s : CRC reel %s, CRC attendu %s" % (numberString+"b",crcBreel,crcBattendu) if crcAreel != crcAattendu : writeError("%s CRC ERROR!" % (numberString+"a.png")) if crcBreel != crcBattendu : writeError("%s CRC ERROR!" % (numberString+"b.png"))
def extractFromFileAndCrc(self, crc, dest): writeError("Désolé, ce type de fichier n'est pas géré %s" % self.file)
def getRomInfoListFromFile(self): writeError("Désolé, ce type de fichier n'est pas géré %s" % self.file) return []
('.nds', NdsHandler)] for (extention, classe) in associator: if file.endswith(extention): return classe(file) writeError("File format not reconized") return VoidHandler(file) gotLib7z = True try: from py7zlib import Archive7z writeInfo("Got 7z Lib") except: writeError('You cannot got 7z file.') writeError('See http://www.joachim-bauch.de/projects/python/pylzma/') gotLib7z = False #cre une liste d'infos sur les roms a partir d'un répertoire def createRomsInfosListFromRep(rep, pathExplored, stoper): '''fonction principale qui parcours les repertoires ''' listCrc = [] #on cré la factory de FileHandler ffh = FactoryFileHandler() for repertoire, sous_reps, fichiers in os.walk(rep): for fichier in fichiers: #on gère l'arrêt
for (extention, classe) in associator: if file.endswith(extention): return classe(file) writeError("File format not reconized") return VoidHandler(file) gotLib7z = True try: from py7zlib import Archive7z writeInfo("Got 7z Lib") except: writeError("You cannot got 7z file.") writeError("See http://www.joachim-bauch.de/projects/python/pylzma/") gotLib7z = False # cre une liste d'infos sur les roms a partir d'un répertoire def createRomsInfosListFromRep(rep, pathExplored, stoper): """fonction principale qui parcours les repertoires """ listCrc = [] # on cré la factory de FileHandler ffh = FactoryFileHandler() for repertoire, sous_reps, fichiers in os.walk(rep): for fichier in fichiers: # on gère l'arrêt if stoper.isDoStop():