diff options
Diffstat (limited to 'bin/standardskriver')
-rwxr-xr-x | bin/standardskriver | 32 |
1 files changed, 19 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 = [] |