summaryrefslogtreecommitdiffstats
path: root/perl-install/printer
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2003-05-19 14:17:37 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2003-05-19 14:17:37 +0000
commit6e555c9eab6165f0794e4b43a322a51b201813c3 (patch)
treea8b897cbb7f3da2d5741630f5c4dfa22d40f2b88 /perl-install/printer
parent0d5106d1fc7aed594dd31930583fe7f62a3ec966 (diff)
downloaddrakx-6e555c9eab6165f0794e4b43a322a51b201813c3.tar
drakx-6e555c9eab6165f0794e4b43a322a51b201813c3.tar.gz
drakx-6e555c9eab6165f0794e4b43a322a51b201813c3.tar.bz2
drakx-6e555c9eab6165f0794e4b43a322a51b201813c3.tar.xz
drakx-6e555c9eab6165f0794e4b43a322a51b201813c3.zip
- (get_cups_autoconf, set_cups_autoconf, get_usermode, set_usermode): simplify
a lot through getVarsFromSh() and setVarsInSh() - (set_jap_textmode) simplify a lot through substInFile() now all /etc/sysconfig/printing accesses get done by MDK::Common::File (until shell template from libconf is used)
Diffstat (limited to 'perl-install/printer')
-rw-r--r--perl-install/printer/main.pm85
1 files changed, 13 insertions, 72 deletions
diff --git a/perl-install/printer/main.pm b/perl-install/printer/main.pm
index 24fd91bc5..6e70dfaad 100644
--- a/perl-install/printer/main.pm
+++ b/perl-install/printer/main.pm
@@ -576,6 +576,8 @@ sub read_ppd_options ($) {
return $COMBODATA->{args};
}
+my %sysconfig = getVarsFromSh("$::prefix/etc/sysconfig/printing");
+
sub set_cups_special_options {
my ($queue) = $_[0];
# Set some special CUPS options
@@ -600,95 +602,34 @@ sub set_cups_special_options {
}
sub set_cups_autoconf {
- my $autoconf = $_[0];
-
- # Read config file
- my $file = "$::prefix/etc/sysconfig/printing";
- my @file_content = cat_($file);
-
- # Remove all valid "CUPS_CONFIG" lines
- /^\s*CUPS_CONFIG/ and $_ = "" foreach @file_content;
-
- # Insert the new "CUPS_CONFIG" line
- if ($autoconf) {
- push @file_content, "CUPS_CONFIG=automatic\n";
- } else {
- push @file_content, "CUPS_CONFIG=manual\n";
- }
-
- output($file, @file_content);
-
- # Restart CUPS
- if ($autoconf) {
- printer::services::restart("cups");
- }
-
+ my ($autoconf) = @_;
+ $sysconfig{CUPS_CONFIG} = $autoconf ? "automatic" : "manual";
+ setVarsInSh("$::prefix/etc/sysconfig/printing", \%sysconfig);
return 1;
}
-sub get_cups_autoconf {
- local *F;
- open F, "< $::prefix/etc/sysconfig/printing" or return 1;
- while (my $line = <F>) {
- return 0 if $line =~ m!^[^\#]*CUPS_CONFIG=manual!;
- }
- return 1;
-}
+sub get_cups_autoconf { $sysconfig{CUPS_CONFIG} ne 'manual' ? 1 : 0 }
sub set_usermode {
- my $usermode = $_[0];
- $::expert = $usermode;
-
- # Read config file
- local *F;
- my $file = "$::prefix/etc/sysconfig/printing";
- my @file_content;
- if (!(-f $file)) {
- @file_content = ();
- } else {
- open F, "< $file" or die "Cannot open $file for reading!";
- @file_content = <F>;
- close F;
- }
-
- # Remove all valid "USER_MODE" lines
- (/^\s*USER_MODE/ and $_ = "") foreach @file_content;
-
- # Insert the new "USER_MODE" line
- if ($usermode) {
- push @file_content, "USER_MODE=expert\n";
- } else {
- push @file_content, "USER_MODE=recommended\n";
- }
-
- # Write back modified file
- open F, "> $file" or die "Cannot open $file for writing!";
- print F @file_content;
- close F;
-
+ my ($usermode) = @_;
+ setVarsInSh("$::prefix/etc/sysconfig/printing", { "USER_MODE" => $usermode ? "expert" : "recommended" });
return 1;
}
-sub get_usermode {
- my %cfg = getVarsFromSh("$::prefix/etc/sysconfig/printing");
- $::expert = $cfg{USER_MODE} eq 'expert' ? 1 : 0;
- return $::expert;
-}
+sub get_usermode() { $::expert = $sysconfig{USER_MODE} eq 'expert' ? 1 : 0 }
sub set_jap_textmode {
my $textmode = ($_[0] ? 'cjk' : '');
- my $file = "$::prefix/etc/cups/mime.convs";
- my @mimeconvs = cat_($file) or die "Cannot open $file for reading!";
- (s!^(\s*text/plain\s+\S+\s+\d+\s+)\S+(\s*$)!$1${textmode}texttops$2!)
- foreach @mimeconvs;
- output($file, @mimeconvs) or die "Cannot open $file for writing!";
+ substInFile {
+ s!^(\s*text/plain\s+\S+\s+\d+\s+)\S+(\s*$)!$1${textmode}texttops$2!
+ } "$::prefix/etc/cups/mime.convs";
return 1;
}
sub get_jap_textmode {
my @mimeconvs = cat_("$::prefix/etc/cups/mime.convs");
(m!^\s*text/plain\s+\S+\s+\d+\s+(\S+)\s*$!m and
- ($1 eq 'cjktexttops') and return 1) foreach @mimeconvs;
+ $1 eq 'cjktexttops' and return 1) foreach @mimeconvs;
return 0;
}