YaST2 Developers Documentation: Configuration of scanner

Configuration of scanner

modules/Scanner.ycp
Scanner settings, input and output functions
Representation of the configuration of scanner. Input and output routines.

Imports

  • Label
  • Package
  • Popup
  • Progress
  • Report
  • Service
  • Summary

Structures

Global Variables

Global Functions

Local Functions

global modified -> boolean

Something was committed to the system? True if system may have been modified.

global proposal_valid -> boolean

global write_only -> boolean

Write only, used during autoinstallation. Don't run services and SuSEconfig, it's all done at one place.

global Modified () -> boolean

Something was committed to the system?

Return value:
true if system may have been modified
global Abort () -> boolean

Abort function

Return value:
true if not modified and user requested abort
global database -> list< map< string, string > >

Scanner database: When package version of sane/hp-officeJet/iscan changes the database is created anew in Scanner::Read() which calls the bash script "/usr/lib/YaST2/bin/create_scanner_database YCP" which outputs on stdout a YCP list of scanner_model_map where the last list entry is an emtpy map.

Structure scanner_model_map

 $[ "package":"The package which provides the backend: sane/hplip/hp-officeJet/iscan (required)",
    "backend":"The name of the backend (required)",
    "manufacturer":"The manufacturer name of the scanner (required)",
    "model":"The model name of the scanner (required)",
    "firmware":"Whether or not firmware upload is required (value is 'required' or the empty string)",
    "interface":"None or one or more scanner interfaces (may be the empty string)",
    "status":"The support status: basic/complete/good/minimal/unsupported/untested (required)",
    "comment":"An optional comment (may be the empty string)"
  ]
global database_manufacturers -> list< string >

Manufacturer list: List of unique manufacturer names. Derived during startup from the scanner database (in the Read function stage "Read or create the scanner database").

global active_scanners -> list< map< string, string > >

Active scanners: Determined at runtime via Scanner::DetermineActiveScanners() which calls the bash script "/usr/lib/YaST2/bin/determine_active_scanners YCP" which outputs on stdout a YCP list of active_scanner_map where the last list entry is an emtpy map.

Structure active_scanner_map

 $[ "backend":"The name of the backend (required)",
    "sane_device":"The SANE device (required)",
    "manufacturer":"The manufacturer name of the scanner (required)",
    "model":"The model name of the scanner (required)",
  ]
global active_backends -> list< string >

Active backends: Determined at runtime via Scanner::DetermineActiveBackends() which calls the bash script "/usr/lib/YaST2/bin/determine_active_scanner_backends YCP" which outputs on stdout a YCP list of backends [ "The name of the backend", ... "" ] where the last list entry is an empty string.

global autodetected_scanners -> list< map< string, string > >

Autodetected scanners: Determined at runtime via Scanner::AutodetectScanners() which calls the bash script "/usr/lib/YaST2/bin/autodetect_scanners YCP" which calls "sane-find-scanner" which may result for example the description strings in the example below. Only in case of USB an automated extraction of manufacturer is possible. If there are two '[...]' substrings then the first one is the manufacturer and the second one is the model (but there may be only one or none substring). The result is a YCP list of autodetected_scanner_map where the last list entry is an emtpy map.

Structure autodetected_scanner_map

 $[ "connection":"Either USB or SCSI (required)",
    "device":"The device, e.g. '/dev/sg0' or 'libusb:001:002' (may be the empty string)"
    "manufacturer":"The manufacturer name of the scanner (may be the empty string)",
    "usb_vendor_id":"The vendor ID (e.g. 0x04b8) of a USB scanner (may be the empty string)",
    "model":"The model name of the scanner (may be the empty string)",
    "usb_product_id":"The product ID (e.g. 0x010b) of a USB scanner (may be the empty string)",
    "description":"The sane-find-scanner output description string (required)"
  ]
Example

 SCSI processor 'HP C6270A 3846' at /dev/sg0
 USB scanner (vendor=0x05da, product=0x20b0) at libusb:002:005
 USB scanner (vendor=0x03f0 [Hewlett-Packard], product=0x0201 [HP ScanJet 6200C]) at libusb:002:006
 USB scanner (vendor=0x04a9 [Canon], product=0x220e [CanoScan], chip=LM9832/3) at libusb:001:005
 USB scanner (vendor=0x04b8 [EPSON], product=0x010b [Perfection1240]) at libusb:001:004
global network_scanning_config -> map< string, string >

Network scanning configuration: Determined at runtime via Scanner::DetermineNetworkScanningConfig() which calls the bash script "/usr/lib/YaST2/bin/determine_network_scanner_config YCP" which outputs on stdout a YCP map network_scanner_config

