dork 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.
Files changed (6) hide show
  1. data/README.md +17 -0
  2. data/bin/dork +19 -0
  3. data/bin/dorkd +43 -0
  4. data/lib/dork.rb +1 -0
  5. data/lib/dork/version.rb +3 -0
  6. metadata +65 -0
@@ -0,0 +1,17 @@
1
+ Dork
2
+ ====
3
+
4
+ DOT to PNG as a service.
5
+
6
+ Run the server:
7
+
8
+ bin/dorkd stomp://mq.yourdomain.com:61613
9
+
10
+ Use the service:
11
+
12
+ cat graph.dot | bin/dork stomp://mq.yourdomain.com:61613 > graph.png
13
+
14
+ You'll need a Stomp server of course. If you don't specify the location of
15
+ this it'll default to `stomp://localhost:61613`.
16
+
17
+ The server will need dot installed.
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ dot = STDIN.read
4
+ if dot.to_s.strip == ''
5
+ puts "Give me some dot!"
6
+ exit 1
7
+ end
8
+
9
+ require 'stomp'
10
+
11
+ results = '/queue/dot.results-' + Process.pid.to_s + '-' + Time.now.to_i.to_s
12
+ client = Stomp::Client.new ARGV[0]
13
+ client.subscribe results, 'auto-delete' => true do |message|
14
+ print message.body
15
+ client.close
16
+ end
17
+
18
+ client.publish '/queue/dot', dot, 'reply-to' => results
19
+ client.join
@@ -0,0 +1,43 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'stomp'
4
+ require 'digest/sha1'
5
+
6
+ WORKING_DIRECTORY = '/tmp'
7
+ FILE_NAME_PREFIX = [ File.basename($0), Process.pid, Time.now.to_i,
8
+ rand(1_000_000) ].join '-'
9
+ FILE_NAME_PATH = WORKING_DIRECTORY + '/' + FILE_NAME_PREFIX + '-'
10
+ executable = %x[which neato].strip
11
+ executable = %x[which dot].strip if executable == ''
12
+ DOT = executable
13
+
14
+ puts "I will run #{DOT} on incoming files"
15
+
16
+ client = Stomp::Client.new ARGV[0]
17
+ client.subscribe '/queue/dot' do |message|
18
+ job_id = Digest::SHA1.hexdigest message.headers['message-id']
19
+ file_name = FILE_NAME_PREFIX + job_id
20
+ puts "Received job #{file_name}"
21
+ png_file = file_name + '.png'
22
+ dot_file = file_name + '.dot'
23
+ File.open dot_file, 'w+' do |f|
24
+ f.print message.body
25
+ end
26
+ puts "DOT written to #{dot_file}"
27
+ command = "#{DOT} -Tpng -o#{png_file} #{dot_file}"
28
+ puts "Running #{command}"
29
+ system command
30
+ puts "Wrote PNG to #{png_file}"
31
+ png = File.read png_file
32
+ destination = message.headers['reply-to']
33
+ client.publish destination, png
34
+ puts "Sent PNG to client at #{destination}"
35
+ File.unlink png_file
36
+ File.unlink dot_file
37
+ puts "Cleaned up job #{file_name}"
38
+ end
39
+
40
+ puts "Working files: #{FILE_NAME_PATH}*"
41
+ puts "Waiting for clients..."
42
+
43
+ client.join
@@ -0,0 +1 @@
1
+ require 'dork/version'
@@ -0,0 +1,3 @@
1
+ module Dork
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Craig R Webster
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: stomp
16
+ requirement: &70127840322700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70127840322700
25
+ description: Instead of installing DOT everywhere and eating memory and CPU on those
26
+ machines, make DOT available as a service
27
+ email:
28
+ - craig@barkingiguana.com
29
+ executables:
30
+ - dork
31
+ - dorkd
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/dork/version.rb
36
+ - lib/dork.rb
37
+ - bin/dork
38
+ - bin/dorkd
39
+ - README.md
40
+ homepage:
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements:
59
+ - A broker capable of talking Stomp
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.10
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: DOT to PNG as a service
65
+ test_files: []