chiplotle-cli-wrapper 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/bin/convert_and_print_svg_to_hpgl.sh +0 -0
- data/bin/print_hpgl.rb +1 -0
- data/bin/print_text.rb +15 -11
- data/chiplotle-cli-wrapper.gemspec +27 -0
- data/lib/chiplotle-cli-wrapper.rb +154 -84
- metadata +67 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17f9c2fb9c99541aa0305af83bd071257e3ee844
|
4
|
+
data.tar.gz: c3eb3d7cd3fb21dc674619c8117a2d6a4f0bac36
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b06642521833d9317380906aff4239d39512c0d86d45882bf24334748597552daca0f2b41dd4af0b715ddbf9e5fa94288526b6e72d108c97ce4651af6c2f495b
|
7
|
+
data.tar.gz: 2cb18c703ad946f9442efb3618620888898a7aa1c3307dd8d0d1f998314e9f003e34b880cacaaddf0f080073ee5e7e08d23c5565b08b9cd73c0e339f3e3e41a0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rob Wilson
|
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,27 @@
|
|
1
|
+
Chiplotle CLI Wrapper
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Description
|
5
|
+
-----------
|
6
|
+
|
7
|
+
Features
|
8
|
+
--------
|
9
|
+
|
10
|
+
Install
|
11
|
+
-------
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install chiplotle-cli-wrapper
|
15
|
+
```
|
16
|
+
|
17
|
+
Build and Install Gem
|
18
|
+
---------------------
|
19
|
+
|
20
|
+
```
|
21
|
+
git clone git@github.com:roobert/chiplotle-cli-wrapper.git && cd chiplotle-cli-wrapper
|
22
|
+
gem build chiplotle-cli-wrapper.gemspec
|
23
|
+
gem install chiplotle-cli-wrapper-<version>.gem
|
24
|
+
```
|
25
|
+
|
26
|
+
Examples
|
27
|
+
--------
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
File without changes
|
data/bin/print_hpgl.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
data/bin/print_text.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# example of a simple app that
|
3
|
+
# example of a simple app that writes text to a plotter
|
4
4
|
#
|
5
5
|
|
6
6
|
require 'chiplotle-cli-wrapper'
|
7
7
|
require 'awesome_print'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
text = false
|
10
|
+
pen = false
|
11
|
+
label_direction = false
|
12
|
+
slant = false
|
13
|
+
character_size = false
|
14
|
+
position = false
|
15
|
+
|
16
|
+
text = ARGV[0] if ARGV[0] != nil
|
17
|
+
pen = ARGV[1] if ARGV[1] != nil
|
18
|
+
label_direction = ARGV[2] if ARGV[2] != nil
|
19
|
+
slant = ARGV[3] if ARGV[3] != nil
|
20
|
+
character_size = ARGV[4] if ARGV[4] != nil
|
21
|
+
position = ARGV[5] if ARGV[5] != nil
|
18
22
|
|
19
23
|
plotter = ChiplotleCliWrapper::Plotter.new
|
20
24
|
|
@@ -22,6 +26,6 @@ plotter.debug = true
|
|
22
26
|
|
23
27
|
ap ARGV
|
24
28
|
|
25
|
-
plotter.
|
29
|
+
plotter.draw(text: text, pen: pen, label_direction: label_direction, slant: slant, character_size: character_size, position: position)
|
26
30
|
|
27
31
|
plotter.close
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "chiplotle-cli-wrapper"
|
7
|
+
|
8
|
+
spec.version = "0.0.4"
|
9
|
+
|
10
|
+
spec.summary = "Wrapper library for the chiplotle-cli tool"
|
11
|
+
spec.description = "A Wrapper for the CLI to the Chiplotle python library"
|
12
|
+
|
13
|
+
spec.authors = ["Rob Wilson"]
|
14
|
+
spec.email = "roobert@gmail.com"
|
15
|
+
spec.homepage = "http://github.com/roobert/chiplotle-cli-wrapper"
|
16
|
+
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
|
26
|
+
spec.add_dependency "log4r"
|
27
|
+
end
|
@@ -1,123 +1,193 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'open3'
|
4
|
+
require 'log4r'
|
5
|
+
|
6
|
+
include Open3
|
7
|
+
include Log4r
|
8
|
+
|
9
|
+
STDOUT.sync = true
|
10
|
+
STDERR.sync = true
|
11
|
+
|
3
12
|
module ChiplotleCliWrapper
|
4
|
-
|
13
|
+
class Plotter
|
14
|
+
attr_accessor :log
|
5
15
|
|
6
|
-
|
16
|
+
def initialize
|
7
17
|
|
8
|
-
|
18
|
+
@log = Logger.new 'chiplotle-cli-wrapper'
|
19
|
+
@log.outputters = Outputter.stdout
|
9
20
|
|
10
|
-
|
21
|
+
# TODO: check for chiplotle installation
|
22
|
+
@chiplotle, @stdout, @stderr = popen3("chiplotle")
|
11
23
|
|
12
|
-
|
24
|
+
# plotter initialization takes 8 seconds
|
25
|
+
begin
|
26
|
+
Timeout::timeout(10) do
|
27
|
+
@stdout.each do |line|
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
@debug = false
|
29
|
+
# this is the last line of the banner output on successul initialization of plotter
|
30
|
+
break if line =~ /Buffer Size:.*/
|
17
31
|
|
18
|
-
|
19
|
-
|
32
|
+
log.info "waiting..."
|
33
|
+
sleep 0.5
|
34
|
+
end
|
20
35
|
end
|
36
|
+
rescue Timeout::Error => e
|
37
|
+
raise Timeout::Error, "#{e}: No plotter detected!"
|
38
|
+
end
|
39
|
+
|
40
|
+
log.info "plotter detected!"
|
41
|
+
|
42
|
+
log.info "setting some defaults..."
|
43
|
+
self.reset_label_size
|
44
|
+
self.label_direction(1,0)
|
45
|
+
self.slant(0)
|
46
|
+
self.position(0,0)
|
47
|
+
self.pen_number(1)
|
48
|
+
self.replace_pen
|
49
|
+
|
50
|
+
log.info "starting stderr/stdout logging threads..."
|
51
|
+
Thread.new do
|
52
|
+
loop do
|
53
|
+
log.info @stdout.gets
|
54
|
+
end
|
55
|
+
end
|
21
56
|
|
22
|
-
|
23
|
-
|
57
|
+
Thread.new do
|
58
|
+
loop do
|
59
|
+
log.info @stderr.gets
|
24
60
|
end
|
61
|
+
end
|
25
62
|
|
26
|
-
|
27
|
-
|
63
|
+
log.info "initialization complete!"
|
64
|
+
end
|
28
65
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
66
|
+
def close
|
67
|
+
# TODO: perform any reset actions...
|
32
68
|
|
33
|
-
|
34
|
-
|
69
|
+
@chiplotle.close
|
70
|
+
#@log.close
|
71
|
+
end
|
35
72
|
|
36
|
-
|
73
|
+
def plotter(command)
|
74
|
+
log "plotter.write(#{command})"
|
37
75
|
|
38
|
-
|
39
|
-
end
|
76
|
+
@chiplotle.puts "plotter.write(#{command})"
|
40
77
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
78
|
+
#"oh no! #{@log.read}" if @log.read != "chiplotle> "
|
79
|
+
end
|
44
80
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
81
|
+
def pen_number(pen_number)
|
82
|
+
plotter "hpgl.SP(#{pen_number})"
|
83
|
+
end
|
49
84
|
|
50
|
-
|
51
|
-
|
52
|
-
|
85
|
+
# device will continue from last position if no values are supplied
|
86
|
+
def position(x, y)
|
87
|
+
plotter "hpgl.PA([(#{x}, #{y})])"
|
88
|
+
end
|
53
89
|
|
54
|
-
|
55
|
-
|
56
|
-
|
90
|
+
def label(text)
|
91
|
+
plotter "hpgl.LB('#{text}')"
|
92
|
+
end
|
57
93
|
|
58
|
-
|
59
|
-
|
60
|
-
|
94
|
+
def character_size(width, height)
|
95
|
+
plotter "hpgl.SI(#{width}, #{height})"
|
96
|
+
end
|
61
97
|
|
62
|
-
|
63
|
-
|
64
|
-
|
98
|
+
def reset_label_size
|
99
|
+
plotter "hpgl.SI()"
|
100
|
+
end
|
65
101
|
|
66
|
-
|
67
|
-
|
68
|
-
|
102
|
+
def label_direction(run,rise)
|
103
|
+
plotter "hpgl.DI(#{run}, #{rise})"
|
104
|
+
end
|
69
105
|
|
70
|
-
|
71
|
-
|
72
|
-
|
106
|
+
def slant(slant)
|
107
|
+
plotter "hpgl.SL(#{slant})"
|
108
|
+
end
|
109
|
+
|
110
|
+
def replace_pen
|
111
|
+
pen_number(0)
|
112
|
+
end
|
113
|
+
|
114
|
+
# TODO: insert new lines when plotter is going to run out of horizontal space
|
115
|
+
# FIXME: maybe use nil rather than defaul values to leave setting unchanged..
|
116
|
+
def write_text(
|
117
|
+
text: '',
|
118
|
+
pen_number: '',
|
119
|
+
slant: '',
|
120
|
+
direction_run: '',
|
121
|
+
direction_rise: '',
|
122
|
+
position_x: '',
|
123
|
+
position_y: '',
|
124
|
+
character_width: '',
|
125
|
+
character_height: ''
|
126
|
+
)
|
127
|
+
if pen_number != ''
|
128
|
+
self.pen_number(pen_number)
|
129
|
+
end
|
130
|
+
|
131
|
+
if direction_run != '' and direction_rise != ''
|
132
|
+
self.label_direction(direction_run, direction_rise)
|
133
|
+
end
|
134
|
+
|
135
|
+
if slant != ''
|
136
|
+
self.slant(slant)
|
137
|
+
end
|
138
|
+
|
139
|
+
if position_x != '' and position_y != ''
|
140
|
+
self.position(position_x, position_y)
|
141
|
+
end
|
142
|
+
|
143
|
+
if character_width != '' and character_height != ''
|
144
|
+
self.character_size(character_width, character_height)
|
145
|
+
end
|
146
|
+
|
147
|
+
if text != ''
|
148
|
+
label(text)
|
149
|
+
end
|
150
|
+
|
151
|
+
reset_label_size
|
152
|
+
|
153
|
+
replace_pen
|
154
|
+
end
|
73
155
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
character_width = 0.285,
|
81
|
-
character_height = 0.375,
|
82
|
-
x = nil,
|
83
|
-
y = nil
|
84
|
-
)
|
156
|
+
# FIXME
|
157
|
+
def convert_hpgl_to_chiplotle_functions(hpgl)
|
158
|
+
hpgl.map do |statement|
|
159
|
+
statement.gsub!(/([A-Za-z]{2})(.*)/, "\1(\2)")
|
160
|
+
end
|
161
|
+
end
|
85
162
|
|
86
|
-
|
163
|
+
# FIXME
|
164
|
+
def draw_hpgl(hpgl)
|
87
165
|
|
88
|
-
|
89
|
-
pen(pen_no)
|
166
|
+
chiplotle_functions = convert_hpgl_to_chiplotle_functions(hpgl)
|
90
167
|
|
91
|
-
|
92
|
-
|
168
|
+
chiplotle_functions.each do |command|
|
169
|
+
plotter("hpgl.#{command}")
|
170
|
+
end
|
171
|
+
end
|
93
172
|
|
94
|
-
|
95
|
-
|
173
|
+
def write_file(hpgl)
|
174
|
+
temp_file = Tempfile.new('chiplotle-cli-wrapper')
|
96
175
|
|
97
|
-
|
98
|
-
rotate(rotation)
|
176
|
+
hpgl.gsub!(/\\r?\\n/, '')
|
99
177
|
|
100
|
-
|
101
|
-
slant(slant)
|
178
|
+
log "hpgl: #{hpgl}"
|
102
179
|
|
103
|
-
|
104
|
-
|
180
|
+
temp_file.write(hpgl)
|
181
|
+
temp_file.close
|
105
182
|
|
106
|
-
|
107
|
-
label_size_reset
|
183
|
+
log "temp_file.path: #{temp_file.path}"
|
108
184
|
|
109
|
-
|
110
|
-
replace_pen
|
111
|
-
end
|
185
|
+
log %x{cat #{temp_file.path}}
|
112
186
|
|
113
|
-
|
114
|
-
hgpl.each do |command|
|
115
|
-
plotter(command)
|
116
|
-
end
|
117
|
-
end
|
187
|
+
@chiplotle.puts("plotter.write_file('#{temp_file.path}')")
|
118
188
|
|
119
|
-
|
120
|
-
|
121
|
-
end
|
189
|
+
# FIXME - fork a sleep remove to prevent file being removed before chiplotle has read it?
|
190
|
+
#temp_file.unlink
|
122
191
|
end
|
192
|
+
end
|
123
193
|
end
|
metadata
CHANGED
@@ -1,47 +1,98 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chiplotle-cli-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rob Wilson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
11
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: log4r
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A Wrapper for the CLI to the Chiplotle python library
|
16
56
|
email: roobert@gmail.com
|
17
|
-
executables:
|
57
|
+
executables:
|
58
|
+
- convert_and_print_svg_to_hpgl.sh
|
59
|
+
- print_hpgl.rb
|
60
|
+
- print_text.rb
|
18
61
|
extensions: []
|
19
62
|
extra_rdoc_files: []
|
20
63
|
files:
|
21
|
-
-
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/convert_and_print_svg_to_hpgl.sh
|
70
|
+
- bin/print_hpgl.rb
|
22
71
|
- bin/print_text.rb
|
72
|
+
- chiplotle-cli-wrapper.gemspec
|
73
|
+
- lib/chiplotle-cli-wrapper.rb
|
23
74
|
homepage: http://github.com/roobert/chiplotle-cli-wrapper
|
24
|
-
licenses:
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
25
78
|
post_install_message:
|
26
79
|
rdoc_options: []
|
27
80
|
require_paths:
|
28
81
|
- lib
|
29
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
83
|
requirements:
|
32
|
-
- -
|
84
|
+
- - '>='
|
33
85
|
- !ruby/object:Gem::Version
|
34
86
|
version: '0'
|
35
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
88
|
requirements:
|
38
|
-
- -
|
89
|
+
- - '>='
|
39
90
|
- !ruby/object:Gem::Version
|
40
91
|
version: '0'
|
41
92
|
requirements: []
|
42
93
|
rubyforge_project:
|
43
|
-
rubygems_version:
|
94
|
+
rubygems_version: 2.0.2
|
44
95
|
signing_key:
|
45
|
-
specification_version:
|
46
|
-
summary: Wrapper for chiplotle-cli
|
96
|
+
specification_version: 4
|
97
|
+
summary: Wrapper library for the chiplotle-cli tool
|
47
98
|
test_files: []
|