summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2007-03-22 11:47:38 +0000
committerThierry Vignaud <tv@mandriva.org>2007-03-22 11:47:38 +0000
commit0200a4d0a6ec77d322fd9091fe2938064c5f48bf (patch)
treec58ca35704c9bfe44bae888ed5a0fcfc1ba0b76d
parent804f38ad458f906c05b4954b68e16290a28ff855 (diff)
downloadmgaonline-0200a4d0a6ec77d322fd9091fe2938064c5f48bf.tar
mgaonline-0200a4d0a6ec77d322fd9091fe2938064c5f48bf.tar.gz
mgaonline-0200a4d0a6ec77d322fd9091fe2938064c5f48bf.tar.bz2
mgaonline-0200a4d0a6ec77d322fd9091fe2938064c5f48bf.tar.xz
mgaonline-0200a4d0a6ec77d322fd9091fe2938064c5f48bf.zip
Generated by svn2cl the jeu 22 mar 2007 12:44:10 CET
-rw-r--r--ChangeLog97
1 files changed, 97 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 49df3554..f3f0e687 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,100 @@
+2007-03-22 11:45 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet: hide "configure the service" menu
+ entry
+
+2007-03-21 23:36 kamberd
+
+ * soft/mdkonline/trunk/po/he.po: correction for Hebrew translation
+
+2007-03-21 22:58 kamberd
+
+ * soft/mdkonline/trunk/po/he.po: update translation for Hebrew
+
+2007-03-21 22:36 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/po/br.po: fix previous automatic commit
+
+2007-03-21 22:33 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/ChangeLog: Generated by svn2cl the mer 21
+ mar 2007 23:30:00 CET
+
+2007-03-21 22:33 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/Makefile: bump release (2.14)
+
+2007-03-21 22:33 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet, soft/mdkonline/trunk/po/af.po,
+ soft/mdkonline/trunk/po/ar.po, soft/mdkonline/trunk/po/az.po,
+ soft/mdkonline/trunk/po/bg.po, soft/mdkonline/trunk/po/bn.po,
+ soft/mdkonline/trunk/po/br.po, soft/mdkonline/trunk/po/bs.po,
+ soft/mdkonline/trunk/po/ca.po, soft/mdkonline/trunk/po/cs.po,
+ soft/mdkonline/trunk/po/cy.po, soft/mdkonline/trunk/po/da.po,
+ soft/mdkonline/trunk/po/de.po, soft/mdkonline/trunk/po/el.po,
+ soft/mdkonline/trunk/po/eo.po, soft/mdkonline/trunk/po/es.po,
+ soft/mdkonline/trunk/po/et.po, soft/mdkonline/trunk/po/eu.po,
+ soft/mdkonline/trunk/po/fa.po, soft/mdkonline/trunk/po/fi.po,
+ soft/mdkonline/trunk/po/fr.po, soft/mdkonline/trunk/po/fur.po,
+ soft/mdkonline/trunk/po/ga.po, soft/mdkonline/trunk/po/gl.po,
+ soft/mdkonline/trunk/po/he.po, soft/mdkonline/trunk/po/hi.po,
+ soft/mdkonline/trunk/po/hr.po, soft/mdkonline/trunk/po/hu.po,
+ soft/mdkonline/trunk/po/hy.po, soft/mdkonline/trunk/po/id.po,
+ soft/mdkonline/trunk/po/is.po, soft/mdkonline/trunk/po/it.po,
+ soft/mdkonline/trunk/po/ja.po, soft/mdkonline/trunk/po/ka.po,
+ soft/mdkonline/trunk/po/ko.po, soft/mdkonline/trunk/po/ku.po,
+ soft/mdkonline/trunk/po/ky.po, soft/mdkonline/trunk/po/lt.po,
+ soft/mdkonline/trunk/po/ltg.po, soft/mdkonline/trunk/po/lv.po,
+ soft/mdkonline/trunk/po/mdkonline.pot,
+ soft/mdkonline/trunk/po/mk.po, soft/mdkonline/trunk/po/mn.po,
+ soft/mdkonline/trunk/po/ms.po, soft/mdkonline/trunk/po/mt.po,
+ soft/mdkonline/trunk/po/nb.po, soft/mdkonline/trunk/po/nl.po,
+ soft/mdkonline/trunk/po/nn.po, soft/mdkonline/trunk/po/pa_IN.po,
+ soft/mdkonline/trunk/po/pl.po, soft/mdkonline/trunk/po/pt.po,
+ soft/mdkonline/trunk/po/pt_BR.po, soft/mdkonline/trunk/po/ro.po,
+ soft/mdkonline/trunk/po/ru.po, soft/mdkonline/trunk/po/sc.po,
+ soft/mdkonline/trunk/po/sk.po, soft/mdkonline/trunk/po/sl.po,
+ soft/mdkonline/trunk/po/sq.po, soft/mdkonline/trunk/po/sr.po,
+ soft/mdkonline/trunk/po/sr@Latn.po,
+ soft/mdkonline/trunk/po/sv.po, soft/mdkonline/trunk/po/ta.po,
+ soft/mdkonline/trunk/po/tg.po, soft/mdkonline/trunk/po/th.po,
+ soft/mdkonline/trunk/po/tl.po, soft/mdkonline/trunk/po/tr.po,
+ soft/mdkonline/trunk/po/uk.po, soft/mdkonline/trunk/po/ur.po,
+ soft/mdkonline/trunk/po/uz.po,
+ soft/mdkonline/trunk/po/uz@Latn.po,
+ soft/mdkonline/trunk/po/vi.po, soft/mdkonline/trunk/po/wa.po,
+ soft/mdkonline/trunk/po/zh_CN.po,
+ soft/mdkonline/trunk/po/zh_TW.po: really display which database
+ is locked
+
+2007-03-21 22:27 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet: add a "locked" status in order to
+ report clearly the issue
+
+2007-03-21 22:23 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/ChangeLog: Generated by svn2cl the mer 21
+ mar 2007 23:20:02 CET
+
+2007-03-21 22:22 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet: (harvester,silentCheck) remove
+ the timers that make the applet constantly polling (#29788)
+
+2007-03-21 22:19 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet: (harvester,silentCheck) fork the
+ updates checking in background, thus fixing:
+ - frozed applet while computing updates
+ - memory leak (15Mb on every check)
+
+2007-03-21 22:09 Thierry Vignaud <tvignaud at mandriva.com>
+
+ * soft/mdkonline/trunk/mdkapplet: (silentCheck) do not needlessly
+ create a new urpm object
+
2007-03-21 22:33 Thierry Vignaud <tvignaud at mandriva.com>
* soft/mdkonline/trunk/Makefile: bump release (2.14)
ref='#n260'>260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
package printer; # $Id$

use diagnostics;
use strict;

use vars qw(%thedb %thedb_gsdriver %printer_type %printer_type_inv @papersize_type %fields @entries_db_short @entry_db_description %descr_to_help %descr_to_db %db_to_descr %descr_to_ppd);

use common qw(:common :system :file);
use commands;

#-if we are in an DrakX config
my $prefix = "";

#-location of the printer database in an installed system
my $PRINTER_DB_FILE    = "/usr/lib/rhs/rhs-printfilters/printerdb";
my $PRINTER_FILTER_DIR = "/usr/lib/rhs/rhs-printfilters";

%printer_type = (
    __("Local printer")            => "LOCAL",
    __("Remote printer")           => "REMOTE",
    __("Remote CUPS server")       => "CUPS",
    __("Remote lpd server")        => "LPD",
    __("Network printer (socket)") => "SOCKET",
    __("SMB/Windows 95/98/NT")     => "SMB",
    __("NetWare")                  => "NCP",
    __("Printer Device URI")       => "URI",
);
%printer_type_inv = reverse %printer_type;

%fields = (
    STANDARD => [qw(QUEUE SPOOLDIR IF)],
    SPEC     => [qw(DBENTRY RESOLUTION PAPERSIZE BITSPERPIXEL CRLF)],
    LOCAL    => [qw(DEVICE)],
    REMOTE   => [qw(REMOTEHOST REMOTEQUEUE)],
    SMB      => [qw(SMBHOST SMBHOSTIP SMBSHARE SMBUSER SMBPASSWD SMBWORKGROUP AF)],
    NCP      => [qw(NCPHOST NCPQUEUE NCPUSER NCPPASSWD)],
);
@papersize_type = qw(letter legal ledger a3 a4);

#------------------------------------------------------------------------------
sub set_prefix($) { $prefix = $_[0]; }

sub default_queue($) { (split '\|', $_[0]{QUEUE})[0] }
sub default_spooldir($) { "/var/spool/lpd/" . default_queue($_[0]) }

sub default_printer_type($) { "LOCAL" }
sub printer_type($) {
    for ($_[0]{mode}) {
	/CUPS/ && return @printer_type_inv{qw(LOCAL REMOTE SMB), $::expert ? qw(URI) : ()};
	/lpr/  && return @printer_type_inv{qw(LOCAL LPD SMB NCP)};
    }
}

sub copy_printer_params($$) {
    my ($from, $to) = @_;
    map { $to->{$_} = $from->{$_} } grep { $_ ne 'configured' } keys %$from; #- avoid cycles.
}

sub getinfo($) {
    my ($prefix) = @_;
    my $printer = {};

    set_prefix($prefix);

    #- try to detect which printing system has been previously installed.
    #- the first detected is the default.
    read_printers_conf($printer); #- try to read existing cups (local only) queues.
    read_configured_queue($printer); #- try to read existing lpr queues.

    add2hash($printer, {
			#- global parameters.
			want         => 0,
			complete     => 0,
			str_type     => undef,
			QUEUE        => "lp",

			#- lpr parameters.
			SPOOLDIR     => "/var/spool/lpd/lp",
			DBENTRY      => "PostScript",
			PAPERSIZE    => "",
			ASCII_TO_PS  => undef,
			CRLF         => undef,
			NUP          => 1,
			RTLFTMAR     => 18,
			TOPBOTMAR    => 18,
			AUTOSENDEOF  => 1,

			DEVICE       => "/dev/lp0",

			REMOTEHOST   => "",
			REMOTEQUEUE  => "",

			NCPHOST      => "", #-"printerservername",
			NCPQUEUE     => "", #-"queuename",
			NCPUSER      => "", #-"user",
			NCPPASSWD    => "", #-"pass",

			SMBHOST      => "", #-"hostname",
			SMBHOSTIP    => "", #-"1.2.3.4",
			SMBSHARE     => "", #-"printername",
			SMBUSER      => "", #-"user",
			SMBPASSWD    => "", #-"passowrd",
			SMBWORKGROUP => "", #-"AS3",

			#- cups parameters.
			DeviceURI    => "parallel:/dev/lp0",
			Info         => "",
			Location     => "",
			State        => "Idle",
			Accepting    => "Yes",
		       });
    $printer;
}

#------------------------------------------------------------------------------
sub read_configured_queue($) {
    my ($printer) = @_;
    my $current = undef;
    my $flush_current = sub {
	if ($current) {
	    add2hash($printer->{configured}{$current->{QUEUE}} ||= {}, $current);
	    $current = undef;
	}
    };

    #- read /etc/printcap file.
    local *PRINTCAP; open PRINTCAP, "$prefix/etc/printcap" or return;
    foreach (<PRINTCAP>) {
	chomp;
	my $p = '(?:\{(.*?)\}|(\S+))';
	if (/^##PRINTTOOL3##\s+$p\s+$p\s+$p\s+$p\s+$p\s+$p\s+$p(?:\s+$p)?/) {
	    &$flush_current;
	    $current = {
			mode => 'lpr',
			TYPE => $1 || $2,
			GSDRIVER => $3 || $4,
			RESOLUTION => $5 || $6,
			PAPERSIZE => $7 || $8,
			#- ignored $9 || $10,
			DBENTRY => $11 || $12,
			BITSPERPIXEL => $13 || $14,
			CRLF => $15 || $16,
		       };
	} elsif (/^\s*$/) { &$flush_current }
	elsif (/^([^:]*):\\/) { $current->{QUEUE} = $1 }
	if (/^\s+:(?:[^:]*:)*sd=([^:]*):/) { $current->{SPOOLDIR} = $1 }
	if (/^\s+:(?:[^:]*:)*lp=([^:]*):\\/) { $current->{DEVICE} = $1 }
	if (/^\s+:(?:[^:]*:)*rm=([^:]*):\\/) { $current->{REMOTEHOST} = $1 }
	if (/^\s+:(?:[^:]*:)*rp=([^:]*):\\/) { $current->{REMOTEQUEUE} = $1 }
	if (/^\s+:(?:[^:]*:)*af=([^:]*):\\/) { $current->{AF} = $1 }
	if (/^\s+:(?:[^:]*:)*if=([^:]*):\\/) { $current->{IF} = $1 }
    }
    close PRINTCAP;
    &$flush_current;

    #- parse general.cfg for any configured queue.
    foreach (values %{$printer->{configured}}) {
	my $entry = $_;
	local *F; open F, "$prefix$entry->{SPOOLDIR}/general.cfg" or next;
	foreach (<F>) {
	    chomp;
	    if (/^\s*(?:export\s+)?PRINTER_TYPE=(.*?)\s*$/) { $entry->{TYPE} = $1 unless defined $entry->{TYPE} }
	    elsif (/^\s*(?:export\s+)?ASCII_TO_PS=(.*?)\s*$/) { $entry->{ASCII_TO_PS} = $1 eq 'YES' unless defined $entry->{ASCII_TO_PS} }
	    elsif (/^\s*(?:export\s+)?PAPER_SIZE=(.*?)\s*$/) { $entry->{PAPERSIZE} = $1 unless defined $entry->{PAPERSIZE} }
	}
	close F;
    }

    #- parse postscript.cfg for any configured queue.
    foreach (values %{$printer->{configured}}) {
	my $entry = $_;
	local *F; open F, "$prefix$entry->{SPOOLDIR}/postscript.cfg" or next;
	foreach (<F>) {
	    chomp;
	    if (/^\s*(?:export\s+)?GSDEVICE=(.*?)\s*$/) { $entry->{GSDRIVER} = $1 unless defined $entry->{GSDRIVER} }
	    elsif (/^\s*(?:export\s+)?RESOLUTION=(.*?)\s*$/) { $entry->{RESOLUTION} = $1 unless defined $entry->{RESOLUTION} }
	    elsif (/^\s*(?:export\s+)?COLOR=-dBitsPerPixel=(.*?)\s*$/) { $entry->{COLOR} = $1 unless defined $entry->{COLOR} }
	    elsif (/^\s*(?:export\s+)?COLOR=(.*?)\s*$/) { $entry->{COLOR} = $1 ? $1 : 'Default' unless defined $entry->{COLOR} }
	    elsif (/^\s*(?:export\s+)?PAPERSIZE=(.*?)\s*$/) { $entry->{PAPERSIZE} = $1 unless defined $entry->{PAPERSIZE} }
	    elsif (/^\s*(?:export\s+)?EXTRA_GS_OPTIONS=(.*?)\s*$/) { $entry->{EXTRA_GS_OPTIONS} = $1 unless defined $entry->{EXTRA_GS_OPTIONS}; $entry->{EXTRA_GS_OPTIONS} =~ s/^\"(.*)\"/$1/ }
	    elsif (/^\s*(?:export\s+)?REVERSE_ORDER=(.*?)\s*$/) { $entry->{REVERSE_ORDER} = $1 unless defined $entry->{REVERSE_ORDER} }
	    elsif (/^\s*(?:export\s+)?PS_SEND_EOF=(.*?)\s*$/) { $entry->{AUTOSENDEOF} = $1 eq 'YES' && $entry->{DBENTRY} eq 'PostScript' unless defined $entry->{AUTOSENDEOF} }
	    elsif (/^\s*(?:export\s+)?NUP=(.*?)\s*$/) { $entry->{NUP} = $1 unless defined $entry->{NUP} }
	    elsif (/^\s*(?:export\s+)?RTLFTMAR=(.*?)\s*$/) { $entry->{RTLFTMAR} = $1 unless defined $entry->{RTLFTMAR} }
	    elsif (/^\s*(?:export\s+)?TOPBOTMAR=(.*?)\s*$/) { $entry->{TOPBOTMAR} = $1 unless defined $entry->{TOPBOTMAR} }
	}
	close F;
    }

    #- parse textonly.cfg for any configured queue.
    foreach (values %{$printer->{configured}}) {
	my $entry = $_;
	local *F; open F, "$prefix$entry->{SPOOLDIR}/textonly.cfg" or next;
	foreach (<F>) {
	    chomp;
	    if (/^\s*(?:export\s+)?TEXTONLYOPTIONS=(.*?)\s*$/) { $entry->{TEXTONLYOPTIONS} = $1 unless defined $entry->{TEXTONLYOPTIONS}; $entry->{TEXTONLYOPTIONS} =~ s/^\"(.*)\"/$1/ }
	    elsif (/^\s*(?:export\s+)?CRLFTRANS=(.*?)\s*$/) { $entry->{CRLF} = $1 eq 'YES' unless defined $entry->{CRLF} }
	    elsif (/^\s*(?:export\s+)?TEXT_SEND_EOF=(.*?)\s*$/) { $entry->{AUTOSENDEOF} = $1 eq 'YES' && $entry->{DBENTRY} ne 'PostScript' unless defined $entry->{AUTOSENDEOF} }
	}
	close F;
    }

    #- get extra parameters for SMB or NCP type queue.
    foreach (values %{$printer->{configured}}) {
	my $entry = $_;
	if ($entry->{TYPE} eq 'SMB') {
	    my $config_file = "$prefix$entry->{SPOOLDIR}/.config";
	    local *F; open F, "$config_file" or next; #die "Can't open $config_file $!";
	    foreach (<F>) {
		chomp;
		if (/^\s*share='\\\\(.*?)\\(.*?)'/) {
		    $entry->{SMBHOST} = $1;
		    $entry->{SMBSHARE} = $2;
		} elsif (/^\s*hostip=(.*)/) {
		    $entry->{SMBHOSTIP} = $1;
		} elsif (/^\s*user='(.*)'/) {
		    $entry->{SMBUSER} = $1;
		} elsif (/^\s*password='(.*)'/) {
		    $entry->{SMBPASSWD} = $1;
		} elsif (/^\s*workgroup='(.*)'/) {
		    $entry->{SMBWORKGROUP} = $1;
		}
	    }
	    close F;
	} elsif ($entry->{TYPE} eq 'NCP') {
	    my $config_file = "$prefix$entry->{SPOOLDIR}/.config";
	    local *F; open F, "$config_file" or next; #die "Can't open $config_file $!";
	    foreach (<F>) {
		chomp;
		if (/^\s*server=(.*)/) {
		    $entry->{NCPHOST} = $1;
		} elsif (/^\s*user='(.*)'/) {
		    $entry->{NCPUSER} = $1;
		} elsif (/^\s*password='(.*)'/) {
		    $entry->{NCPPASSWD} = $1;
		} elsif (/^\s*queue='(.*)'/) {
		    $entry->{NCPQUEUE} = $1;
		}
	    }
	    close F;
	}
    }

    #- assume this printing system, but only if some queue are defined.
    scalar(keys %{$printer->{configured}}) > 0 and $printer->{mode} ||= 'lpr';
}

sub read_printer_db(;$) {
    my $dbpath = $prefix . ($_[0] || $PRINTER_DB_FILE);

    scalar(keys %thedb) > 4 and return; #- try reparse if using only ppa, POSTSCRIPT, TEXT.

    my %available_devices; #- keep only available devices in our database.
    local *AVAIL; open AVAIL, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/bin/gs --help |";
    foreach (<AVAIL>) {
	if (/^Available devices:/ ... /^\S/) {
	    @available_devices{split /\s+/, $_} = () if /^\s+/;
	}
    }
    close AVAIL;
    $available_devices{ppa} = undef; #- if -x "$prefix/usr/bin/pbm2ppa" && -x "$prefix/usr/bin/pnm2ppa";
    delete $available_devices{''};
    @available_devices{qw/POSTSCRIPT TEXT/} = (); #- these are always available.

    local $_; #- use of while (<...
    local *DBPATH; #- don't have to do close ... and don't modify globals at least
    open DBPATH, $dbpath or die "An error has occurred on $dbpath : $!";

    while (<DBPATH>) {
	if (/^StartEntry:\s(\w*)/) {
	    my $entry = { ENTRY => $1 };

	  WHILE :
	      while (<DBPATH>) {
		SWITCH: {
		      /GSDriver:\s*(\w*)/      and do { $entry->{GSDRIVER} = $1; last SWITCH };
		      /Description:\s*{(.*)}/  and do { $entry->{DESCR}    = $1; last SWITCH };
		      /About:\s*{\s*(.*?)\s*}/ and do { $entry->{ABOUT}    = $1; last SWITCH };
		      /About:\s*{\s*(.*?)\s*\\\s*$/
			and do {
			    my $string = $1;
			    while (<DBPATH>) {
				$string =~ /\S$/ and $string .= ' ';
				/^\s*(.*?)\s*\\\s*$/ and $string .= $1;
				/^\s*(.*?)\s*}\s*$/  and do { $entry->{ABOUT} = $string . $1; last SWITCH };
			    }
			};
		      /Resolution:\s*{(.*)}\s*{(.*)}\s*{(.*)}/
			and do { push @{$entry->{RESOLUTION} ||= []}, { XDPI => $1, YDPI => $2, DESCR => $3 }; last SWITCH };
		      /BitsPerPixel:\s*{(.*)}\s*{(.*)}/
			and do { push @{$entry->{BITSPERPIXEL} ||= []}, {DEPTH => $1, DESCR => $2}; last SWITCH };

		      /EndEntry/ and last WHILE;
		  }
	      }
	    if (exists $available_devices{$entry->{GSDRIVER}}) {
		$thedb{$entry->{ENTRY}} = $entry;
		$thedb_gsdriver{$entry->{GSDRIVER}} = $entry;
	    }
	}
    }

    @entries_db_short     = sort keys %printer::thedb;
    %descr_to_db          = map { $printer::thedb{$_}{DESCR}, $_ } @entries_db_short;
    %descr_to_help        = map { $printer::thedb{$_}{DESCR}, $printer::thedb{$_}{ABOUT} } @entries_db_short;
    @entry_db_description = keys %descr_to_db;
    %db_to_descr          = reverse %descr_to_db;
}

#------------------------------------------------------------------------------
sub read_printers_conf {
    my ($printer) = @_;
    my $current = undef;

    #- read /etc/cups/printers.conf file.
    #- according to this code, we are now using the following keys for each queues.
    #-    DeviceURI > lpd://printer6/lp
    #-    Info      > Info Text
    #-    Location  > Location Text
    #-    State     > Idle|Stopped
    #-    Accepting > Yes|No
    local *PRINTERS; open PRINTERS, "$prefix/etc/cups/printers.conf" or return;
    foreach (<PRINTERS>) {
	chomp;
	/^\s*#/ and next;
	if (/^\s*<(?:DefaultPrinter|Printer)\s+([^>]*)>/) { $current = { mode => 'CUPS', QUEUE => $1, } }
	elsif (/\s*<\/Printer>/) { $current->{QUEUE} && $current->{DeviceURI} or next; #- minimal check of synthax.
				   add2hash($printer->{configured}{$current->{QUEUE}} ||= {}, $current); $current = undef }
	elsif (/\s*(\S*)\s+(.*)/) { $current->{$1} = $2 }
    }
    close PRINTERS;

    #- assume this printing system.
    $printer->{mode} ||= 'CUPS';
}

sub get_direct_uri {
    #- get the local printer to access via a Device URI.
    my @direct_uri;
    local *F; open F, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/sbin/lpinfo -v |";
    foreach (<F>) {
	/^(direct|usb|serial)\s+(\S*)/ and push @direct_uri, $2;
    }
    close F;
    @direct_uri;
}

sub get_descr_from_ppd {
    my ($printer) = @_;
    my %ppd;

    #- if there is no ppd, this means this is the PostScript generic filter.
    local *F; open F, "$prefix/etc/cups/ppd/$printer->{QUEUE}.ppd" or return "Generic PostScript";
    foreach (<F>) {
	/^\*([^\s:]*)\s*:\s*\"([^\"]*)\"/ and do { $ppd{$1} = $2; next };
	/^\*([^\s:]*)\s*:\s*([^\s\"]*)/   and do { $ppd{$1} = $2; next };
    }
    close F;

    $ppd{Manufacturer} . '|' . ($ppd{NickName} || $ppd{ShortNickName} || $ppd{ModelName}) .
      ($ppd{LanguageVersion} && (" (" . lc(substr($ppd{LanguageVersion}, 0, 2)) . ")"));
}

sub poll_ppd_base {
    #- before trying to poll the ppd database available to cups, we have to make sure
    #- the file /etc/cups/ppds.dat is no more modified.
    #- if cups continue to modify it (because it reads the ppd files available), the
    #- poll_ppd_base program simply cores :-)
    run_program::rooted($prefix, "ifup lo"); #- else cups will not be happy!
    run_program::rooted($prefix, "/etc/rc.d/init.d/cups start");

    foreach (1..60) {
	local *PPDS; open PPDS, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/bin/poll_ppd_base -a |";
	foreach (<PPDS>) {
	    chomp;
	    my ($ppd, $mf, $descr, $lang) = split /\|/;
	    $ppd && $mf && $descr and $descr_to_ppd{"$mf|$descr" . ($lang && " ($lang)")} = $ppd;
	}
	close PPDS;
	scalar(keys %descr_to_ppd) > 5 and last;
	sleep 1; #- we have to try again running the program, wait here a little before.
    }

    scalar(keys %descr_to_ppd) > 5 or die "unable to connect to cups server";

    #- assume a default printer not using any ppd at all.
    $descr_to_ppd{"Generic PostScript"} = '';
}

#-******************************************************************************
#- write functions
#-******************************************************************************

#------------------------------------------------------------------------------
#- given the path queue_path, we create all the required spool directory
#------------------------------------------------------------------------------
sub create_spool_dir($) {
    my ($queue_path) = @_;
    my $complete_path = "$prefix/$queue_path";

    commands::mkdir_("-p", $complete_path);

    unless ($::testing) {
	#-redhat want that "drwxr-xr-x root lp"
	my $gid_lp = (getpwnam("lp"))[3];
	chown 0, $gid_lp, $complete_path
	  or die "An error has occurred - can't chgrp $complete_path to lp $!";
    }
}

#------------------------------------------------------------------------------
#-given the input spec file 'input', and the target output file 'output'
#-we set the fields specified by fieldname to the values in fieldval
#-nval  is the number of fields to set
#-Doesnt currently catch error exec'ing sed yet
#------------------------------------------------------------------------------
sub create_config_file($$%) {
    my ($inputfile, $outputfile, %toreplace) = @_;
    template2file("$prefix/$inputfile", "$prefix/$outputfile", %toreplace);
    eval { commands::chown_("root.lp", "$prefix/$outputfile") };
}


#------------------------------------------------------------------------------
#-copy master filter to the spool dir
#------------------------------------------------------------------------------
sub copy_master_filter($) {
    my ($queue_path) = @_;
    my $complete_path = "$prefix/$queue_path/filter";
    my $master_filter = "$prefix/$PRINTER_FILTER_DIR/master-filter";

    eval { commands::cp('-f', $master_filter, $complete_path) };
    $@ and die "Can't copy $master_filter to $complete_path $!";
    eval { commands::chown_("root.lp", $complete_path); };
}

#------------------------------------------------------------------------------
#- given a PrintCap Entry, create the spool dir and special
#- rhs-printfilters related config files which are required
#------------------------------------------------------------------------------
my $intro_printcap_test = "
#
# Please don't edit this file directly unless you know what you are doing!
# Look at the printcap(5) man page for more info.
# Be warned that the control-panel printtool requires a very strict format!
#
# This file can be edited with printerdrake or printtool.
#

";

sub configure_queue($) {
    my ($entry) = @_;

    for ($entry->{mode}) {
	/CUPS/ && do {
	    #- at this level, we are using lpadmin to create a local printer (only local
	    #- printer are supported with printerdrake).
	    require run_program;
	    run_program::rooted($prefix, "lpadmin",
				"-p", $entry->{QUEUE},
				$entry->{State} eq 'Idle' && $entry->{Accepting} eq 'Yes' ? ("-E") : (),
				"-v", $entry->{DeviceURI},
				$entry->{cupsPPD} ? ("-m", $entry->{cupsPPD}) : (),
				$entry->{Info} ? ("-D", $entry->{Info}) : (),
				$entry->{Location} ? ("-L", $entry->{Location}) : (),
			       );
	    last };
	/lpr/  && do {
	    #- old style configuration scheme for lpr.
	    my $queue_path = "$entry->{SPOOLDIR}";
	    create_spool_dir($queue_path);

	    my $get_name_file = sub {
		my ($name) = @_;
		("$PRINTER_FILTER_DIR/$name.in", "$entry->{SPOOLDIR}/$name")
	    };
	    my ($filein, $file);
	    my %fieldname = ();
	    my $dbentry = $thedb{($entry->{DBENTRY})} or die "no dbentry";

	    #- make general.cfg
	    ($filein, $file) = &$get_name_file("general.cfg");
	    $fieldname{ascps_trans} = $entry->{ASCII_TO_PS} || $dbentry->{GSDRIVER} eq 'ppa' ? "YES" : "NO";
	    $fieldname{desiredto}   = $dbentry->{GSDRIVER} ne "TEXT" ? "ps" : "asc";
	    $fieldname{papersize}   = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter";
	    $fieldname{printertype} = $entry->{TYPE};
	    create_config_file($filein, $file, %fieldname);

	    #- now do postscript.cfg