示例#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()
示例#2
0
    def ajouter(self):
        m = Misc()
        m.name = self.ui.lineEditNom.text()

        if self.ui.comboBoxType.currentIndex() is 0:
            m.type = 'Spice'
        elif self.ui.comboBoxType.currentIndex() is 1:
            m.type = 'Fining'
        elif self.ui.comboBoxType.currentIndex() is 2:
            m.type = 'Water Agent'
        elif self.ui.comboBoxType.currentIndex() is 3:
            m.type = 'Herb'
        elif self.ui.comboBoxType.currentIndex() is 4:
            m.type = 'Flavor'
        elif self.ui.comboBoxType.currentIndex() is 5:
            m.type = 'Other'
        else:
            m.type = 'Spice'
        ImportBase.addMisc(m)
        self.setModel()
示例#3
0
文件: base.py 项目: j0ack/joliebulle
 def delMisc(m):
     ImportBase().listeMiscs.remove(m)
     root = ImportBase().arbre.getroot()
     iterator = root.iter("MISC")
     item = None
     for elem in iterator:
         tempMisc = Misc.parse(elem)
         if m.name == tempMisc.name and m.type == tempMisc.type:
             item = elem
     if item is not None:
         root.remove(item)
         ImportBase.save(root)
示例#4
0
def importBSMXMisc(data):
    misc = Misc()
    misc.name = data.find("F_M_NAME").text
    # 1 tsp (US) = 4.92892161458 gr
    misc.amount = float(data.find("F_M_AMOUNT").text) * 4.92892161458
    misc.time = float(data.find("F_M_TIME").text)
    misc.type = data.find("F_M_USE_FOR").text
    bsmx_misc_usage = {"1": model.constants.MISC_USE_BOIL, "5": model.constants.MISC_USE_MASH}
    misc.use = bsmx_misc_usage.get(data.find("F_M_TYPE").text, model.constants.MISC_USE_BOIL)
    return misc
示例#5
0
def importBSMXMisc(data):
    misc = Misc()
    misc.name = data.find('F_M_NAME').text
    # 1 tsp (US) = 4.92892161458 gr
    misc.amount = float(data.find('F_M_AMOUNT').text) * 4.92892161458
    misc.time = float(data.find('F_M_TIME').text)
    misc.type = data.find('F_M_USE_FOR').text
    bsmx_misc_usage = {
        '1': model.constants.MISC_USE_BOIL,
        '5': model.constants.MISC_USE_MASH
    }
    misc.use = bsmx_misc_usage.get(
        data.find('F_M_TYPE').text, model.constants.MISC_USE_BOIL)
    return misc
示例#6
0
def importBeerXMLMisc(data):
    misc = Misc()

    for child in data:
        if 'NAME' == child.tag:
            misc.name = child.text
        elif 'AMOUNT' == child.tag:
            misc.amount = float(child.text) * 1000
        elif 'TYPE' == child.tag:
            misc.type = child.text
        elif 'TIME' == child.tag:
            try:
                misc.time = float(child.text)
            except ValueError:
                misc.time = 0.0
                logger.debug(
                    "misc time attribute is not numeric:%s", child.text)
        elif 'USE' == child.tag:
            if 'Boil' == child.text:
                misc.use = model.constants.MISC_USE_BOIL
            elif 'Mash' == child.text:
                misc.use = model.constants.MISC_USE_MASH
            elif 'Primary' == child.text:
                misc.use = model.constants.MISC_USE_PRIMARY
            elif 'Secondary' == child.text:
                misc.use = model.constants.MISC_USE_SECONDARY
            elif 'Bottling' == child.text:
                misc.use = model.constants.MISC_USE_BOTTLING
            else:
                logger.warn(
                    "Unkown misc use '%s', assuming 'Boil' by default",
                    child.text
                )
                misc.use = model.constants.MISC_USE_BOIL

    return misc
