def parse_value(self, value): if value.endswith("%"): percent = int(value[0:-1]) return percent2amplification(percent) elif value.lower().endswith("db"): db = int(value[0:-2]) return decibel2amplification(db) elif "." in value: return float(value) elif value.startswith("0x"): return int(value, 16) else: return int(value)
def string_to_volume(self, strval): strval = strval.lower() vol = 0 if strval.endswith("db"): try: dbval = float(strval[0:-2]) vol = decibel2amplification(dbval) except: logging.error("Can't parse db value {}", strval) return None # TODO elif strval.endswith("%"): try: pval = float(strval[0:-1]) vol = percent2amplification(pval) except: logging.error("Can't parse db value {}", strval) return None else: vol = float(strval) return vol