Ejemplo n.º 1
0
def extractFromPathAndCrc(archive, crc, dest):
    writeInfo("Extact From : %s to %s" % (archive, dest))

    # on cré la factory de FileHandler
    ffh = FactoryFileHandler()
    fh = ffh.getFileHandler(archive)
    fh.extractFromFileAndCrc(crc, dest)
Ejemplo n.º 2
0
def extractFromPathAndCrc(archive, crc, dest):
    writeInfo("Extact From : %s to %s" % (archive, dest))

    #on cré la factory de FileHandler
    ffh = FactoryFileHandler()
    fh = ffh.getFileHandler(archive)
    fh.extractFromFileAndCrc(crc, dest)
Ejemplo n.º 3
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open Zip file %s" % self.file)
     fd = zipfile.ZipFile(self.file, "r")
     for name in fd.namelist():
         crc = getCRCFromInt(fd.getinfo(name).CRC)
         listCrc.append(crc)
     return listCrc
Ejemplo n.º 4
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open Zip file %s" % self.file)
     fd = zipfile.ZipFile(self.file, "r")
     for name in fd.namelist():
         crc = getCRCFromInt(fd.getinfo(name).CRC)
         listCrc.append(crc)
     return listCrc
Ejemplo n.º 5
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open Nds file")
     fd = open(self.file, "rb")
     crc = getCRCFromBuffer(fd.read())
     listCrc.append(crc)
     fd.close()
     return listCrc
Ejemplo n.º 6
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open Nds file")
     fd = open(self.file, "rb")
     crc = getCRCFromBuffer(fd.read())
     listCrc.append(crc)
     fd.close()
     return listCrc
Ejemplo n.º 7
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open TarGz file")
     tar = tarfile.open(self.file, "r:gz")
     for element in tar:
         if element.isreg():
             fd = tar.extractfile(element)
             crc = getCRCFromBuffer(fd.read())
             fd.close()
             listCrc.append(crc)
     return listCrc
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 def getRomInfoListFromFile(self):
     listCrc = []
     writeInfo("Open TarGz file")
     tar = tarfile.open(self.file, "r:gz")
     for element in tar:
         if element.isreg():
             fd = tar.extractfile(element)
             crc = getCRCFromBuffer(fd.read())
             fd.close()
             listCrc.append(crc)
     return listCrc
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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")
Ejemplo n.º 13
0
 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")
Ejemplo n.º 14
0
    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()
Ejemplo n.º 15
0
 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()
Ejemplo n.º 16
0
 def extractFromFileAndCrc(self, crc, dest):
     fd = zipfile.ZipFile(self.file, "r")
     for name in fd.namelist():
         crcFd = getCRCFromInt(fd.getinfo(name).CRC)
         # crcFd = getCRCFromBuffer(fd.read(name))
         if crc == crcFd:
             writeInfo("On extracte un Zip %s" % name)
             data = fd.read(name)
             fdest = NamedTemporaryFile()
             # fdest = open("tmp" + "/" + name, 'w+b', os.O_SYNC)
             fdest.write(data)
             fdest.flush()
             # fdest.close()
             # truncateRomFile("tmp" + "/" + name, dest + "/" + name)
             truncateRomFile(fdest.name, dest + "/" + name)
             # os.remove("tmp" + "/" + name)
             fdest.close()
     writeInfo("Ecriture Finie")
Ejemplo n.º 17
0
 def extractFromFileAndCrc(self, crc, dest):
     fd = zipfile.ZipFile(self.file, "r")
     for name in fd.namelist():
         crcFd = getCRCFromInt(fd.getinfo(name).CRC)
         #crcFd = getCRCFromBuffer(fd.read(name))
         if crc == crcFd:
             writeInfo("On extracte un Zip %s" % name)
             data = fd.read(name)
             fdest = NamedTemporaryFile()
             #fdest = open("tmp" + "/" + name, 'w+b', os.O_SYNC)
             fdest.write(data)
             fdest.flush()
             #fdest.close()
             #truncateRomFile("tmp" + "/" + name, dest + "/" + name)
             truncateRomFile(fdest.name, dest + "/" + name)
             #os.remove("tmp" + "/" + name)
             fdest.close()
     writeInfo("Ecriture Finie")
Ejemplo n.º 18
0
    def run(self):
        self.running = True
        writeInfo("Je run le Parcourateur")
        self.app.setStateText("Parcours in progress...")
        self.stoper = ThreadStoper()

        rep = self.app.config.c['repRoms']

        cleanNonExistentPath(self.app.p.pathAlreadyExplored)

        listCrc = createRomsInfosListFromRep(rep, self.app.p, self.stoper)
        for elt in listCrc:
            if elt not in self.app.r.roms:
                self.app.r.roms.append(elt)
        updateGamesInfoWithPath(self.app.r.roms, self.app.c.games)
        self.app.needRefresh = True

        self.running = False

        self.app.setStateText("Parcours Done.")
        writeInfo("Parcours Done.")
