~ubuntu-branches/ubuntu/trusty/foomatic-db-engine/trusty

« back to all changes in this revision

Viewing changes to lib/Foomatic/DB.pm

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-06-30 10:59:21 UTC
  • mfrom: (1.2.6 upstream) (2.1.31 lucid)
  • Revision ID: james.westby@ubuntu.com-20100630105921-zyo2bf23qxxermg6
Tags: 4.0.4-1
* New upstream release (Closes: #532982)

* Remove foomatic-filters-ppds package: upstream has deprecated it.
  (Closes: #584355)

* Merge from Ubuntu:
  - postinst: PPD auto updaters:
    "If the package is updated, it is checked whether existing
     queues use PPDs of this package and if yes, the PPDs get
     updated." (Till)
  - Don't install the bug presubj for them.
  - Install the apport hook on Ubuntu
  - Merge the changelog entries.
  - Merge most package relationships.
  - Get rid of foomatic-db-hpijs references (deprecated upstream).
  - Cleanup descriptions

* Add myself to Uploaders as I'll help Chris in maintaining
  foomatic-db-engine.
* Convert to dh7 tiny style, cleanup packaging files.
  - Add fixPerlModulesInstall.patch to get them right.
* Fix some hyphen-used-as-minus lintian warnings by creating
  manpagesFixes.patch
* Add lintian overrides.
* debian/watch: update (Closes: #550751).
* Add Vcs-* fields with new packaging repository.
* Convert to 3.0 (quilt) source format.
* Bump Standards to 3.9.0.0 - Remove pre-oldstable Conflicts.

* Obviously acknowledge NMU. Thanks to Slávek Banko again!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1167
1167
                        die ("Given PPD file not found, neither as $ppddlpath nor as $ppdfile!\n");
1168
1168
                    }
1169
1169
                } else {
1170
 
                    $ppdfile =~ m:$basedir/(.*)$:;
1171
 
                    $ppddlpath = $1;
 
1170
                    $ppddlpath = $1 if $ppdfile =~ m:$basedir/(.*)$:;
1172
1171
                }
1173
1172
            } else {
1174
1173
                if (! -r $ppdfile) {
1176
1175
                }
1177
1176
                $ppddlpath = $ppdfile;
1178
1177
            }
 
1178
            if ($ppddlpath eq "") {
 
1179
                my $mk = $dat->{'id'};
 
1180
                $mk =~ s/^([^\-]+)\-.*$/$1/;
 
1181
                my $ppd = $ppdfile;
 
1182
                $ppd =~ s:^.*/([^/]+):$1:;
 
1183
                $ppddlpath = "PPD/$mk/$ppd";    
 
1184
            }
 
1185
            $ppddlpath =~ s/\.gz$//i;
1179
1186
        }
1180
1187
    }
1181
 
                              
 
1188
 
