| 634 | |
| 635 | def getPrinterCoefficients(self, printername) : |
| 636 | """Returns a mapping of coefficients for a particular printer.""" |
| 637 | branchbasename = "coefficient_" |
| 638 | try : |
| 639 | globalbranches = [ (k, self.config.get("global", k)) for k in self.config.options("global") if k.startswith(branchbasename) ] |
| 640 | except ConfigParser.NoSectionError, msg : |
| 641 | raise PyKotaConfigError, "Invalid configuration file : %s" % msg |
| 642 | try : |
| 643 | sectionbranches = [ (k, self.config.get(printername, k)) for k in self.config.options(printername) if k.startswith(branchbasename) ] |
| 644 | except ConfigParser.NoSectionError, msg : |
| 645 | sectionbranches = [] |
| 646 | branches = {} |
| 647 | for (k, v) in globalbranches : |
| 648 | value = v.strip() |
| 649 | if value : |
| 650 | try : |
| 651 | branches[k] = float(value) |
| 652 | except ValueError : |
| 653 | raise PyKotaConfigError, "Invalid coefficient %s (%s) for printer %s" % (k, value, printername) |
| 654 | |
| 655 | for (k, v) in sectionbranches : |
| 656 | value = v.strip() |
| 657 | if value : |
| 658 | try : |
| 659 | branches[k] = float(value) # overwrite any global option or set a new value |
| 660 | except ValueError : |
| 661 | raise PyKotaConfigError, "Invalid coefficient %s (%s) for printer %s" % (k, value, printername) |
| 662 | else : |
| 663 | del branches[k] # empty value disables a global option |
| 664 | |
| 665 | return branches |