Added ability to request CUPS Job Number and the amount of pages printed #1037
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found myself in the need of retrieving the job number from CUPS, therefore I implemented it. I added guards for the Printer class, as if it is not using a
CupsPrinterConnector
it should not return these values. I found the amount of files was also returned, so I added it as well.The command
lp -d <queue name> <file name>
returns in the formatrequest id is <queue name>-<job name> (<amt of files> file(s))
. As the job name never contains a dash, we can safely say that the last part of this word, after the last dash, will be the job number. The "word" containing the amount of files is only preceded by a(
, thus stripping the first letter of this string should always return the number given.I was not sure if you are okay with these functions residing also inside of the
Printer
. But you can remove them if you feel that's nicer, as it functionality for a specific connector (but I felt this data should come from the printer, and not the connector).