indicator_delcom 0.0.2

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 ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ This could be checked into github, but we have currently used up all our private repositories.
2
+
3
+ indicatord - is a sinatra app (running as root) that drives the usb delcom light
4
+ jenkins_light - monitors the jenkins ci view running on JENKINS_URL and modifies the indicator light by sending get requests to the sinatra app
5
+
6
+ TODO:
7
+ for some reason the bin/indicatord isn't working, so instead its running with the following file:
8
+
9
+ :::: /usr/local/bin/indicatord ::::
10
+ #!/bin/sh
11
+ ruby /home/ci/dev/indicator/bin/indicatord
12
+ :::: /usr/local/bin/indicatord ::::
13
+
data/bin/indicatord ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'sinatra'
5
+ require_relative './delcom_904006'
6
+
7
+ get '/:device_number/:color' do
8
+ device_number = params.delete('device_number').to_i
9
+ indicator = Delcom::SignalIndicator.new(device_number)
10
+ color = params.delete('color')
11
+ flash_options = nil
12
+ if params.keys.include? 'n' or params.keys.include? 'duration'
13
+ flash_options = {
14
+ :n => (params.delete('n') || Delcom::SignalIndicator::FLASH_N).to_i,
15
+ :duration => (params.delete('duration') || Delcom::SignalIndicator::FLASH_DURATION).to_f,
16
+ }
17
+ indicator.flash(color, flash_options)
18
+ else
19
+ indicator.send(color)
20
+ end
21
+ haml :index, :locals => { :color => color, :flash_options => flash_options }
22
+ end
23
+
24
+ __END__
25
+
26
+ @@ index
27
+ %body{:bgcolor=>color}
28
+ %h1 flash_options:
29
+ %h2= flash_options.inspect
data/bin/jenkins_light ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ require 'net/http'
3
+ require 'rubygems'
4
+ require 'json'
5
+
6
+ INDICATOR_URL = URI.parse("http://localhost:4567/0/")
7
+
8
+ JENKINS_URL = URI.parse("#{ENV['JENKINS_URL']}/api/json/")
9
+
10
+ SLEEP_TIME = 2
11
+
12
+ def indicator(indicator_str)
13
+ #puts indicator_str
14
+ #exit
15
+ Net::HTTP.get(INDICATOR_URL+indicator_str)
16
+ end
17
+
18
+ i=0
19
+ begin
20
+ while i+=1
21
+ color = begin
22
+ body = Net::HTTP.get(JENKINS_URL)
23
+ if body.empty?
24
+ "white" # The lights are on, but nobody's home
25
+ else
26
+ jobs = JSON.load(body)["jobs"]
27
+ colors = jobs.collect { |j| j["color"] }
28
+ if colors.include? "red"
29
+ "red" # At least one light is red
30
+ elsif colors.include? "red_anime"
31
+ i % 2 == 0 ? "red" : "blue" # No lights are red, but at least one is flashing red
32
+ elsif colors.include? "blue_anime"
33
+ i % 2 == 0 ? "blue" : "green" # All lights are green, but at least one is flashing green
34
+ elsif colors.include? "blue"
35
+ "green" # All lights are green
36
+ else
37
+ "yellow" # Buggered if I know
38
+ end
39
+ end
40
+ rescue Exception => e
41
+ "bluegreen?n=50&duration=0.3" # Something bad, probably a network error
42
+ end
43
+ indicator(color)
44
+ sleep SLEEP_TIME
45
+ end
46
+ ensure
47
+ indicator("off") # Turn the indicator off when you're done
48
+ end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Author: Ian Leitch <ian@envato.com>
4
+ # Copyright 2010 Envato
5
+ # Author: chris@playup.com
6
+
7
+ require 'rubygems'
8
+ require 'usb'
9
+
10
+ module Delcom
11
+ class SignalIndicator
12
+
13
+ FLASH_N = 10
14
+ FLASH_DURATION = 0.3
15
+
16
+ COLORS = {
17
+ :off => "\x00",
18
+ :green => "\x01",
19
+ :red => "\x02",
20
+ :yellow => "\x03",
21
+ :blue => "\x04",
22
+ :bluegreen => "\x05",
23
+ :purple => "\x06",
24
+ :white => "\x07"
25
+ }
26
+
27
+ COLORS.each { |k,v|
28
+ define_method k do msg(v) end
29
+ }
30
+
31
+ def self.devices
32
+ @devices ||= USB.devices.select {|device| device.idVendor == VENDOR_ID && device.idProduct == PRODUCT_ID}.tap { |devices|
33
+ raise "Unable to find delcom device(s)" unless devices
34
+ }
35
+ end
36
+
37
+ def initialize(device_number=0)
38
+ @device = self.class.devices[device_number]
39
+ end
40
+
41
+ def flash(color, options)
42
+ p n = options[:n] || FLASH_N
43
+ p duration = options[:duration] || FLASH_DURATION
44
+ (1..n).each {
45
+ send(color)
46
+ sleep duration
47
+ off
48
+ sleep duration
49
+ }
50
+ end
51
+
52
+ private
53
+
54
+ VENDOR_ID = 0x0fc5
55
+ PRODUCT_ID = 0xb080
56
+ INTERFACE_ID = 0
57
+
58
+ def close
59
+ handle.release_interface(INTERFACE_ID)
60
+ handle.usb_close
61
+ @handle = nil
62
+ end
63
+
64
+ def msg(data)
65
+ handle.usb_control_msg(0x21, 0x09, 0x0635, 0x000, "\x65\x0C#{data}\xFF\x00\x00\x00\x00", 0)
66
+ end
67
+
68
+ def handle
69
+ @handle ||= @device.usb_open.tap { |h|
70
+ begin
71
+ # ruby-usb bug: the arity of rusb_detach_kernel_driver_np isn't defined correctly, it should only accept a single argument.
72
+ if USB::DevHandle.instance_method(:usb_detach_kernel_driver_np).arity == 2
73
+ h.usb_detach_kernel_driver_np(INTERFACE_ID, INTERFACE_ID)
74
+ else
75
+ h.usb_detach_kernel_driver_np(INTERFACE_ID)
76
+ end
77
+ rescue Errno::ENODATA => e
78
+ # Already detached
79
+ end
80
+ h.set_configuration(@device.configurations.first)
81
+ h.claim_interface(INTERFACE_ID)
82
+ }
83
+ end
84
+ end
85
+ end
86
+
87
+ if __FILE__ == $0
88
+ device_number = ARGV.size == 1 ? ARGV[0].to_i : 0
89
+ Delcom::SignalIndicator.new(device_number).yellow
90
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indicator_delcom
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - PlayUp Devops
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-07-09 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: haml
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.2.23
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: ruby-usb
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.3
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.9.2
57
+ type: :development
58
+ version_requirements: *id004
59
+ description: |
60
+ Sinatra app that drives the delcom indicator light
61
+
62
+ email:
63
+ - devops@playup.com
64
+ executables:
65
+ - indicatord
66
+ - jenkins_light
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - lib/delcom_904006.rb
73
+ - README.md
74
+ - LICENSE
75
+ - bin/indicatord
76
+ - bin/jenkins_light
77
+ homepage: http://github.com/playup/indicator
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.21
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Sinatra app that drives the delcom indicator light
104
+ test_files: []
105
+