I found an answer for the question:
I use a function to find every user who is logged in and use all the yaml-files of each logged in user (the userconfig.yaml is permanently saved and gets an update during login).
# using self made module system.current_users()
users = system.current_users()
printers_with_users = {}
for username in users:
try:
printer_yaml = config_data.retrieve_for(username).get(u"printers", [])
except:
print("Aborting: Can't find userconfig.yaml!\n")
exit(1)
for device, dev_list in printer_yaml.iteritems():
# parsing datas...
config_classes = dev_list.get("config_classes", None)
descr = get_unicode(dev_list, u"descr")
printer_id = get_unicode(dev_list, u"id")
is_local = dev_list.get("is_local", None)
listen_network = dev_list.get("listen_network", None)
location = get_unicode(dev_list, u"location")
ppd_file = get_unicode(dev_list, u"ppd_file")
ppd_uri = get_unicode(dev_list, u"ppd_uri")
printer_uri = get_unicode(dev_list, u"printer_uri")
# here is the cool part ;)
printers_with_users.setdefault(printer_id, []).append(username)
#configuring printers...
# configure access rules in printers.conf
for printers, accepted_users in printers_with_users.iteritems():
users_string = ",".join(accepted_users)
try:
subproc.call('lpadmin', ['-p', printers, '-u', 'allow:%s' % users_string])
except:
print ( " - unable to set user access rules\n" )
print (config_error) % printers
continue
I'm doing the same thing for the classes, too.
I can still clean the whole config file during each login and can also assure that every user can use his own printers.
Hopefully this is helpful for everyone who has the same problem (even though it is only a small piece of the whole printer manager ;) ).