constable 0.0.1 → 0.1.0
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/README.md +4 -4
- data/bin/constable-identify +14 -2
- data/bin/constabled +21 -6
- data/lib/constable/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Installing
|
|
13
13
|
|
14
14
|
The server needs ImageMagick installed. Mostly I do this using `apt-get`:
|
15
15
|
|
16
|
-
apt-get
|
16
|
+
apt-get install imagemagick
|
17
17
|
|
18
18
|
You'll need a broker that talks Stomp somewhere on your network. I use Apache
|
19
19
|
Apollo, and I'm not totally sure if the code uses anything that's specific to
|
@@ -24,14 +24,14 @@ bring this closer to reality please send them to me!
|
|
24
24
|
Usage
|
25
25
|
-----
|
26
26
|
|
27
|
-
ImageMagick provides a huge
|
27
|
+
ImageMagick provides a huge number of commands and options. Supporting them
|
28
28
|
all is a big task, so I'm implementing just the few that I use. If you need
|
29
29
|
something else supported, please do fork and patch the project. Let me know
|
30
30
|
and I'll pull your changes.
|
31
31
|
|
32
32
|
Run the server, somewhere that has ImageMagick installed:
|
33
33
|
|
34
|
-
constabled --broker
|
34
|
+
constabled --broker=stomp://mq.yourdomain.com:61613
|
35
35
|
|
36
36
|
Use the services on the command line. You don't need ot have ImageMagick
|
37
37
|
installed on your client machines, just constable.
|
@@ -49,7 +49,7 @@ Constable (and I have no plans to handle it).
|
|
49
49
|
A brief example of what interacting with Constable looks like, here
|
50
50
|
identifying some image file I had lying around on disk:
|
51
51
|
|
52
|
-
$ cat input_file | constable-identify --broker
|
52
|
+
$ cat input_file | constable-identify --broker=stomp://mq.yourdomain.com:61613
|
53
53
|
constabled-164829495-102948483-1939485.jpg JPEG 640x480 DirectClass 87kb 0.050u 0:01
|
54
54
|
|
55
55
|
I explicitly state the broker in the above commands but if you leave out that
|
data/bin/constable-identify
CHANGED
@@ -11,9 +11,19 @@ encoded_input = Base64.encode64 image
|
|
11
11
|
|
12
12
|
require 'stomp'
|
13
13
|
require 'json'
|
14
|
+
require "getoptlong"
|
15
|
+
|
16
|
+
options = {}
|
17
|
+
argv = GetoptLong.new(
|
18
|
+
[ "--broker", "-b", GetoptLong::OPTIONAL_ARGUMENT ]
|
19
|
+
)
|
20
|
+
argv.each do |option, value|
|
21
|
+
options['broker'] = value if option == '--broker'
|
22
|
+
end
|
23
|
+
options['broker'] ||= 'stomp://127.0.0.1:61613'
|
14
24
|
|
15
25
|
results = '/queue/constable.results-' + Process.pid.to_s + '-' + Time.now.to_i.to_s
|
16
|
-
client = Stomp::Client.new
|
26
|
+
client = Stomp::Client.new options['broker']
|
17
27
|
client.subscribe results, 'auto-delete' => true do |message|
|
18
28
|
results = JSON.parse message.body
|
19
29
|
if results['exit_code'] == 0
|
@@ -24,9 +34,11 @@ client.subscribe results, 'auto-delete' => true do |message|
|
|
24
34
|
client.close
|
25
35
|
end
|
26
36
|
|
37
|
+
parameters = ARGV.join ' '
|
27
38
|
command = {
|
28
39
|
command: 'identify',
|
29
|
-
input: encoded_input
|
40
|
+
input: encoded_input,
|
41
|
+
parameters: parameters
|
30
42
|
}
|
31
43
|
command_json = JSON.generate command
|
32
44
|
|
data/bin/constabled
CHANGED
@@ -6,6 +6,7 @@ require 'json'
|
|
6
6
|
require 'tempfile'
|
7
7
|
require 'open3'
|
8
8
|
require 'base64'
|
9
|
+
require 'getoptlong'
|
9
10
|
|
10
11
|
class Job
|
11
12
|
module WorkingEnvironment
|
@@ -31,14 +32,15 @@ class Job
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
def run_command
|
35
|
-
puts "Running #{
|
36
|
-
stdin, stdout, stderr, command = Open3.popen3
|
35
|
+
def run_command command_line
|
36
|
+
puts "Running #{command_line}"
|
37
|
+
stdin, stdout, stderr, command = Open3.popen3 command_line
|
37
38
|
{
|
38
39
|
stdout: stdout.readlines.join,
|
39
40
|
stderr: stderr.readlines.join,
|
40
41
|
exit_code: command.value.exitstatus,
|
41
|
-
pid: command.value.pid
|
42
|
+
pid: command.value.pid,
|
43
|
+
command_line: command_line
|
42
44
|
}
|
43
45
|
end
|
44
46
|
end
|
@@ -55,9 +57,13 @@ class Job
|
|
55
57
|
|
56
58
|
def execute
|
57
59
|
using_file_with_content options['input'] do |file|
|
58
|
-
run_command "identify #{file.path}"
|
60
|
+
run_command "identify #{parameters} #{file.path}"
|
59
61
|
end
|
60
62
|
end
|
63
|
+
|
64
|
+
def parameters
|
65
|
+
'-verbose' if options['parameters'] == '-verbose'
|
66
|
+
end
|
61
67
|
end
|
62
68
|
|
63
69
|
attr_accessor :options
|
@@ -91,7 +97,16 @@ class Job
|
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
|
100
|
+
options = {}
|
101
|
+
argv = GetoptLong.new(
|
102
|
+
[ "--broker", "-b", GetoptLong::OPTIONAL_ARGUMENT ]
|
103
|
+
)
|
104
|
+
argv.each do |option, value|
|
105
|
+
options['broker'] = value if option == '--broker'
|
106
|
+
end
|
107
|
+
options['broker'] ||= 'stomp://127.0.0.1:61613'
|
108
|
+
|
109
|
+
client = Stomp::Client.new options['broker']
|
95
110
|
client.subscribe '/queue/constable' do |message|
|
96
111
|
puts "Received #{message.headers['message-id']}"
|
97
112
|
|
data/lib/constable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-30 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stomp
|
16
|
-
requirement: &
|
16
|
+
requirement: &70227556077520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70227556077520
|
25
25
|
description: Installing ImageMagick and RMagick everywhere sucks, right? So install
|
26
26
|
it in one place and have everything else use that one install.
|
27
27
|
email:
|