home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl5 / Debconf / FrontEnd / Passthrough.pm < prev    next >
Encoding:
Perl POD Document  |  2006-07-24  |  6.4 KB  |  290 lines

  1. #!/usr/bin/perl -w
  2. # This file was preprocessed, do not edit!
  3.  
  4.  
  5. package Debconf::FrontEnd::Passthrough;
  6. use strict;
  7. use Carp;
  8. use IO::Socket;
  9. use IO::Handle;
  10. use Debconf::FrontEnd;
  11. use Debconf::Element;
  12. use Debconf::Element::Select;
  13. use Debconf::Element::Multiselect;
  14. use Debconf::Log qw(:all);
  15. use Debconf::Encoding;
  16. use base qw(Debconf::FrontEnd);
  17.  
  18. my ($READFD, $WRITEFD, $SOCKET);
  19. if (defined $ENV{DEBCONF_PIPE}) {
  20.         $SOCKET = $ENV{DEBCONF_PIPE};
  21. } elsif (defined $ENV{DEBCONF_READFD} && defined $ENV{DEBCONF_WRITEFD}) {
  22.         $READFD = $ENV{DEBCONF_READFD};
  23.         $WRITEFD = $ENV{DEBCONF_WRITEFD};
  24. } else {
  25.         die "Neither DEBCONF_PIPE nor DEBCONF_READFD and DEBCONF_WRITEFD were set\n";
  26. }
  27.  
  28.  
  29. sub init {
  30.     my $this=shift;
  31.  
  32.         if (defined $SOCKET) {
  33.                 $this->{readfh} = $this->{writefh} = IO::Socket::UNIX->new(
  34.                 Type => SOCK_STREAM,
  35.                 Peer => $SOCKET
  36.             ) || croak "Cannot connect to $SOCKET: $!";
  37.         } else {
  38.                 $this->{readfh} = IO::Handle->new_from_fd(int($READFD), "r") || croak "Failed to open fd $READFD: $!";
  39.                 $this->{writefh} = IO::Handle->new_from_fd(int($WRITEFD), "w") || croak "Failed to open fd $WRITEFD: $!";
  40.         }
  41.  
  42.     binmode $this->{readfh}, ":utf8";
  43.     binmode $this->{writefh}, ":utf8";
  44.  
  45.     $this->{readfh}->autoflush(1);
  46.     $this->{writefh}->autoflush(1);
  47.     
  48.     $this->SUPER::init(@_);
  49.     $this->interactive(1);
  50. }
  51.  
  52.  
  53. sub talk {
  54.     my $this=shift;
  55.     my $command=join(' ', map { Debconf::Encoding::to_Unicode($_) } @_);
  56.     my $reply;
  57.     
  58.     my $readfh = $this->{readfh} || croak "Broken pipe";
  59.     my $writefh = $this->{writefh} || croak "Broken pipe";
  60.     
  61.     debug developer => "----> $command";
  62.     print $writefh $command."\n";
  63.     $writefh->flush;
  64.     $reply = <$readfh>;
  65.     chomp($reply);
  66.     debug developer => "<---- $reply";
  67.     my ($tag, $val) = split(' ', $reply, 2);
  68.     $val = '' unless defined $val;
  69.     $val = Debconf::Encoding::convert("UTF-8", $val);
  70.  
  71.     return ($tag, $val) if wantarray;
  72.     return $tag;
  73. }
  74.  
  75.  
  76. sub makeelement
  77. {
  78.     my $this=shift;
  79.     my $question=shift;
  80.  
  81.     my $type=$question->type;
  82.     if ($type eq "select" || $type eq "multiselect") {
  83.         $type=ucfirst($type);
  84.         return "Debconf::Element::$type"->new(question => $question);
  85.     } else {
  86.         return Debconf::Element->new(question => $question);
  87.     }
  88. }
  89.  
  90.  
  91. sub capb_backup
  92. {
  93.     my $this=shift;
  94.     my $val = shift;
  95.  
  96.     $this->{capb_backup} = $val;
  97.     $this->talk('CAPB', 'backup') if $val;
  98. }
  99.  
  100.  
  101. sub capb
  102. {
  103.     my $this=shift;
  104.     my $ret;
  105.     return $this->{capb} if exists $this->{capb};
  106.  
  107.     ($ret, $this->{capb}) = $this->talk('CAPB');
  108.     return $this->{capb} if $ret eq '0';
  109. }
  110.  
  111.  
  112. sub title
  113. {
  114.     my $this = shift;
  115.     return $this->{title} unless @_;
  116.     my $title = shift;
  117.  
  118.     $this->{title} = $title;
  119.     $this->talk('TITLE', $title);
  120. }
  121.  
  122.  
  123. sub settitle
  124. {
  125.     my $this = shift;
  126.     my $question = shift;
  127.  
  128.     $this->{title} = $question->description;
  129.  
  130.     my $tag = $question->template->template;
  131.     my $type = $question->template->type;
  132.     my $desc = $question->description;
  133.     my $extdesc = $question->extended_description;
  134.  
  135.     $this->talk('DATA', $tag, 'type', $type);
  136.  
  137.     if ($desc) {
  138.         $desc =~ s/\n/\\n/g;
  139.         $this->talk('DATA', $tag, 'description', $desc);
  140.     }
  141.  
  142.     if ($extdesc) {
  143.         $extdesc =~ s/\n/\\n/g;
  144.         $this->talk('DATA', $tag, 'extended_description', $extdesc);
  145.     }
  146.  
  147.     $this->talk('SETTITLE', $tag);
  148. }
  149.  
  150.  
  151. sub go {
  152.     my $this = shift;
  153.  
  154.     my @elements=grep $_->visible, @{$this->elements};
  155.     foreach my $element (@elements) {
  156.         my $question = $element->question;
  157.         my $tag = $question->template->template;
  158.         my $type = $question->template->type;
  159.         my $desc = $question->description;
  160.         my $extdesc = $question->extended_description;
  161.         my $default;
  162.         if ($type eq 'select') {
  163.             $default = $element->translate_default;
  164.         } elsif ($type eq 'multiselect') {
  165.             $default = join ', ', $element->translate_default;
  166.         } else {
  167.             $default = $question->value;
  168.         }
  169.  
  170.                 $this->talk('DATA', $tag, 'type', $type);
  171.  
  172.         if ($desc) {
  173.             $desc =~ s/\n/\\n/g;
  174.             $this->talk('DATA', $tag, 'description', $desc);
  175.         }
  176.  
  177.         if ($extdesc) {
  178.             $extdesc =~ s/\n/\\n/g;
  179.             $this->talk('DATA', $tag, 'extended_description',
  180.                         $extdesc);
  181.         }
  182.  
  183.         if ($type eq "select" || $type eq "multiselect") {
  184.             my $choices = $question->choices;
  185.             $choices =~ s/\n/\\n/g if ($choices);
  186.             $this->talk('DATA', $tag, 'choices', $choices);
  187.         }
  188.  
  189.         $this->talk('SET', $tag, $default) if $default ne '';
  190.  
  191.         my @vars=$Debconf::Db::config->variables($question->{name});
  192.         for my $var (@vars) {
  193.             my $val=$Debconf::Db::config->getvariable($question->{name}, $var);
  194.             $val='' unless defined $val;
  195.             $this->talk('SUBST', $tag, $var, $val);
  196.         }
  197.  
  198.         $this->talk('INPUT', $question->priority, $tag);
  199.     }
  200.  
  201.     if (@elements && (scalar($this->talk('GO')) eq "30") && $this->{capb_backup}) {
  202.         return;
  203.     }
  204.     
  205.     foreach my $element (@{$this->elements}) {
  206.         if ($element->visible) {
  207.             my $tag = $element->question->template->template;
  208.             my $type = $element->question->template->type;
  209.  
  210.             my ($ret, $val)=$this->talk('GET', $tag);
  211.             if ($ret eq "0") {
  212.                 if ($type eq 'select') {
  213.                     $element->value($element->translate_to_C($val));
  214.                 } elsif ($type eq 'multiselect') {
  215.                     $element->value(join(', ', map { $element->translate_to_C($_) } split(', ', $val)));
  216.                 } else {
  217.                     $element->value($val);
  218.                 }
  219.                 debug developer => "Got \"$val\" for $tag";
  220.             }
  221.         } else {
  222.             my $default='';
  223.             $default=$element->question->value if defined $element->question->value;
  224.             $element->value($default);
  225.         }
  226.     }
  227.  
  228.     return 1;
  229. }
  230.  
  231.  
  232. sub progress_data {
  233.     my $this=shift;
  234.     my $subcommand=shift;
  235.     my $question=shift;
  236.  
  237.     my $tag=$question->template->template;
  238.     my $type=$question->template->type;
  239.     my $desc=$question->description;
  240.     my $extdesc=$question->extended_description;
  241.  
  242.     $this->talk('DATA', $tag, 'type', $type);
  243.  
  244.     if ($desc) {
  245.         $desc =~ s/\n/\\n/g;
  246.         $this->talk('DATA', $tag, 'description', $desc);
  247.     }
  248.  
  249.     if ($extdesc) {
  250.         $extdesc =~ s/\n/\\n/g;
  251.         $this->talk('DATA', $tag, 'extended_description', $extdesc);
  252.     }
  253. }
  254.  
  255. sub progress_start {
  256.     my $this=shift;
  257.  
  258.     $this->progress_data('START', $_[2]);
  259.     return $this->talk('PROGRESS', 'START', $_[0], $_[1], $_[2]->template->template);
  260. }
  261.  
  262. sub progress_set {
  263.     my $this=shift;
  264.  
  265.     return $this->talk('PROGRESS', 'SET', $_[0]);
  266. }
  267.  
  268. sub progress_step {
  269.     my $this=shift;
  270.  
  271.     return $this->talk('PROGRESS', 'STEP', $_[0]);
  272. }
  273.  
  274. sub progress_info {
  275.     my $this=shift;
  276.  
  277.     $this->progress_data('INFO', $_[0]);
  278.     return $this->talk('PROGRESS', 'INFO', $_[0]->template->template);
  279. }
  280.  
  281. sub progress_stop {
  282.     my $this=shift;
  283.  
  284.     return $this->talk('PROGRESS', 'STOP');
  285. }
  286.  
  287.  
  288. 1
  289.  
  290.