r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[Samba/gebeck_regimport.git] / source3 / python / samba / printerdata.py
blob6c40cc4b26dd7a95315a32f26b124fe7e65f6afd
1 #!/usr/bin/env python
4 # A python module that maps printerdata to a dictionary. We define
5 # two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData
6 # and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx
10 # TODO:
12 # - Implement __delitem__
15 from samba import spoolss
17 class printerdata:
18 def __init__(self, host, creds = {}, access = 0x02000000):
19 # For read access, use MAXIMUM_ALLOWED_ACCESS = 0x02000000
20 # For write access, use PRINTER_ACCESS_ADMINISTER = 0x00000004
21 self.hnd = spoolss.openprinter(host, creds = creds, access = access)
23 def keys(self):
24 return self.hnd.enumprinterdata().keys()
26 def __getitem__(self, key):
27 return self.hnd.getprinterdata(key)['data']
29 def __setitem__(self, key, value):
30 # Store as REG_BINARY for now
31 self.hnd.setprinterdata({"key": "", "value": key, "type": 3,
32 "data": value})
34 class printerdata_ex:
35 def __init__(self, host, creds = {}, access = 0x02000000):
36 # For read access, use MAXIMUM_ALLOWED_ACCESS = 0x02000000
37 # For write access, use PRINTER_ACCESS_ADMINISTER = 0x00000004
38 self.host = host
39 self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver",
40 "DsUser"]
41 self.creds = creds
42 self.access = access
44 def keys(self):
45 return self.top_level_keys
47 def has_key(self, key):
48 for k in self.top_level_keys:
49 if k == key:
50 return 1
51 return 0
53 class printerdata_ex_subkey:
54 def __init__(self, host, key, creds, access):
55 self.hnd = spoolss.openprinter(host, creds, access)
56 self.key = key
58 def keys(self):
59 return self.hnd.enumprinterdataex(self.key).keys()
61 def __getitem__(self, key):
62 return self.hnd.getprinterdataex(self.key, key)['data']
64 def __getitem__(self, key):
65 return self.printerdata_ex_subkey(
66 self.host, key, self.creds, self.access)