1182
1189
    if ($dat->{'driver'} =~ /Postscript/i) {
1183
1190
        $pdls = join(',', ($pdls, "POSTSCRIPT$dat->{'ppdpslevel'}"));
1184
1191
    } elsif ($dat->{'driver'} =~ /(pxl|pcl[\s\-]?xl)/i) {
1197
1204
    if ($pdls) {
1198
1205
        for my $l (split(',', $pdls)) {
1199
1206
            my ($lang, $level) = ('', '');
1200
 
            if ($l =~ /\b(PostScript|PS|BR-?Script)(\d?)\b/i) {
 
1207
            if ($l =~ /\b(PostScript|PS|BR-?Script|KPDL-?)\s*(\d?)\b/i) {
1201
1208
                $lang = "postscript";
1202
1209
                $level = $2;
1203
1210
            } elsif ($l =~ /\b(PDF)\b/i) {
1256
1263
                } else {
1257
1264
                    $drivers{'pxlmono'} = 1;
1258
1265
                    $drivers{'lj5gray'} = 1;
 
1266
                    $drivers{'lj5mono'} = 1;
1259
1267
                }
1260
1268
            } elsif ($level eq "5e") {
1261
1269
                $drivers{'ljet4d'} = 1;
1262
1270
                $drivers{'ljet4'} = 1;
1263
1271
                $drivers{'lj4dith'} = 1;
1264
 
                $drivers{'hpijs'} = 1;
 
1272
                if ($dat->{'make'} =~ /^(HP|Hewlett[\s-]+Packard)$/i) {
 
1273
                    $drivers{'hplip'} = 1;
 
1274
                } else {
 
1275
                    $drivers{'hpijs-pcl5e'} = 1;
 
1276
                }
1265
1277
                $drivers{'gutenprint'} = 1;
1266
1278
            } elsif ($level eq "5c") {
1267
1279
                $drivers{'cljet5'} = 1;
1268
 
                $drivers{'hpijs'} = 1;
 
1280
                if ($dat->{'make'} =~ /^(HP|Hewlett[\s-]+Packard)$/i) {
 
1281
                    $drivers{'hplip'} = 1;
 
1282
                } else {
 
1283
                    $drivers{'hpijs-pcl5c'} = 1;
 
1284
                }
1269
1285
            } elsif ($level eq "5") {
1270
1286
                $drivers{'ljet3d'} = 1;
1271
1287
                $drivers{'ljet3'} = 1;
1415
1431
            $line =~ m!^([^\"]*?)\s*\"!;
1416
1432
            $cmd .= " $1";
1417
1433
            $cmd =~ s/^\s*//;
1418
 
            $dat->{'ppdproduct'} = unhexify($cmd);
1419
 
            $dat->{'ppdproduct'} =~ s/^\s*\(\s*//;
1420
 
            $dat->{'ppdproduct'} =~ s/\s*\)\s*$//;
 
1434
            my $ppdproduct = unhexify($cmd);
 
1435
            $ppdproduct =~ s/^\s*\(\s*//;
 
1436
            $ppdproduct =~ s/\s*\)\s*$//;
 
1437
            @{$dat->{'ppdproduct'}} = ()
 
1438
                if !defined($dat->{'ppdproduct'});
 
1439
            push(@{$dat->{'ppdproduct'}}, $ppdproduct);
1421
1440
        } elsif (m!^\*Manufacturer:\s*\"(.*)$!) {
1422
1441
            # "*Manufacturer: <code>"
1423
1442
            my $line = $1;
2087
2106
        ($dat->{'make'}, $dat->{'model'}) = guessmake($dat->{'makemodel'});
2088
2107
        $dat->{'model'} =~ s/^(.*?)\s*(,|Foomatic|CUPS|\(?\d+\.\d+\)?)/$1/i;
2089
2108
    }
2090
 
    if (defined($dat->{'general_mdl'})) {
 
2109
    if (defined($dat->{'ppdmodelname'})) {
 
2110
        (my $dummy, $dat->{'model'}) = guessmake($dat->{'ppdmodelname'});
 
2111
    } elsif (defined($dat->{'ppdproduct'}) &&
 
2112
             (scaler(@{$dat->{'ppdproduct'}}) == 1)) {
 
2113
        $dat->{'model'} = $dat->{'ppdproduct'}[0];
 
2114
    } elsif (!$dat->{'model'} && defined($dat->{'general_mdl'})) {
2091
2115
        $dat->{'model'} = $dat->{'general_mdl'};
2092
 
    } elsif (defined($dat->{'ppdmodelname'})) {
2093
 
        $dat->{'model'} = guessmake($dat->{'ppdmodelname'});
2094
 
    } elsif (!$dat->{'model'} && defined($dat->{'ppdproduct'})) {
2095
 
        $dat->{'model'} = $dat->{'ppdproduct'};
 
2116
    } elsif (defined($dat->{'ppdproduct'})) {
 
2117
        $dat->{'model'} = $dat->{'ppdproduct'}[0];
2096
2118
    }
2097
2119
    $dat->{'make'} = clean_manufacturer_name($dat->{'make'});
2098
2120
    $dat->{'model'} = clean_manufacturer_name($dat->{'model'});
2106
2128
    # and *Product fields of the PPD.
2107
2129
    $dat->{'general_mfg'} = $dat->{'ppdmanufacturer'} if 
2108
2130
        $dat->{'ppdmanufacturer'} && !$dat->{'general_mfg'};
2109
 
    $dat->{'general_mdl'} = $dat->{'ppdproduct'} if 
 
2131
    $dat->{'general_mdl'} = $dat->{'ppdproduct'}[0] if 
2110
2132
        $dat->{'ppdproduct'} && !$dat->{'general_mdl'};
2111
2133
    $dat->{'general_ieee'} = "MFG:" . $dat->{'general_mfg'} .
2112
2134
        ";MDL:" . $dat->{'general_mdl'} . ";" if 
2114
2136
        !$dat->{'general_ieee'};
2115
2137
 
2116
2138
    # Generate the Foomatic printer ID
2117
 
    if (!$dat->{'id'}) {
2118
 
        my $mk = $dat->{'make'};
2119
 
        $mk =~ s/\s+/_/g;
2120
 
        $mk =~ s/\+/plus/g;
2121
 
        $mk =~ s/[^A-Za-z0-9\._]/_/g;
2122
 
        $mk =~ s/_+/_/g;
2123
 
        $mk =~ s/^_//;
2124
 
        $mk =~ s/_$//;
2125
 
        my $md = $dat->{'model'};
2126
 
        $md =~ s/\s+/_/g;
2127
 
        $md =~ s/\+/plus/g;
2128
 
        $md =~ s/[^A-Za-z0-9\.\-]/_/g;
2129
 
        $md =~ s/_+/_/g;
2130
 
        $md =~ s/^_//;
2131
 
        $md =~ s/_$//;
2132
 
        $dat->{'id'} = "$mk-$md";
2133
 
    }
 
2139
    $dat->{'id'} = generatepid($dat->{'make'}, $dat->{'model'})
 
2140
        if !$dat->{'id'};
2134
2141
 
2135
2142
    # Find out printer's page description languages and suitable drivers
 
2143
    if (!defined($parameters->{'drivers'})) {
 
2144
        $parameters->{'drivers'} = [$dat->{'driver'}];
 
2145
    }
 
2146
    if (!defined($parameters->{'pdls'})) {
 
2147
        $parameters->{'pdls'} = [split(',', $dat->{'general_cmd'})];
 
2148
    } else {
 
2149
        push(@{$parameters->{'pdls'}}, split(',', $dat->{'general_cmd'}));
 
2150
    }
2136
2151
    apply_driver_and_pdl_info($dat, $parameters);
2137
2152
 
2138
2153
    # Find the maximum resolution
2208
2223
    return $dat;
2209
2224
}
2210
2225
 
 
2226
sub generatepid {
 
2227
    # Generate the Foomatic printer ID
 
2228
    my ($mk, $md) = @_;
 
2229
    $mk =~ s/\s+/_/g;
 
2230
    $mk =~ s/\+/plus/g;
 
2231
    $mk =~ s/[^A-Za-z0-9\._]/_/g;
 
2232
    $mk =~ s/_+/_/g;
 
2233
    $mk =~ s/^_//;
 
2234
    $mk =~ s/_$//;
 
2235
    $md =~ s/\s+/_/g;
 
2236
    $md =~ s/\+/plus/g;
 
2237
    $md =~ s/[^A-Za-z0-9\.\-]/_/g;
 
2238
    $md =~ s/_+/_/g;
 
2239
    $md =~ s/^_//;
 
2240
    $md =~ s/_$//;
 
2241
    return "$mk-$md";
 
2242
}
 
2243
 
2211
2244
sub perltoxml {
2212
2245
    my ($this, $mode) = @_;
2213
2246
 
3192
3225
sub ppd1284DeviceID {
3193
3226
 
3194
3227
    # Clean up IEEE-1284 device ID to only contain the fields relevant
3195
 
    # to printer model auto-detection (MFG, MDL, DES, CMD, SKU), thus
 
3228
    # to printer model auto-detection (MFG, MDL, DES, CMD, SKU, DRV), thus
3196
3229
    # the line length limit of PPDs does not get exceeded on very long
3197
3230
    # ID strings.
3198
3231
 
3199
3232
    my ($id) = @_;
3200
3233
    my $ppdid = "";
3201
3234
    
3202
 
    foreach my $field ("(MFG|MANUFACTURER)", "(MDL|MODEL)", "(CMD|COMMANDS?\s*SET)", "(DES|DESCRIPTION)", "SKU", "DRV") {
 
3235
    foreach my $field ("(MFG|MANUFACTURER)", "(MDL|MODEL)", "(CMD|COMMANDS?\\s*SET)", "(DES|DESCRIPTION)", "SKU", "DRV") {
3203
3236
        if ($id =~ m/(\b$field:\s*[^:;]+;?)/is) {
3204
 
            $ppdid .= $1;
 
3237
            my $f = $1;
 
3238
            $ppdid .= ";" if $ppdid && $ppdid !~ /;$/;
 
3239
            $ppdid .= $f;
3205
3240
        }
3206
3241
    }
3207
3242
 
3277
3312
            }
3278
3313
        }
3279
3314
    }
 
3315
    $ieee1284 .= ";" if $ieee1284 && $ieee1284 !~ /;$/;
3280
3316
    $ieee1284 .= "DRV:D$driver" .
3281
3317
        ($recdriver ? ($driver eq $recdriver ? ",R1" : ",R0") : "") .
3282
3318
        "$drvfield;";
4247
4283
                 sprintf("\n*${jcl}OpenUI *%s/%s: Boolean\n", $name, 
4248
4284
                         cutguiname($com, $shortgui)));
4249
4285
 
4250
 
            if ($arg->{'style'} eq 'G' || $optstyle == "JCL") {
 
4286
            if ($arg->{'style'} eq 'G' || $optstyle eq "JCL") {
4251
4287
                # Ghostscript argument
4252
4288
                $psstr = $cmd;
4253
4289
                # Boolean options should not use the "%s" default for $cmd
4939
4975
                s/(?<=[a-zA-Z0-9])[^a-zA-Z0-9]+[a-zA-Z0-9]*$//;
4940
4976
            my $new =
4941
4977
                "$parts{'make'} $parts{'model'}, $parts{'driver'}";
4942
 
            last if ($new == $shortnickname);
 
4978
            last if ($new eq $shortnickname);
4943
4979
            $shortnickname = $new;
4944
4980
        }
4945
4981
        if (length($shortnickname) > 31) {
4949
4985
    }
4950
4986
 
4951
4987
    my $color;
4952
 
    if ($dat->{'color'}) {
 
4988
    if ($dat->{'color'} &&
 
4989
        (!defined($dat->{'drvcolor'}) || ($dat->{'drvcolor'} != 0))) {
4953
4990
        $color = "*ColorDevice: True\n*DefaultColorSpace: RGB";
4954
4991
    } else {
4955
4992
        $color = "*ColorDevice: False\n*DefaultColorSpace: Gray";
4966
5003
            $dat->{$type} = '';
4967
5004
        }
4968
5005
    }
4969
 
    my $extralines = $dat->{'printerppdentry'} .
4970
 
                     $dat->{'driverppdentry'} .
4971
 
                     $dat->{'comboppdentry'};
 
5006
    my $extralines = ($dat->{'comboppdentry'} ?
 
5007
                      $dat->{'comboppdentry'} :
 
5008
                      $dat->{'printerppdentry'} .
 
5009
                      $dat->{'driverppdentry'});
4972
5010
 
4973
5011
    my $tmpl = get_tmpl();
4974
5012
    $tmpl =~ s!\@\@POSTPIPE\@\@!$postpipe!g;
5271
5309
*cupsModelNumber:  2
5272
5310
*cupsFilter:    "application/vnd.cups-postscript 100 foomatic-rip"
5273
5311
*cupsFilter:    "application/vnd.cups-pdf 0 foomatic-rip"
5274
 
*cupsFilter:    "application/vnd.apple-pdf 25 foomatic-rip"
5275
5312
*%pprRIP:        foomatic-rip other
5276
5313
*ModelName:     "\@\@MODEL\@\@"
5277
5314
*ShortNickName: "\@\@SHORTNICKNAME\@\@"
5289
5326
*PSVersion:     "(3010.000) 861"
5290
5327
*PSVersion:     "(3010.000) 862"
5291
5328
*PSVersion:     "(3010.000) 863"
 
5329
*PSVersion:     "(3010.000) 864"
 
5330
*PSVersion:     "(3010.000) 870"
5292
5331
*LanguageLevel: "3"
5293
5332
\@\@COLOR\@\@
5294
5333
*FileSystem:    False