ruby-foomatic 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/lib/foomatic.rb +39 -0
- data/lib/foomatic/version.rb +3 -0
- data/spec/db/source/printer/HP-LaserJet_1200.xml +165 -0
- data/spec/foomatic_spec.rb +22 -0
- data/spec/spec_helper.rb +4 -0
- metadata +103 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Edgars Beigarts
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# ruby-foomatic
|
2
|
+
|
3
|
+
Ruby interface to the [Foomatic printer database](http://www.linuxfoundation.org/collaborate/workgroups/openprinting/databasefoomatic).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ apt-get install foomatic-db
|
9
|
+
```
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ gem install ruby-foomatic
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "foomatic"
|
19
|
+
foomatic = Foomatic::DB.open("/usr/share/foomatic/db")
|
20
|
+
foomatic.printers.each do |printer|
|
21
|
+
puts printer.inspect
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/lib/foomatic.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "nokogiri"
|
3
|
+
require "foomatic/version"
|
4
|
+
|
5
|
+
module Foomatic
|
6
|
+
class DB
|
7
|
+
def self.open(path = "/usr/share/foomatic/db")
|
8
|
+
new(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :path
|
12
|
+
|
13
|
+
def initialize(path)
|
14
|
+
@path = Pathname.new(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def printers
|
18
|
+
path.join("source", "printer").each_child.map do |f|
|
19
|
+
xml = Nokogiri::XML.parse(f)
|
20
|
+
Printer.new.tap do |printer|
|
21
|
+
printer.id = xml.root.attribute("id").to_s
|
22
|
+
printer.make = xml.root.xpath("make").text
|
23
|
+
printer.model = xml.root.xpath("model").text
|
24
|
+
printer.url = xml.root.xpath("url").text
|
25
|
+
Printer::MECHANISM_TYPES.each do |type|
|
26
|
+
printer.send("#{type}=", xml.root.xpath("mechanism/#{type}").any?)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Printer
|
34
|
+
attr_accessor :id, :make, :model, :url
|
35
|
+
MECHANISM_TYPES = [:laser, :led, :inkjet, :dotmatrix, :impact, :sublimation, :transfer, :thermal, :color]
|
36
|
+
attr_accessor(*MECHANISM_TYPES)
|
37
|
+
MECHANISM_TYPES.each { |type| alias_method(:"#{type}?", type) }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
<printer id="printer/HP-LaserJet_1200">
|
2
|
+
<make>HP</make>
|
3
|
+
<model>LaserJet 1200</model>
|
4
|
+
<mechanism>
|
5
|
+
<laser />
|
6
|
+
<resolution>
|
7
|
+
<dpi>
|
8
|
+
<x>1200</x>
|
9
|
+
<y>1200</y>
|
10
|
+
</dpi>
|
11
|
+
</resolution>
|
12
|
+
</mechanism>
|
13
|
+
<url>http://hpshopping.speedera.net/www.shopping.hp.com/shopping/pdf/lj1200.pdf</url>
|
14
|
+
<lang>
|
15
|
+
<postscript level="2" />
|
16
|
+
<pcl level="6" />
|
17
|
+
<pjl />
|
18
|
+
<text>
|
19
|
+
<charset>us-ascii</charset>
|
20
|
+
</text>
|
21
|
+
</lang>
|
22
|
+
<autodetect>
|
23
|
+
<general>
|
24
|
+
<commandset>PJL,MLC,PCL,PCLXL,POSTSCRIPT</commandset>
|
25
|
+
<manufacturer>Hewlett-Packard</manufacturer>
|
26
|
+
<model>HP LaserJet 1200</model>
|
27
|
+
</general>
|
28
|
+
<usb>
|
29
|
+
<description>Hewlett-Packard LaserJet 1200</description>
|
30
|
+
</usb>
|
31
|
+
<snmp>
|
32
|
+
<description>HP LaserJet 1200</description>
|
33
|
+
</snmp>
|
34
|
+
</autodetect>
|
35
|
+
<functionality>A</functionality>
|
36
|
+
<driver>pxlmono</driver>
|
37
|
+
<drivers>
|
38
|
+
<driver>
|
39
|
+
<id>hplip</id>
|
40
|
+
</driver>
|
41
|
+
</drivers>
|
42
|
+
<comments>
|
43
|
+
<en>
|
44
|
+
Postscript level 2 out of the box, parallel and USB connection,
|
45
|
+
1200n with ethernet connection, scan extension available.<p>
|
46
|
+
|
47
|
+
For basic printing functionality use the Postscript PPD. For
|
48
|
+
advanced functionality such as printer status and maintenance
|
49
|
+
features, use the <a
|
50
|
+
href="http://hplipopensource.com/"> HPLIP
|
51
|
+
driver</a> (which includes HPIJS). <p>
|
52
|
+
|
53
|
+
This printer is a good choice for a cheap laser printer,
|
54
|
+
especially when you print a lot of text documents, as letters,
|
55
|
+
documentation, manuals, ... for these documents it is really fast,
|
56
|
+
as advertized by HP. But when using it on complicated graphics
|
57
|
+
(web pages rendered by Konqueror, photo "convert"ed to
|
58
|
+
PostScript with ImageMagick) in PostScript mode, it is very slow
|
59
|
+
and can easily run out of memory. If you use it in PCL mode, it is
|
60
|
+
fast in both text and graphics printing. Therefore we recommend to
|
61
|
+
use this printer with a Ghostscript driver like
|
62
|
+
"pxlmono" or HPLIP.<p>
|
63
|
+
|
64
|
+
Here is a somewhat longer
|
65
|
+
review from Robert (racsw at frontiernet dot net):<p>
|
66
|
+
|
67
|
+
<i>My testing was done on a PIII / 600Mhz machine with 256K
|
68
|
+
of RAM installed running Mandrake Linux 8.1. While I intended to
|
69
|
+
use this printer as a USB connected device, I was never successful
|
70
|
+
at getting it to work properly, and so switched over to a parallel
|
71
|
+
port connection. In fairness, I don't believe this is the
|
72
|
+
fault of the printer itself. I see no
|
73
|
+
reason why it shouldn't work on USB (</i>ed: Mandrake
|
74
|
+
8.2 configures this printer.
|
75
|
+
automatically<i>).<p>
|
76
|
+
|
77
|
+
IMO, the 1200/1200se is an excellent high-volume document printer,
|
78
|
+
and those folks like myself that need to print the normal volumes
|
79
|
+
of documents, How-To's, Installation procedures, etc, that a
|
80
|
+
typical Linux user requires will find this printer an excellent
|
81
|
+
choice.<p>
|
82
|
+
|
83
|
+
The printer itself comes with 8Mb of memory onboard, with a 100
|
84
|
+
pin DIMM slot capable of another 64Mb, for a total of 72Mb. In the
|
85
|
+
testing I performed with and without this additional memory
|
86
|
+
installed, I could find no difference in speed either way. But
|
87
|
+
for those who feel they want this memory anyhow, I would advise
|
88
|
+
you purchase the Kingston module from <a
|
89
|
+
href="http://www.pcconnection.com/">http://www.pcconnection.com/</a>
|
90
|
+
for $39.00. HP wants a whopping $470.00 (more expensive than the
|
91
|
+
printer itself, 12x the price of the Kingston memory) for the same
|
92
|
+
module.<p>
|
93
|
+
|
94
|
+
For those wanting to print graphics on this machine, I would
|
95
|
+
suggest an Inkjet printer instead like a DeskJet or the popular
|
96
|
+
and proven Epson Stylus C80. If attempting to print a WYSIWYG
|
97
|
+
rendition of a web page, I would make two suggestions. First,
|
98
|
+
don't use Konqueror. Konqueror has two disadvantages. For one,
|
99
|
+
there is no selection for GreyScale, which, when used, cuts the
|
100
|
+
printing time down from 10 - 15 seconds to about 2 - 3. Secondly,
|
101
|
+
Konqueror also does some strange things with the image, which,
|
102
|
+
when printed, will render your copy hard to read with respect to
|
103
|
+
font sizes and such.<p>
|
104
|
+
|
105
|
+
Here's what OpenPrinting founder Grant Taylor
|
106
|
+
says:<p>
|
107
|
+
|
108
|
+
"Konq appears to print using a Qt canvas widget feature whereby the
|
109
|
+
canvas widget unifies the fonts - you'll see it flicker into
|
110
|
+
small font for a moment - and generates equivalent ps code.
|
111
|
+
Oddly, it unifies the fonts to some weird 6-point font that's
|
112
|
+
mostly useless on paper; this is what you saw. One can only hope
|
113
|
+
they'll fix this in KDE3."<p>
|
114
|
+
|
115
|
+
I tested most of the browsers on this printer, and by far and away
|
116
|
+
the most readable, highest quality WYSIWYG printing was from
|
117
|
+
Netscape.<p>
|
118
|
+
|
119
|
+
But that's not what this printer is designed for. For
|
120
|
+
documentation and online manuals, it's hard to
|
121
|
+
beat. It's very fast, quiet and smooth. Contrary to another
|
122
|
+
user's report, I found the paper tray well constructed and
|
123
|
+
easy to insert. It's strength was evidenced by finding my
|
124
|
+
10lb (near 5 kg) house cat sitting on it one afternoon.<p>
|
125
|
+
|
126
|
+
As far as the rendering speed is concerned, I think it's
|
127
|
+
fine. HP advertises a 10 second print time for this machine, and
|
128
|
+
as long as you're not using Konqueror, I was able to meet this
|
129
|
+
time consistently. If the user selects "GreyScale"
|
130
|
+
instead of color for their particular application, the time takes
|
131
|
+
a drastic nosedive to 2-3 seconds, with the same image on the
|
132
|
+
page as you would have seen if you had selected "Color"
|
133
|
+
instead. This 10 second time was also verified by another 1200
|
134
|
+
user running SUSE 7.3.<p>
|
135
|
+
|
136
|
+
If this printer takes longer to print, it's apparently not
|
137
|
+
the internal rendering logic at fault, but the browser or
|
138
|
+
application used instead.<p>
|
139
|
+
|
140
|
+
</i>[...]<i> I think recommending this printer to
|
141
|
+
others is a safe bet. It is working perfectly, and as long as I
|
142
|
+
use it for what it's intended, it does it's job quickly
|
143
|
+
and quietly. </i>[...]<i> People who want to print
|
144
|
+
graphics would probably not select a LaserJet of any variety,
|
145
|
+
unless it's for proofing. And then, it becomes a function of
|
146
|
+
the application that creates and sends the job to the printer that
|
147
|
+
determines what comes out on the page. This I have proven after
|
148
|
+
all these tests.<p>
|
149
|
+
|
150
|
+
I would also say that I used the CUPS printing system for the
|
151
|
+
majority of my testing, and it seems to work fine. There was no
|
152
|
+
bad test results that I achieved that I could attribute to the
|
153
|
+
CUPS system itself. Usually, with Netscape, Mozilla, Adobe
|
154
|
+
Acrobat, etc, I would specify "qtcups" as the print
|
155
|
+
command. Using "lpr" worked as well with no discernible
|
156
|
+
difference.<p>
|
157
|
+
|
158
|
+
I give "two thumbs up" for this printer for sure, and because of
|
159
|
+
the $399 price tag, I can now justify the speed and cost-per-page
|
160
|
+
advantage of owning a high-volume LaserJet for home
|
161
|
+
use.</i><p>
|
162
|
+
|
163
|
+
</en>
|
164
|
+
</comments>
|
165
|
+
</printer>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Foomatic::DB do
|
4
|
+
subject(:db) do
|
5
|
+
foomatic = Foomatic::DB.open(File.expand_path("../db", __FILE__))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#printers" do
|
9
|
+
it "should return list of printers" do
|
10
|
+
db.printers.should be_an_instance_of(Array)
|
11
|
+
db.printers[0].should be_an_instance_of(Foomatic::Printer)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should include 'HP LaserJet 1200' printer" do
|
15
|
+
printer = db.printers[0]
|
16
|
+
printer.make.should eq "HP"
|
17
|
+
printer.model.should eq "LaserJet 1200"
|
18
|
+
printer.should be_laser
|
19
|
+
printer.should_not be_color
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-foomatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edgars Beigarts
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.2.2
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.2.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.11'
|
62
|
+
description: Ruby interface to the Foomatic printer database
|
63
|
+
email:
|
64
|
+
- edgars.beigarts@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/foomatic/version.rb
|
70
|
+
- lib/foomatic.rb
|
71
|
+
- README.md
|
72
|
+
- LICENSE
|
73
|
+
- spec/db/source/printer/HP-LaserJet_1200.xml
|
74
|
+
- spec/foomatic_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: http://github.com/ebeigarts/ruby-foomatic
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.24
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Ruby interface to the Foomatic printer database
|
100
|
+
test_files:
|
101
|
+
- spec/db/source/printer/HP-LaserJet_1200.xml
|
102
|
+
- spec/foomatic_spec.rb
|
103
|
+
- spec/spec_helper.rb
|