Plugins

Package with routines to access the plugins (Python modules) stored in the current subdirectory.

Usage:

plugins(args_for_names_function)
get_functions(plugin_name)(args_for_plugin_function)
call_functions(plugin_name, args_for_plugin_function)

Jobs to Printer

Watchdog for /pdf directory that is able to sent new files to a printer

Send new pdfs files on a printer configured in Cups.

Expected settings: output_printer set and not *stream as endlesstext setting; i.e. output_printer is defined; and it is not an infinite stream.

In other terms, a pdf is sent to printer if:

  • endlesstext setting is no, plain-jobs, strip-escp2-jobs,

  • and output_printer setting is not no

TODO: only “no” for endless config because strip wrongly builds empty pdf files

=> not any of (“plain-jobs”, “strip-escp2-jobs”, “no”)

class libreprinter.plugins.lp_jobs_to_printer_watchdog.PdfEventHandler(*args, printer_name=None, **kwargs)[source]

Watch a directory via a parent Observer and emit events accordingly

This class only reimplement on_created() event.

Watched directories:

  • pdf: *.pdf

Attribute:
param printer_name:

Name of the CUPS printer which will receive files as jobs.

type printer_name:

str

Class attribute:
param FILES_REGEX:

Patterns to detect pdf files.

type FILES_REGEX:

list[str]

on_closed(event)[source]

PDF creation is detected, send it to the configured printer

libreprinter.plugins.lp_jobs_to_printer_watchdog.setup_pdf_watchdog(config)[source]

Initialise a watchdog on /pdf directory in configured output_path.

Any pdf file created in these directories will be sent to the printer configured via output_printer.

Returns:

Observer that is currently watching directories.

Return type:

watchdog.Observer

PCL to PDF

Watchdog for /pcl directory that is able to convert new files into pdfs

The conversion is made thanks to the pcl_converter_path setting pointing to the GhostPCL binary.

class libreprinter.plugins.lp_pcl_to_pdf_watchdog.PclEventHandler(*args, converter_path=None, **kwargs)[source]

Watch a directory via a parent Observer and emit events accordingly

This class only reimplement on_created() event.

Watched directory:

  • pcl: *.pcl

Attribute:
param converter_path:

Path to GhostPCL binary.

type converter_path:

str

Class attribute:
param FILES_REGEX:

Patterns to detect pcl files.

type FILES_REGEX:

list[str]

on_closed(event)[source]

PCL file creation is detected, convert it to PDF

libreprinter.plugins.lp_pcl_to_pdf_watchdog.setup_pcl_watchdog(config)[source]

Initialise a watchdog on /pcl directory in configured output_path.

Any pcl file created in this directories will be converted in /pdf by the ghostpcl binary whose path is indicated in the variable pcl_converter_path.

Returns:

Observer that is currently watching directories.

Return type:

watchdog.Observer

ESC & ESC/P2 converter

Interprocess communication

Open and use shared memory object created by converters

libreprinter.legacy_interprocess_com.debug_shared_memory()[source]

Display content of status messages in shared memory

Note

Pending jobs are not showed.

libreprinter.legacy_interprocess_com.get_status_message(offset)[source]

Get value at the given address in shared memory

Expects that initialize_interprocess_com() is called before.

Note

Equivalent of legacy “peekPacketWord”

Return type:

int

libreprinter.legacy_interprocess_com.initialize_interprocess_com()[source]

Init/open shared memory

Shared file is at /dev/shm/retroprinter-shared-mem and initially created by converters.

We just purpose a hacky r/w binding to this object (which is very badly implemented in converters: the original project hopes to store a packet based on int16 into 2 int8 in 2 separated bytes in shared memory. In fact the OS uses 4 bytes (int32) for each “int” stored. So, for 512 packets we use 2048 bytes, and by accessing to 405 offset we access to 1620 offset in file. The file is badly initialized but it works because the OS reserves much more data than 512 bytes: a multiple of page size.).

Note

Equivalent of legacy “initialize_interface_comms”

Returns:

The file handler on the shared memory file for its proper closing.

Return type:

<_io.BufferedRandom>

libreprinter.legacy_interprocess_com.send_status_message(offset, value)[source]

Put given value to the given offset in shared memory

Expects that initialize_interprocess_com() is called before.

Note

Equivalent of legacy “pokePacketWord”

Parameters:
  • offset (int) – Address

  • value (int) – Value

Converter wrapper

Parametrize and launch espc2 converter binary as subprocess

libreprinter.plugins.lp_escp2_converter.launch_escp2_converter(config)[source]

Start escp2 converter

If the config files contains a directory in escp2_converter_path setting, we expect that the binary is in this directory and has the name convert-escp2.

convert-escp2 <path> <timeout> <retain_data> <printing> <endlesstext> <retain_pdf>

Fixed parameters:

  • path: Path in output_path configuration variable.

  • timeout: 4, Wait for more data in file; pause waiting new byte in file

  • retain_data: 1, Useless param didn’t used

  • printing: 0, Do not let the converter send pdf to printer; see libreprinter.jobs_to_printer_watchdog().

  • endlesstext: Configured in endlesstext configuration variable.

  • retain_pdf: 1, Useless param didn’t used; endlesstext handles this behaviour

Ex: convert-escp2 ./ 4 1 0 0 1

Ex priority reg: nice -n19 <command>

Parameters:

config (configparser.ConfigParser) – ConfigParser object

Returns:

subprocess descriptor

Return type:

subprocess.Popen