SickHub / docker-cups-airprint

A standalone CUPS and Avahi (mDNS/Bonjour) server, exposing local printers on AirPrint for iOS devices
GNU General Public License v3.0
165 stars 38 forks source link

Regarding #45 - color-supported not avaible breaks airprint-generate.py #59

Closed burnbabyburn closed 1 year ago

burnbabyburn commented 1 year ago

@vajonam

Hi, i am coming from this commit In the past i had removed the gpc stuff on a local checkout myself. And your very nice container worked fine for months ATM i am migrating my docker host and tried to go with upstream again But it seems pull #45 killed it for me

output:

cups-airprint  | The dockerized CUPS instance is now ready for use! The web
cups-airprint  | interface is available here:
cups-airprint  | URL:       http://192.168.1.253:631/ or http://futros740:631/
cups-airprint  | Username:  admin
cups-airprint  | Password:  admin
cups-airprint  |
cups-airprint  | ===========================================================
cups-airprint  | Traceback (most recent call last):
cups-airprint  |   File "/opt/airprint/airprint-generate.py", line 299, in <module>
cups-airprint  |     apg.generate()
cups-airprint  |   File "/opt/airprint/airprint-generate.py", line 179, in generate
cups-airprint  |     if attrs['color-supported']:
cups-airprint  | KeyError: 'color-supported'

printer creation:

- CUPS_LPADMIN_PRINTER1=lpadmin -D "HP laserJet M2727 MFP" -p LaserJet123 -v lpd://10.0.0.29/queue -L LivingRoom -o HPOption_Duplexer=true -o Resolution=1200dpi -o PageSize=A4 -o Duplex=DuplexNoTumble -o MediaType=Plain -o Smoothing=off -o HPEconoMode=false -o HPServicesWeb=ProductManuals -o printer-error-policy=abort-job -o cupsIPPSupplies=true
- CUPS_LPADMIN_PRINTER1_ENABLE=cupsenable LaserJet123
- CUPS_LPADMIN_PRINTER1_ACCEPT=cupsaccept LaserJet123

the attrs array parsed in python script (this is from manual adding via cups interface and trying hplip address for more information so ignore device uri) arry parsed in pythonscript.txt

Adding the color-supported to CUPS_LPADMIN_PRINTER1 was not sufficient

(Only) after removing the color-supported option from airprint-generate.py creating an avahi service was successful Commenting out wasn't ideal, so i did some research. Seems to me like the value checked for color isn't ideal and/or needs a fallback:

Sadly my python skills s**** and my printer is not supporting that much, so i leave the additional information here and maybe get back to it

the quick fix for me is to just comment out the commit mentioned above

Greetings

DrPsychick commented 1 year ago

It might be that a simple change could fix it: if attrs['color-supported']: -> if 'color-supported' in attrs:

Let me know if that helps @burnbabyburn , then I can update the code quickly.

burnbabyburn commented 1 year ago

@DrPsychick Thx for the fix. Worked for me, but the Color is always true now! I added some missing stuff from the specification and an else clause for the color. Maybe another possability is to use if attrs.get('color-supported', True): Someone needs to check the python code though

                copies = Element('txt-record')
                if 'copies' in attrs.get('job-creation-attributes-supported'):
                    copies.text = 'Copies=T'
                else:
                    copies.text = 'Copies=F'
                service.append(copies)

                tbcp = Element('txt-record')
                if 'tbcp' in attrs.get('port-monitor-supported'):
                    tbcp.text = 'TBCP=T'
                else:
                    tbcp.text = 'TBCP=F'
                service.append(tbcp)

                staple = Element('txt-record')
                if '4' in attrs.get('finishings-supported'):
                    staple.text = 'Staple=T'
                else:
                    staple.text = 'Staple=F'
                service.append(staple)

##THE OR PART IS BROKEN
                punch = Element('txt-record')
                punch.text = 'Punch=U'
                if '3' in attrs.get('finishings-supported'):
                    punch.text = 'Punch=0'
                if '70' or '71' or '72' or '73' in attrs.get('finishings-supported'):
                    punch.text = 'Punch=1'
                if '74' or '75' or '76' or '77' in attrs.get('finishings-supported'):
                    punch.text = 'Punch=2'
                if '78' or '79' or '80' or '81' in attrs.get('finishings-supported'):
                    punch.text = 'Punch=3'
                if '82' or '83' or '84' or '85' in attrs.get('finishings-supported'):
                    punch.text = 'Punch=4'
                service.append(punch)
##
                bind = Element('txt-record')
                if '7' in attrs.get('finishings-supported'):
                    bind.text = 'Bind=T'
                else:
                    bind.text = 'Bind=F'
                service.append(bind)

                collate = Element('txt-record')
                if 'separate-documents-collated-copies' in attrs.get('multiple-document-handling-supported'):
                    collate.text = 'Collate=T'
                else:
                    collate.text = 'Collate=F'
                service.append(collate)

                duplex = Element('txt-record')
                if 'sides' in attrs.get('job-creation-attributes-supported'):
                    duplex.text = 'Duplex=T'
                else:
                    duplex.text = 'Duplex=F'
                service.append(duplex)

                color = Element('txt-record')
                if attrs['color-supported']:
                    color.text = 'Color=T'
                else:
                    color.text = 'Color=F'
                service.append(color)
vajonam commented 1 year ago

sorry the late response. I have moved to a printer that supports air print natively so haven't been using this container much recently.

DrPsychick commented 1 year ago

should be fine now, thanks for the extremely fast feedback @burnbabyburn !