home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / foomatic-preferred-driver < prev    next >
Encoding:
Text File  |  2007-03-07  |  8.9 KB  |  344 lines

  1. #!/usr/bin/perl
  2.  
  3. # This is foomatic-preferred driver, it reads the printer database
  4. # overview and puts default driver entries (<driver>..</driver>) into
  5. # every printer's XML database entry.
  6.  
  7. use Foomatic::Defaults;
  8. use Foomatic::DB qw/get_overview/;
  9. use Data::Dumper;
  10. use strict;
  11. # Needs "get_overview" to be added to the "@EXPORT_OK" list of DB.pm!
  12.  
  13. # Read out the program name with which we were called, but discard the path
  14. $0 =~ m!/([^/]+)\s*$!;
  15. my $progname = $1;
  16. my $debug = 0;
  17.  
  18. my $db = new Foomatic::DB;
  19.  
  20. # Get the printer overview list as a Perl data structure
  21. $db->get_overview();
  22. print "DB " . Dumper($db ) if $debug;
  23.  
  24. my $printer;
  25. for $printer (@{$db->{'overview'}}) {
  26.     print "$printer->{'make'} $printer->{'model'} ($printer->{'id'})";
  27.     if ($printer->{'driver'}) { # We have already a default driver
  28.     # Check whether this driver is one which supports the printer
  29.     # If yes, this printer has a correct default driver so we do not
  30.     # need to set a new default driver
  31.     my $found = 0;
  32.     for my $d (@{$printer->{'drivers'}}) {
  33.         if ($d eq $printer->{'driver'}) {
  34.         $found = 1;
  35.         last;
  36.         }
  37.     }
  38.     if ($found) {
  39.         print " (Keeping old default driver): $printer->{'driver'}\n";
  40.         next;
  41.     } else {
  42.         print " (Default driver wrong)\n";
  43.     }
  44.     } else {
  45.     print " (No default driver defined)\n";
  46.     }
  47.     if ($printer->{'functionality'} eq 'F') {
  48.     # If the printer is a "Paperweight", do not correct the
  49.     # default driver, remove the wrong setting and skip the 
  50.     # printer
  51.     $printer->{'driver'} = "";
  52.     print ": --> Skipping \"Paperweight\"\n";
  53.     } else {
  54.     #Sort drivers appropriate to ranking list
  55.     my @sorted = sort sortdrivers @{$printer->{'drivers'}};
  56.     print ": @sorted --> $sorted[0]\n";
  57.     $printer->{'driver'} = $sorted[0];
  58.     }
  59.     open PRINTERENTRY, "< $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be read!\n";
  60.     my  @printerentryfield = <PRINTERENTRY>;
  61.     close PRINTERENTRY;
  62.     
  63.     my $printerentry = join ('', @printerentryfield);
  64.     if ($printerentry =~ m!<driver>(.*)</driver>!s) {
  65.     $printerentry =~ 
  66.       s!<driver>(.+)</driver>!<driver>$printer->{'driver'}</driver>!sg;
  67.     } elsif ($printerentry =~ m=(<!\-\-unknown preferred "driver"\-\->)=s){
  68.     $printerentry =~ 
  69.       s=(<!\-\-unknown preferred "driver"\-\->)=\n  <driver>$printer->{'driver'}</driver>=sg;
  70.     } elsif ($printerentry =~ m!<unverified\s*/>!s) {
  71.     $printerentry =~
  72.       s!<unverified\s*/>!<unverified />\n  <driver>$printer->{'driver'}</driver>!sg;
  73.     } elsif ($printerentry =~ m!</functionality>!s) {
  74.     $printerentry =~
  75.       s!</functionality>!</functionality>\n  <driver>$printer->{'driver'}</driver>!sg;
  76.     } else {
  77.     $printerentry =~
  78.       s!</model>!</model>\n  <driver>$printer->{'driver'}</driver>!sg;
  79.     }
  80.     open PRINTERENTRY, "> $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be written!\n";
  81.     print PRINTERENTRY $printerentry;
  82.     close PRINTERENTRY;
  83. }
  84.  
  85. exit 0;
  86.  
  87. sub sortdrivers ($$) {
  88.  
  89.     # All sorting done case-sensitive and characters which are not a letter
  90.     # or number are taken out!!
  91.  
  92.     # List of driver names in a ranking which driver should be preferred
  93.     # against other drivers.
  94.     # The terms must fit to the beginning of the line, terms which must fit
  95.     # exactly must have '\$' in the end.
  96.     my @drivers =      (
  97.             # Laser printers (except winprinters)
  98.             "epl5800", # Additional functionality for Epson
  99.             "epl2050", # Laser printers
  100.             "epl2050p",
  101.             "hl1250", # Special Brother drivers should be preferred
  102.             "hl1240", # for Brother printers
  103.                         "Postscript", # Tray selection, 1200+ dpi, color laser
  104.             "alc2000", # Epson color lasers print in color 
  105.             "alc8500", # with these drivers from Epson
  106.             "cljet5\$", # color laser PCL
  107.             "cljet5c",
  108.             "pxlcolor", # 1200 dpi color laser PCL
  109.             "pxlmono", # 1200 dpi, faster than "lj5gray"
  110.             "epl5900", # This driver has a bug, "pxlmono" works
  111.                    # correctly 
  112.             "lj5gray", # 1200 dpi
  113.             "lj5mono",
  114.             "ljet4\$", # HP laser drivers, the newer, the better
  115.             "ljet4d",
  116.             "lj4dithp",
  117.             "lj4dith\$",
  118.             "hl7x0", # Brother driver, proprietary language,
  119.                  # to prefer when there is also PCL
  120.                  # emulation
  121.             "ljet3d",
  122.             "ljet3\$",
  123.             "ljet2p",
  124.             "ljetplus",
  125.             "laserjet",
  126.             # HP PPA inkjets, when a printer is supported by one
  127.             # of these drivers, it is for sure not supported by
  128.             # any other driver.
  129.             "pnm2ppa", # color
  130.             "pbm2ppa", # bw
  131.             # Lexmark 3200, the Gimp-Print support for this
  132.             # printer is broken
  133.             "lxm3200-tweaked",
  134.             "lxm3200\$",
  135.             "lxm3200c",
  136.             "lxm3200m",
  137.             "lxm3200p",
  138.             # Canon BJC-8200, these UPPs are probably better
  139.             # than Gimp-Print
  140.             "bj8pa06n.upp",
  141.             "bj8oh06n.upp",
  142.             "bj8ts06n.upp",
  143.             "bj8gc12f.upp",
  144.             "bj8hg12f.upp",
  145.             "bj8pp12f.upp",
  146.             # HP and compatible inkjets
  147.             "hpijs-rss", # HP drivers, patched
  148.             "hpijs", # HP drivers, with Duplex and 1200 dpi
  149.             "cdj970", # Duplex support
  150.             "DJ", # HP drivers, but no duplex
  151.             "chp2200", # HP driver
  152.             "gimp-print-ijs", # IJS plug-in driver of Gimp-Print
  153.             "gimp-print", # Tray selection on laser, best 
  154.                       # quality on inkjets (for HP HP's
  155.                       # driver is better
  156.             "stp", # Predecessor of Gimp-Print
  157.             "cdj1600", # Relatively good drivers for HP inkjets
  158.             "cdj890",  # not covered by Gimp-Print or the HP
  159.             "cdj880",  # drivers
  160.             "cdj850",
  161.             "cdj670",
  162.             "pcl3", # When nothing else works ...
  163.             "hpdj", # Predecessor of pcl3
  164.             "sharp.upp", # Gets Sharp inkjets to work without
  165.                          # a lot of hassle
  166.             "cdj550\$",
  167.             "cdj550.upp",
  168.             "cdj500",
  169.             "djet500", # Somewhat old-fashioned
  170.             "deskjet",
  171.             # Canon inkjets
  172.             "s400a1.upp", # New printer, UPPs are probably 
  173.             "s400b1.upp", # better than "bjc600"/"bjc800"
  174.             "bjc800", # More flexible than the Uniprint drivers
  175.             "bjc600",
  176.             "bj200",
  177.             "bj10e",
  178.             "bjc6000a1.upp",
  179.             "bjc6000b1.upp",
  180.             "bjc610a0.upp",
  181.             "bjc610a1.upp",
  182.             "bjc610a2.upp",
  183.             "bjc610a3.upp",
  184.             "bjc610a4.upp",
  185.             "bjc610a5.upp",
  186.             "bjc610a6.upp",
  187.             "bjc610a7.upp",
  188.             "bjc610a8.upp",
  189.             "bjc610b1.upp",
  190.             "bjc610b2.upp",
  191.             "bjc610b3.upp",
  192.             "bjc610b4.upp",
  193.             "bjc610b6.upp",
  194.             "bjc610b7.upp",
  195.             "bjc610b8.upp",
  196.             # Epson inkjets
  197.             "st640ih.upp",
  198.             "st640ihg.upp",
  199.             "st640p.upp",
  200.             "st640pg.upp",
  201.             "st640pl.upp",
  202.             "st640plg.upp",
  203.             "stc640p.upp",
  204.             "Stp720p.upp",
  205.             "Stp720pl.upp",
  206.             "Stp870p.upp",
  207.             "Stp870pl.upp",
  208.             "stcolor",
  209.             "st800",
  210.             "PM760p.upp",
  211.             "PM760pl.upp",
  212.             "PM820p.upp",
  213.             "PM820pl.upp",
  214.             "Stc670p.upp",
  215.             "Stc670pl.upp",
  216.             "Stc680p.upp",
  217.             "Stc680pl.upp",
  218.             "Stc760p.upp",
  219.             "Stc760pl.upp",
  220.             "Stc777p.upp",
  221.             "Stc777pl.upp",
  222.             "stc1520h.upp",
  223.             "stc800ih.upp",
  224.             "stc800p.upp",
  225.             "stc800pl.upp",
  226.             "stc740ih.upp",
  227.             "stc740p.upp",
  228.             "stc740pl.upp",
  229.             "stc600ih.upp",
  230.             "stc600p.upp",
  231.             "stc600pl.upp",
  232.             "stc500p.upp",
  233.             "stc500ph.upp",
  234.             "stc300.upp",
  235.             "stc300bm.upp",
  236.             "stc300bl.upp",
  237.             "stc2.upp",
  238.             "stc2_h.upp",
  239.             "stc2s_h.upp",
  240.             "stc.upp",
  241.             "stc_h.upp",
  242.             "stc_l.upp",
  243.             "stcany.upp",
  244.             # Lexmark inkjets
  245.             "lz11",
  246.             "cZ11somsom",
  247.             "cZ11",
  248.             "lx5000",
  249.             "lex7000",
  250.             "lex5700",
  251.             "lx5700m",
  252.             "pbm2l7k",
  253.             # Thermo sublimation printers
  254.             "ppmtomd", # The successor of "ppmtocpva"
  255.             "ppmtocpva",
  256.             "md5k",
  257.             "md2k",
  258.             # Others
  259.             "t4693d8",
  260.             "t4693d4",
  261.             "t4693d2",
  262.             "necp2x.upp",
  263.             "necp2x6.upp",
  264.             "declj250", # More adjustable options
  265.             "lj250",
  266.             "pj", # More adjustable options
  267.             "paintjet",
  268.             "pjxl", # More adjustable options
  269.             "pjetxl",
  270.             "pjxl300",
  271.             "iwhi",
  272.             "iwlo",
  273.             "necp6",  # in most cases the NEC PinWriter P6 (+)
  274.             "epsonc", # is used without colour add-on.
  275.             "epson",
  276.             "eps9high",
  277.             "eps9mid",
  278.             "lq850",
  279.             "cjet",
  280.             "lbp8",
  281.             "oki182",
  282.             "ibmpro",
  283.             "gdi",
  284.             "pbmtozjs",
  285.             # Japanese printer drivers
  286.             "rpdl",
  287.             "pr201",
  288.             "pr150",
  289.             "picty180",
  290.             "npdl",
  291.             "ml600",
  292.             "mj8000c",
  293.             "mj700v2c",
  294.             "mj6000c",
  295.             "mj500c",
  296.             "md50Mono",
  297.             "md50Eco",
  298.             "md1xMono",
  299.             "lp2000",
  300.             "lj4dithp",
  301.             "lips4v",
  302.             "lips4",
  303.             "lips2p",
  304.             "lbp320",
  305.             "lbp310",
  306.             "jj100",
  307.             "fmpr",
  308.             "fmlbp",
  309.             "filter800_3300",
  310.             "filter800",
  311.             "filter770",
  312.             "filter760",
  313.             "escpage",
  314.             "dj505j",
  315.             "bjc880j",
  316.             "bjc800j",
  317.             "bj10vh",
  318.             "bj10v",
  319.             "bj10",
  320.             "sj48",
  321.             # Omni is in experimental state, so other drivers
  322.             # give probably better output
  323.             "omni"
  324.             );
  325.  
  326.     my $first = $_[0];
  327.     my $second = $_[1];
  328.     # The driver names to compare are absolutely equal ->
  329.     #    Bug in database ==> ignore
  330.     if ($first eq $second) {return 0};
  331.  
  332.     # Check whether they are in the @standardopts list
  333.     my $i;
  334.     for ($i = 0; $i <= $#drivers; $i++) {
  335.         my $firstinlist = ($first =~ /^$drivers[$i]/);
  336.         my $secondinlist = ($second =~ /^$drivers[$i]/);
  337.         if (($firstinlist) && (!$secondinlist)) {return -1};
  338.         if (($secondinlist) && (!$firstinlist)) {return 1};
  339.     }
  340.  
  341.     # No preference found, stop here
  342.     die "No preference found between $first and $second!\n";
  343. }
  344.