summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-04-17 16:11:46 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-04-17 16:11:46 +0200
commit62788c4329958d7414d1ff618b8b48ef7ca225a5 (patch)
tree9600878e4c85eea98429188eaf73140cde55296b /bin
parent62e61fa20366b5b8abdd1a024462b44b0d6611b4 (diff)
downloaditzks-systems-62788c4329958d7414d1ff618b8b48ef7ca225a5.tar.gz
itzks-systems-62788c4329958d7414d1ff618b8b48ef7ca225a5.tar.bz2
itzks-systems-62788c4329958d7414d1ff618b8b48ef7ca225a5.zip
standardskriver tool: Tolerate non-existing [sections] in standardskriver.cfg.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/standardskriver32
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 = []