示例#7
0
def importBeerXMLMisc(data):
    misc = Misc()

    for child in data:
        if 'NAME' == child.tag :
            misc.name = child.text
        elif 'AMOUNT' == child.tag :
            misc.amount = float(child.text)*1000
        elif 'TYPE' == child.tag :
            misc.type = child.text
        elif 'TIME' == child.tag:
            try:
                misc.time = float(child.text)
            except ValueError:
                misc.time = 0.0
                logger.debug("misc time attribute is not numeric:%s", child.text)
        elif 'USE' == child.tag:
            if 'Boil' == child.text:
                misc.use = model.constants.MISC_USE_BOIL
            elif 'Mash' == child.text:
                misc.use = model.constants.MISC_USE_MASH
            elif 'Primary' == child.text:
                misc.use = model.constants.MISC_USE_PRIMARY
            elif 'Secondary' == child.text:
                misc.use = model.constants.MISC_USE_SECONDARY
            elif 'Bottling' == child.text:
                misc.use = model.constants.MISC_USE_BOTTLING
            else:
                logger.warn ("Unkown misc use '%s', assuming 'Boil' by default", child.text)
                misc.use = model.constants.MISC_USE_BOIL

    return misc
示例#8
0
文件: base.py 项目: j0ack/joliebulle
    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)
示例#9
0
def importDictRecipe(dic):
    logger.debug("Start parsing dict")

    recipe = Recipe()
    recipe.path = dic['path']
    recipe.name = dic['name']
    recipe.brewer = dic['brewer']
    recipe.style = dic['style']
    if dic['type'] == "All Grain":
        recipe.type = RECIPE_TYPE_ALL_GRAIN
    elif dic['type'] == "Extract":
        recipe.type = RECIPE_TYPE_EXTRACT
    elif recipe.type == "Partial Mash":
        recipe.type = RECIPE_TYPE_PARTIAL_MASH

    recipe.volume = dic['volume']
    recipe.boil = dic['boilTime']
    recipe.efficiency = dic['efficiency']

    for hop_dic in dic['hops']:
        hop = Hop()
        hop.name = hop_dic['name']

        if hop_dic['form'] == "Pellet":
            hop.form = HOP_FORM_PELLET
        elif hop_dic['form'] == "Leaf":
            hop.form = HOP_FORM_LEAF
        elif hop_dic['form'] == "Plug":
            hop.form = HOP_FORM_PLUG
        hop.alpha = hop_dic['alpha']
        hop.use = hop_dic['use']
        hop.time = hop_dic['time']
        hop.amount = hop_dic['amount']
        recipe.listeHops.append(hop)

    for f_dic in dic['fermentables']:
        f = Fermentable()
        f.name = f_dic['name']
        f.type = f_dic['type']
        f.fyield = f_dic['fyield']
        f.color = f_dic['color']
        f.amount = f_dic['amount']
        if f_dic['afterBoil'] == 'TRUE':
            f.useAfterBoil = True
        else:
            f.useAfterBoil = False
        f.recommendMash = f_dic['recoMash']
        recipe.listeFermentables.append(f)

    for y_dic in dic['yeasts']:
        y = Yeast()
        y.name = y_dic['name']
        y.productId = y_dic['product_id']
        y.labo = y_dic['labo']
        y.form = y_dic['form']
        y.attenuation = y_dic['attenuation']
        recipe.listeYeasts.append(y)

    for m_dic in dic['miscs']:
        m = Misc()
        m.name = m_dic['name']
        m.amount = m_dic['amount']
        m.type = m_dic['type']
        m.use = m_dic['use']
        m.time = m_dic['time']
        recipe.listeMiscs.append(m)

    mash_dic = dic['mashProfile']
    recipe.mash.name = mash_dic['name']
    recipe.mash.ph = mash_dic['ph']
    recipe.mash.spargeTemp = mash_dic['sparge']
    recipe.mash.tunTemp = mash_dic['tunTemp']

    for s_dic in mash_dic['steps']:
        s = MashStep()
        s.name = s_dic['name']
        s.time = s_dic['time']
        s.temp = s_dic['temp']
        s.type = s_dic['type']
        recipe.listeMashSteps.append(s)
    recipe.recipeNotes = dic['notes']

    return recipe