Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix parsing for non-english systems #24

Merged
merged 2 commits into from Nov 7, 2023

Conversation

ovi1337
Copy link
Contributor

@ovi1337 ovi1337 commented Oct 28, 2023

Main issue:
The getPrinters method is returning an empty array, because the parser is searching for printer but on systems with different system languages will it be for example Drucker and don't will match for anything.
The same issue will be in the mapping of additional information.

Solution:
Force console output of the lpstat -lp command to english to make the parsing work on non-english systems.

German systems is currently showing this result:

lpstat -lp
Drucker „Brother_MFC_J4420DW“ ist inaktiv; aktiviert seit Mon Oct  2 13:55:07 2023
	Aktiviertes Formular:
	Inhaltstypen: beliebig
	Druckertypen: unbekannt
	Beschreibung: Brother MFC-J4420DW
	Hinweise: none
	Standort:
	Verbindung: direkt
	Schnittstelle: /private/etc/cups/ppd/Brother_MFC_J4420DW.ppd
	Bei Fehler: kein Hinweis
	Nach Fehler: fortsetzen
	Zugelassene Benutzer:innen:
		(alles)
	Zugelassene Formulare:
		(ohne)
	Banner erforderlich
	Zeichensätze:
		(ohne)
	Standardzeilenhöhe:
	Standardseitengröße:
	Standard-Anschlusseinstellungen:

With the prefix will it be forced to english:

SOFTWARE= LANG=C lpstat -lp
printer Brother_MFC_J4420DW is idle.  enabled since Mon Oct  2 13:55:07 2023
	Form mounted:
	Content types: any
	Printer types: unknown
	Description: Brother MFC-J4420DW
	Alerts: none
	Location:
	Connection: direct
	Interface: /private/etc/cups/ppd/Brother_MFC_J4420DW.ppd
	On fault: no alert
	After fault: continue
	Users allowed:
		(all)
	Forms allowed:
		(none)
	Banner required
	Charset sets:
		(none)
	Default pitch:
	Default page size:
	Default port settings:

Force console output to english to make it work on non-english systems
@ovi1337 ovi1337 changed the title Force english output - get-printers.ts Force english output Oct 28, 2023
@ovi1337 ovi1337 changed the title Force english output Fix parsing for non-english systems Oct 28, 2023
@artiebits
Copy link
Owner

hi @ovi1337 thanks for your contribution. in general your PR looks good to be, and I have only one question - why do we need SOFTWARE=?

@jimnys-8
Copy link
Contributor

jimnys-8 commented Nov 6, 2023

I didn't make the PR, but I also ran into this problem and came here to propose this exact solution! Regarding your question, Apple apparently has this piece of code in their version of CUPS:

if (!getenv("SOFTWARE") || (language = getenv("LANG")) == NULL)
      language = appleLangDefault();

This means that the default language is used unless the SOFTWARE env var is set to something (anything!). Found this info here: https://unix.stackexchange.com/a/33836

@artiebits artiebits changed the title Fix parsing for non-english systems fix: fix parsing for non-english systems Nov 7, 2023
@artiebits
Copy link
Owner

@ovi1337 thanks for the pull request, @jimnys-8 thanks for the explanation

@artiebits artiebits merged commit 4fe8bdf into artiebits:master Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants