diff options
| -rwxr-xr-x | bin/standardskriver | 32 | ||||
| -rw-r--r-- | debian/changelog | 7 | 
2 files changed, 26 insertions, 13 deletions
| diff --git a/bin/standardskriver b/bin/standardskriver index 33d12e0..60f9f59 100755 --- a/bin/standardskriver +++ b/bin/standardskriver @@ -60,7 +60,7 @@ import re  from socket import gethostname, getfqdn  import netaddr  from optparse import OptionParser -from ConfigParser import RawConfigParser +import ConfigParser  # check whose customer system we are on...  customer_id = None @@ -84,7 +84,7 @@ if not os.path.exists(CFG_FILE):      print CFG_FILE_EXAMPLE      sys.exit(1) -cfg = RawConfigParser() +cfg = ConfigParser.RawConfigParser()  # hack: mac addrs contain :, which clashes with cfg syntax  cfg.OPTCRE = re.compile(          r'(?P<option>[^=\s][^=]*)'          # very permissive! @@ -131,8 +131,11 @@ def get_group_match():      if customer_id:          group_sections.append('groups.{customer}'.format(customer=customer_id))      for section in group_sections: -        for group, printer in cfg.items(section): -            if group.strip('@') in groups: return printer +        try: +            for group, printer in cfg.items(section): +                if group.strip('@') in groups: return printer +        except ConfigParser.NoSectionError: +            pass      return None  def get_machine_match(): @@ -140,16 +143,19 @@ def get_machine_match():      if customer_id:          machine_sections.append('machine.{customer}'.format(customer=customer_id))      for section in machine_sections: -        for machine, printer in cfg.items(section): -            if any(fnmatchcase(macaddr, machine.replace('-', '').replace(':', '')) for macaddr in macaddrs): -                return printer -            elif any(fnmatchcase(hostname, machine) for hostname in hostnames): -                return printer -            else: -                machines = netaddr.IPSet(machine.split(',')) -                myaddrs = netaddr.IPSet(ipaddrs) -                if machines & myaddrs: +        try: +            for machine, printer in cfg.items(section): +                if any(fnmatchcase(macaddr, machine.replace('-', '').replace(':', '')) for macaddr in macaddrs):                      return printer +                elif any(fnmatchcase(hostname, machine) for hostname in hostnames): +                    return printer +                else: +                    machines = netaddr.IPSet(machine.split(',')) +                    myaddrs = netaddr.IPSet(ipaddrs) +                    if machines & myaddrs: +                        return printer +        except ConfigParser.NoSectionError: +            pass      return None  matches = [] diff --git a/debian/changelog b/debian/changelog index 54c8f43..0ab0817 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +itzks-systems (2015.04.17.2) UNRELEASED; urgency=medium + +  * standardskriver tool: +    - Tolerate non-existing [sections] in standardskriver.cfg. + + -- Mike Gabriel <mike.gabriel@das-netzwerkteam.de>  Fri, 17 Apr 2015 16:11:18 +0200 +  itzks-systems (2015.04.17.1) unstable; urgency=medium    * standardskriver tool: | 
