From 82ba4c63204093c68482cdb8b0068389d2960d7b Mon Sep 17 00:00:00 2001 From: FiZiX Date: Wed, 1 May 2024 17:14:36 -0400 Subject: [PATCH 1/2] Various fixes including paper size and removal of unneeded fields. --- root/root/airprint-generate.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) mode change 100644 => 100755 root/root/airprint-generate.py diff --git a/root/root/airprint-generate.py b/root/root/airprint-generate.py old mode 100644 new mode 100755 index 146e3f2..a411967 --- a/root/root/airprint-generate.py +++ b/root/root/airprint-generate.py @@ -77,7 +77,6 @@ 'image/urf': True, 'image/png': True, 'image/tiff': True, - 'image/png': True, 'image/jpeg': True, 'image/gif': True, 'text/plain': True, @@ -126,6 +125,7 @@ def generate(self): for p, v in list(printers.items()): if v['printer-is-shared']: attrs = conn.getPrinterAttributes(p) + uri = urlparse.urlparse(v['printer-uri-supported']) tree = ElementTree() @@ -170,26 +170,22 @@ def generate(self): service.append(desc) product = Element('txt-record') - product.text = 'product=(GPL Ghostscript)' + product.text = f"product=({v['printer-info']})" service.append(product) - state = Element('txt-record') - state.text = 'printer-state=%s' % (v['printer-state']) - service.append(state) - - ptype = Element('txt-record') - ptype.text = 'printer-type=%s' % (hex(v['printer-type'])) - service.append(ptype) + kind = Element('txt-record') + kind.text = 'kind=document' + service.append(kind) if attrs['color-supported']: color = Element('txt-record') color.text = 'Color=T' service.append(color) - if attrs['media-default'] == 'iso_a4_210x297mm': - max_paper = Element('txt-record') - max_paper.text = 'PaperMax=legal-A4' - service.append(max_paper) + paper_max = 'PaperMax=legal-A4' + max_paper = Element('txt-record') + max_paper.text = paper_max + service.append(max_paper) pdl = Element('txt-record') fmts = [] @@ -229,18 +225,18 @@ def generate(self): if self.directory: fname = os.path.join(self.directory, fname) - - f = open(fname, 'w') if etree: - tree.write(f, pretty_print=True, xml_declaration=True, encoding="UTF-8") + etree.indent(tree) + tree.write(fname, xml_declaration=True, encoding="UTF-8") else: + f = open(fname, 'w') xmlstr = tostring(tree.getroot()) doc = parseString(xmlstr) dt= minidom.getDOMImplementation('').createDocumentType('service-group', None, 'avahi-service.dtd') doc.insertBefore(dt, doc.documentElement) doc.writexml(f) - f.close() + f.close() if self.verbose: sys.stderr.write('Created: %s%s' % (fname, os.linesep)) From f42f52a36a9f0fb906801b992531fe5fb265a8b8 Mon Sep 17 00:00:00 2001 From: FiZiX Date: Wed, 1 May 2024 18:02:23 -0400 Subject: [PATCH 2/2] Various fixes including paper size and removal of unneeded fields. --- root/root/airprint-generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/root/airprint-generate.py b/root/root/airprint-generate.py index a411967..1dad304 100755 --- a/root/root/airprint-generate.py +++ b/root/root/airprint-generate.py @@ -206,7 +206,7 @@ def generate(self): dropped = [] # TODO XXX FIXME all fields should be checked for 255 limit - while len('pdl=%s' % (fmts)) >= 255: + while len('pdl=%s' % fmts) >= 255: (fmts, drop) = fmts.rsplit(',', 1) dropped.append(drop)