Structure network_scanner_config

 $[ "net_backend_hosts":"Comma seperated list of hosts in /etc/sane.d/net.conf",
    "saned_hosts":"Comma seperated list of hosts or subnets in /etc/sane.d/saned.conf"
  ]
global actual_environment -> map< string, string >

Environment values: It is a map of environment_values

Structure environment_values

 $[ "sane_version":"What 'rpm -q sane' returns (required)",
    "hplip_version":"What 'rpm -q hplip' returns (required)",
    "hp-officeJet_version":"What 'rpm -q hp-officeJet' returns (required)",
    "iscan_version":"What 'rpm -q iscan' returns (required)"
  ]
global selected_model_database_index -> integer

Selected model database index: The index in the scanner database list (of model maps) for the model which was selected by the user in the SelectModelDialog. Preset to -1 which indicates that no model is selected.

global selected_autodetected_scanners_index -> integer

Selected autodetected scanners index: The index in the autodetected scanners list (of autodetected scanner maps) for the model which was selected by the user in the OverviewDialog. Preset to -1 which indicates that no model is selected.

local ExecuteBashCommand (string bash_commandline) -> boolean

Wrapper for SCR::Execute to execute a bash command to increase verbosity via y2milestone. It reports the command via y2milestone in any case and it reports exit code, stdout and stderr via y2milestone in case of non-zero exit code.

Parameters:
bash_commandline string of the bash command to be executed
Return value:
true on success
local InstalledPackageVersion (string package_name) -> string

Determine the version of an installed package by calling a bash command (rpm).

Parameters:
package_name string of the package name
Return value:
of the version of an installed package or "failed to determine" otherwise
local TestAndInstallPackage (string package_name) -> boolean

Test whether the package is installed (Package::Installed) and if not then test whether the package is available to be installed (Package::Available) and if yes then install it (Package::Install).

Parameters:
package_name string of the package name
Return value:
true on success
local DetermineActiveScanners () -> boolean

Determine the active scanners by calling a bash script which calls "scanimage -L" and processes its output and stores the results as YCP list in a temporary file and then read the temporary file (SCR::Read) to get the YCP list of active_scanner_map

Return value:
true on success
local DetermineActiveBackends () -> boolean

Determine the active backends by calling a bash script which calls "grep ... /etc/sane.d/dll.conf" and processes its output and stores the results as YCP list in a temporary file and then read the temporary file (SCR::Read) to get the YCP list of active backends.

Return value:
true on success
local AutodetectScanners () -> boolean

Try to autodetect USB and SCSI scanners by calling a bash script which calls "sane-find-scanner" and processes its output and stores the results as YCP list in a temporary file and then read the temporary file (SCR::Read) to get the YCP list of autodetected_scanner_map

Return value:
true on success
local SetUsbScannerAccessPermissions () -> boolean

Search the autodetected_scanners list for USB scanners and if at least one USB scanner was found, then create the file /etc/resmgr.conf.d/50-scanner.conf with an entry for each autodetected USB scanner like ----------------------------------------------------------------------------------- add usb:vendor=0x1234,product=0x5678 scanner add usb:vendor=0x1a2b,product=0x3c4d scanner ----------------------------------------------------------------------------------- and (re)-start and enable the service "resmgr" otherwise remove the file /etc/resmgr.conf.d/50-scanner.conf and (re)-start the service "resmgr". Ignore whether or not an autodetected USB scanner appears in the active_scanners list (i.e. simply grant access to all autodetected USB scanners) because on x86_64 "scanimage -L" cannot find scanners using the 32-bit epkowa backend (from the proprietary binary-only 32-bit-only "iscan" package for Epson scanners) so that in this case the scanner cannot appear in the active_scanners list but "sane-find-scanner" finds (almost all) Epson USB scanners so that the scanner is in the autodetected_scanners list.

Return value:
true on success
local SetScsiScannerAccessPermissions () -> boolean