Ejemplo n.º 19
0
 def run(self):
     self.running = True
     writeInfo("Je run le Parcourateur")
     self.app.setStateText("Parcours in progress...")
     self.stoper = ThreadStoper()
     
     rep = self.app.config.c['repRoms']
     
     cleanNonExistentPath(self.app.p.pathAlreadyExplored)
     
     listCrc = createRomsInfosListFromRep(rep, self.app.p, self.stoper)
     for elt in listCrc:
         if elt not in self.app.r.roms:
             self.app.r.roms.append(elt)
     updateGamesInfoWithPath(self.app.r.roms, self.app.c.games)
     self.app.needRefresh = True
     
     self.running = False
     
     self.app.setStateText("Parcours Done.")
     writeInfo("Parcours Done.")
Ejemplo n.º 20
0
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():
                writeInfo("Ordre d'arret du parcours de roms, on doit partir")
                return []
            path = os.path.join(repertoire, fichier)
            #print path
            if not pathExplored.contientPath(path):
                #on cré le FileHandler qui va gérer le fichier
                fh = ffh.getFileHandler(path)
                if fh is not None:
                    for item in fh.getRomInfoListFromFile():
                        listCrc.append([item, path])
                    pathExplored.ajouterPath(path)
    return listCrc
Ejemplo n.º 21
0
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():
                writeInfo("Ordre d'arret du parcours de roms, on doit partir")
                return []
            path = os.path.join(repertoire, fichier)
            # print path
            if not pathExplored.contientPath(path):
                # on cré le FileHandler qui va gérer le fichier
                fh = ffh.getFileHandler(path)
                if fh is not None:
                    for item in fh.getRomInfoListFromFile():
                        listCrc.append([item, path])
                    pathExplored.ajouterPath(path)
    return listCrc
Ejemplo n.º 22
0
 def extractFromFileAndCrc(self, crc, dest):
     tar = tarfile.open(archive, "r:gz")
     for file in tar:
         if file.isreg():
             fd = tar.extractfile(file)
             crcFd = getCRCFromBuffer(fd.read())
             fd.close()
             if crc == crcFd:
                 writeInfo("On extracte un TarGz %s" % file)
                 fd = tar.extractfile(file)
                 data = fd.read()
                 print file.__dict__
                 name = os.path.basename(file.name)
                 writeInfo("On extract du TarGz ", name)
                 fdest = NamedTemporaryFile()
                 # fdest = open("tmp" + "/" + name, 'w+b', os.O_SYNC)
                 fdest.write(data)
                 fdest.flush()
                 # fdest.close()
                 # truncateRomFile("tmp" + "/" + name, dest + "/" + name)
                 truncateRomFile(fdest.name, dest + "/" + name)
                 fdest.close()
                 # os.remove("tmp" + "/" + name)
     writeInfo("Ecriture Finie")
Ejemplo n.º 23
0
 def extractFromFileAndCrc(self, crc, dest):
     tar = tarfile.open(archive, "r:gz")
     for file in tar:
         if file.isreg():
             fd = tar.extractfile(file)
             crcFd = getCRCFromBuffer(fd.read())
             fd.close()
             if crc == crcFd:
                 writeInfo("On extracte un TarGz %s" % file)
                 fd = tar.extractfile(file)
                 data = fd.read()
                 print file.__dict__
                 name = os.path.basename(file.name)
                 writeInfo("On extract du TarGz ", name)
                 fdest = NamedTemporaryFile()
                 #fdest = open("tmp" + "/" + name, 'w+b', os.O_SYNC)
                 fdest.write(data)
                 fdest.flush()
                 #fdest.close()
                 #truncateRomFile("tmp" + "/" + name, dest + "/" + name)
                 truncateRomFile(fdest.name, dest + "/" + name)
                 fdest.close()
                 #os.remove("tmp" + "/" + name)
     writeInfo("Ecriture Finie")
Ejemplo n.º 24
0
            (".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:
Ejemplo n.º 25
0
    def extractFromFileAndCrc(self, crc, dest):
        import shutil

        writeInfo("On copie direct le fichier %s vers %s" % (self.file, dest + "/" + os.path.basename(self.file)))
        truncateRomFile(self.file, dest + "/" + os.path.basename(self.file))
Ejemplo n.º 26
0
 def stop(self):
     writeInfo("On décide d'arréter le parcourateur")
     self.stoper.doStop()
Ejemplo n.º 27
0
 def extractFromFileAndCrc(self, crc, dest):
     import shutil
     writeInfo("On copie direct le fichier %s vers %s" %
               (self.file, dest + '/' + os.path.basename(self.file)))
     truncateRomFile(self.file, dest + '/' + os.path.basename(self.file))
Ejemplo n.º 28
0
 def stop(self):
     writeInfo("On décide d'arréter le parcourateur")
     self.stoper.doStop()
Ejemplo n.º 29
0
        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)


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):