deal with empty config values

workspace
Brendan Howell 5 years ago
parent 0dd6bc979b
commit f9a24c458b

@ -184,14 +184,17 @@ class Bureau(object):
printcfg = configparser.ConfigParser() printcfg = configparser.ConfigParser()
try: try:
printcfg.read("printers.cfg") printcfg.read("printers.cfg")
self.smprint = object() self.smprint = {}
self.smprint["vendorid"] = int(printcfg["smallprinter"]["vendorid"], 16) for hexkey in ["vendorid", "productid", "inep", "outep"]:
self.smprint["prodid"] = int(printcfg["smallprinter"]["productid"], 16) val = printcfg["smallprinter"][hexkey]
self.smprint["in_ep"] = int(printcfg["smallprinter"]["inep"], 16) if val == "":
self.smprint["out_ep"] = int(printcfg["smallprinter"]["outep"], 16) self.smprint[hexkey] = None
else:
self.smprint[hexkey] = int(val, 16)
self.smprint["width"] = int(printcfg["smallprinter"]["width"]) self.smprint["width"] = int(printcfg["smallprinter"]["width"])
self.smprint["textwidth"] = int(printcfg["smallprinter"]["textwidth"]) self.smprint["textwidth"] = int(printcfg["smallprinter"]["textwidth"])
self.lp = {}
self.lp["name"] = printcfg["largeprinter"]["name"] self.lp["name"] = printcfg["largeprinter"]["name"]
self.lp["papersize"] = printcfg["largeprinter"]["papersize"] self.lp["papersize"] = printcfg["largeprinter"]["papersize"]
self.lp["duplex"] = printcfg["largeprinter"].getboolean("duplex") self.lp["duplex"] = printcfg["largeprinter"].getboolean("duplex")

Loading…
Cancel
Save