Search the active_scanners list for possible SCSI scanners (":/dev/" in SANE device) and if at least one possible SCSI scanner was found, then run /etc/init.d/sane-dev (using "restart" to be safe that outdated permissions are reset) and enable it for reboot ("insserv") otherwise stop it and disable it for reboot ("insserv -r"). Note that it must search for ":/dev/" to find only SCSI scanners ("backend:/dev/sg...") because for example the hpaio backend may have also "/dev/" in its device, e.g.: "hpaio:/usb/HP_LaserJet_1220?device=/dev/usb/lp0", this depends on the particular model (e.g. when it doesn't report a serial number).

Return value:
true on success
local DependantPrintQueueExists (string backend_name) -> boolean

Test whether there exist a print queue which depends on the specified SANE backend. Examples: hpaio (package hplip): Setting up the hpaio backend requires to activate/start the hplip service. It may happen that the conflicting service ptal is in use by the CUPS printing system. I.e. there may be a print queue which uses the ptal CUPS backend. hpoj (package hp-officeJet): Setting up the hpoj backend requires to initialize/activate/start the ptal service. It may happen that the conflicting service hplip is in use by the CUPS printing system. I.e. there may be a print queue which uses the hp CUPS backend. Note: The test is only implememnted for the CUPS printing system. A dependant print queue can exists only for the SANE backends hpaio and hpoj. For all other backends no dependant print queue can exists.

Parameters:
backend_name string of the SANE backend name
Return value:
true if a dependant CUPS print queue exists for the backends hpaio or hpoj
global Read () -> boolean

Read all scanner settings: - Check installed packages - Read or create the scanner database - Determine active scanners - Determine active backends - Try to autodetect USB and SCSI scanners

Return value:
true on success
global Write () -> boolean

Write scanner settings: - Save the actual environment

Return value:
true on success
global RestartDetection () -> boolean

Restart the whole autodetection by calling all autodetection functions in the same order as during the initial Read(): DetermineActiveScanners results a new active_scanners map which is empty if nothing was detected or if DetermineActiveScanners fails. DetermineActiveBackends results a new active_backends list which is empty if nothing was detected or if DetermineActiveBackends fails. AutodetectScanners results a new autodetected_scanners map which is empty if nothing was detected or if AutodetectScanners fails. RestartDetection is called when the user restarts the detection in the OverviewDialog and if testing of an active scanner failed (see the TestBackend function). The result is that all information in the OverviewDialog is recreated.

Return value:
true in any case (errors result only empty maps or list).
global OverviewContents () -> list< map< string, any > >

Create the content for WizardHW::SetContents

Return value:
a list of maps with keys "id" : string = the identification of the device, "rich_descr" : string = RichText description of the device "table_descr" : list = fields of the table
global ModelItems (string filter_string) -> list

Create a list of items from the database entries which is used for the SelectionBox in the SelectModelDialog

Parameters:
filter_string string of a search string to return only matching models (retunr all models if filter_string is the empty string)
Return value:
of model strings (manufacturer, model, backend, comment)
global ActivateBackend (string backend_name, integer database_index, boolean user_confirmation) -> boolean

Activate the backend in /etc/sane.d/dll.conf according to the specified backend_name or if the specified backend_name is the empty string then set the backend_name according to a specified database_index.

Parameters:
backend_name string of a backend which should be activated (if backend_name is the empty string then database_index must be >= 0)
database_index integer which points to an entry in the model database (if backend_name is the empty string then the backend according to the database_index is used)
user_confirmation boolean true if user confirmation popup in case of problems is requested
Return value:
true on success
global DeactivateBackend (string backend_name, integer database_index, boolean user_confirmation) -> boolean

Deactivate the backend in /etc/sane.d/dll.conf according to the specified backend_name or if the specified backend_name is the empty string then set the backend_name according to a specified database_index.

Parameters:
backend_name string of a backend which should be deactivated (if backend_name is the empty string then database_index must be >= 0)
database_index integer which points to an entry in the model database (if backend_name is the empty string then the backend according to the database_index is used)
user_confirmation boolean true if user confirmation popup in case of problems is requested
Return value:
true on success
global TestBackend (string backend_name) -> boolean

Test the backend according to the specified backend_name.

Parameters:
backend_name string of a backend which should be tested
Return value:
true on success
global DetermineNetworkScanningConfig () -> boolean

Determine the network scanning config by calling a bash script which calls "grep ... /etc/sane.d/net.conf" and "grep ... /etc/sane.d/saned.conf" and processes its output and stores the results as YCP map in a temporary file and then read the temporary file (SCR::Read) to get the YCP map

Return value:
true on success
global SetupNetworkScanningConfig () -> boolean

Setup the network scanning config by calling a bash script which writes into /etc/sane.d/net.conf, /etc/sane.d/saned.conf, and /etc/xinetd.d/sane-port and reloads or starts the xinetd dependig on whether it is running or not

Return value:
true on success
global Import (map settings) -> boolean

Get all scanner settings from the first parameter. For use by autoinstallation.

Parameters:
settings The YCP structure to be imported.
Return value:
true on success
global Export () -> map

Dump the scanner settings to a single map. For use by autoinstallation.

Return value:
Dumped settings (later acceptable by Import ())
global AutoPackages () -> map

Return packages needed to be installed and removed during autoinstallation to insure module has all needed software installed.

Return value:
with 2 lists.