Exemple #1
0
    def parseFile(self, s):
        fichierBeerXML = s
        try:
            self.arbre = ET.parse(fichierBeerXML)
            presentation = self.arbre.find('.//RECIPE')  # noqa
            fermentables = self.arbre.findall('.//FERMENTABLE')
            hops = self.arbre.findall('.//HOP')
            levures = self.arbre.findall('.//YEAST')
            misc = self.arbre.findall('.//MISC')

            for element in hops:
                ImportBase.addHop(Hop.parse(element))
            for element in fermentables:
                ImportBase.addFermentable(Fermentable.parse(element))
            for element in misc:
                ImportBase.addMisc(Misc.parse(element))
            for element in levures:
                ImportBase.addYeast(Yeast.parse(element))
        except:
            self.warningFile()

        self.hopsNum = len(hops)
        self.fermNum = len(fermentables)
        self.miscNum = len(misc)
        self.yeastNum = len(levures)

        self.info()
Exemple #2
0
 def delHop(h):
     ImportBase().listeHops.remove(h)
     root = ImportBase().arbre.getroot()
     iterator = root.iter("HOP")
     item = None
     for elem in iterator:
         tempHop = Hop.parse(elem)
         if (h.name == tempHop.name and h.form == tempHop.form
                 and h.alpha == tempHop.alpha):
             item = elem
     if item is not None:
         root.remove(item)
         ImportBase.save(root)
Exemple #3
0
    def __init__(self):
        logger.debug("Import %s", database_file)
        fichierBeerXML = database_file
        self.arbre = ET.parse(fichierBeerXML)

        presentation = self.arbre.find('.//RECIPE')
        fermentables = self.arbre.findall('.//FERMENTABLE')
        hops = self.arbre.findall('.//HOP')
        levures = self.arbre.findall('.//YEAST')
        misc = self.arbre.findall('.//MISC')

        self.listeFermentables = list()
        self.listeHops = list()
        self.listeYeasts = list()
        self.listeMiscs = list()

        # Ingredient fermentescibles
        for element in fermentables:
            self.listeFermentables.append(Fermentable.parse(element))
        self.listeFermentables = sorted(self.listeFermentables,
                                        key=attrgetter('name'))
        logger.debug("%s fermentables in database, using %s bytes in memory",
                     len(self.listeFermentables),
                     sys.getsizeof(self.listeFermentables))

        # Houblons
        for element in hops:
            self.listeHops.append(Hop.parse(element))
        self.listeHops = sorted(self.listeHops, key=attrgetter('name'))
        logger.debug("%s hops in database, using %s bytes in memory",
                     len(self.listeHops), sys.getsizeof(self.listeHops))

        # Levures
        for element in levures:
            self.listeYeasts.append(Yeast.parse(element))
        self.listeYeasts = sorted(self.listeYeasts, key=attrgetter('name'))
        logger.debug("%s yeasts in database, using %s bytes in memory",
                     len(self.listeYeasts), sys.getsizeof(self.listeYeasts))

        # Ingredients divers
        for element in misc:
            self.listeMiscs.append(Misc.parse(element))
        self.listeMiscs = sorted(self.listeMiscs, key=attrgetter('name'))
        logger.debug("%s miscs in database, using %s bytes in memory",
                     len(self.listeMiscs), sys.getsizeof(self.listeMiscs))

        logger.debug("Import %s terminé", database_file)

        # Import Mash file
        logger.debug("Import %s", mash_file)
        arbre = ET.parse(mash_file)

        mash = arbre.findall('.//MASH')
        self.listeMashes = list()

        for element in mash:
            self.listeMashes.append(Mash.parse(element))
        logger.debug("%s mash in database, using %s bytes in memory",
                     len(self.listeMashes), sys.getsizeof(self.listeMashes))

        logger.debug("Import %s terminé", mash_file)