buildlights 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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Darrin Holst
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = buildlights
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Darrin Holst. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "buildlights"
8
+ gem.executables = "buildlights"
9
+ gem.summary = %Q{build monitor that will trigger lights via x10}
10
+ gem.email = "darrinholst@gmail.com"
11
+ gem.homepage = "http://github.com/darrinholst/buildlights"
12
+ gem.authors = ["Darrin Holst"]
13
+ gem.rubyforge_project = "buildlights"
14
+ gem.add_dependency("simple-rss", ">= 1.2")
15
+ gem.add_dependency("hpricot", ">= 0.8.1")
16
+ end
17
+
18
+ Jeweler::RubyforgeTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION.yml')
49
+ config = YAML.load(File.read('VERSION.yml'))
50
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "build-lights #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
60
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/buildlights ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'buildlights'
7
+
8
+ BuildLights.cli ARGV
@@ -0,0 +1,63 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{build-lights}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Darrin Holst"]
9
+ s.date = %q{2009-08-13}
10
+ s.default_executable = %q{buildlights}
11
+ s.email = %q{darrinholst@gmail.com}
12
+ s.executables = ["buildlights"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/buildlights",
25
+ "build-lights.gemspec",
26
+ "lib/buildlights.rb",
27
+ "lib/ccnet.rb",
28
+ "lib/hudson.rb",
29
+ "lib/lights.rb",
30
+ "test/ccnet_test.rb",
31
+ "test/hudson_test.rb",
32
+ "test/lights_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/darrinholst/build-lights}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubyforge_project = %q{build-lights}
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{build monitor that will trigger lights via x10}
41
+ s.test_files = [
42
+ "test/ccnet_test.rb",
43
+ "test/hudson_test.rb",
44
+ "test/lights_test.rb",
45
+ "test/test_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<simple-rss>, [">= 1.2"])
54
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
55
+ else
56
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
57
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
61
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{buildlights}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Darrin Holst"]
9
+ s.date = %q{2009-08-13}
10
+ s.default_executable = %q{buildlights}
11
+ s.email = %q{darrinholst@gmail.com}
12
+ s.executables = ["buildlights"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "bin/buildlights",
25
+ "build-lights.gemspec",
26
+ "buildlights.gemspec",
27
+ "lib/buildlights.rb",
28
+ "lib/ccnet.rb",
29
+ "lib/hudson.rb",
30
+ "lib/lights.rb",
31
+ "test/ccnet_test.rb",
32
+ "test/hudson_test.rb",
33
+ "test/lights_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/darrinholst/buildlights}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubyforge_project = %q{buildlights}
40
+ s.rubygems_version = %q{1.3.5}
41
+ s.summary = %q{build monitor that will trigger lights via x10}
42
+ s.test_files = [
43
+ "test/ccnet_test.rb",
44
+ "test/hudson_test.rb",
45
+ "test/lights_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<simple-rss>, [">= 1.2"])
55
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
56
+ else
57
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
58
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
62
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
63
+ end
64
+ end
@@ -0,0 +1,38 @@
1
+ require 'optparse'
2
+ require 'ccnet'
3
+ require 'hudson'
4
+ require 'lights'
5
+
6
+ module BuildLights
7
+ extend self
8
+
9
+ def cli(args)
10
+ urls = []
11
+
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: buildlights [options]"
14
+
15
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
16
+ $verbose = true
17
+ end
18
+
19
+ opts.on("--hudson [URL]", "Hudson url") do |url|
20
+ urls << [Hudson, url]
21
+ end
22
+
23
+ opts.on("--ccnet [URL]", "CruiseControl.net url") do |url|
24
+ urls << [CcNet, url]
25
+ end
26
+ end.parse!
27
+
28
+ raise "must supply at least one url to check" if urls.empty?
29
+
30
+ failed_jobs = []
31
+
32
+ urls.each do |url|
33
+ failed_jobs << url.first.new(url.last).failed_jobs
34
+ end
35
+
36
+ Lights.new.send(failed_jobs.flatten.empty? ? :success : :failed)
37
+ end
38
+ end
data/lib/ccnet.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ module BuildLights
5
+ class CcNet
6
+ def initialize(uri, parser = XmlParser)
7
+ puts "CruiseControl.net url: #{uri}" if $verbose
8
+ @doc = parser.parse(uri)
9
+ end
10
+
11
+ def failed_jobs
12
+ @doc.search(:Project).map do |project|
13
+ name = project[:name]
14
+ status = project[:lastBuildStatus]
15
+ puts "#{name} -> #{status}" if $verbose
16
+ failed = /FAIL/i.match(status)
17
+ name if failed
18
+ end.compact
19
+ end
20
+ end
21
+
22
+ class XmlParser
23
+ def self.parse(uri)
24
+ Hpricot::XML(open(uri))
25
+ end
26
+ end
27
+ end
28
+
data/lib/hudson.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'simple-rss'
2
+ require 'open-uri'
3
+
4
+ module BuildLights
5
+ class Hudson
6
+ def initialize(uri, parser = FeedParser)
7
+ puts "Hudson url: #{uri}" if $verbose
8
+ @feed = parser.parse uri
9
+ end
10
+
11
+ def failed_jobs
12
+ @feed.entries.each.map do |entry|
13
+ match = /(.*) #\d+ (.*)/.match(entry.title)
14
+ raise "Invalid rss title #{entry.title}" unless match
15
+ name = match[1]
16
+ status = match[2]
17
+ puts "#{name} -> #{status}" if $verbose
18
+ failed = /FAIL/i.match(status)
19
+ name if failed
20
+ end.compact
21
+ end
22
+ end
23
+
24
+ class FeedParser
25
+ def self.parse(uri)
26
+ SimpleRSS.parse(open(uri))
27
+ end
28
+ end
29
+ end
data/lib/lights.rb ADDED
@@ -0,0 +1,39 @@
1
+ module BuildLights
2
+ class Lights
3
+ GREEN = 1
4
+ RED = 2
5
+
6
+ def initialize(implementation = BottleRocket)
7
+ @implementation = implementation
8
+ end
9
+
10
+ def success
11
+ @implementation.turn_on GREEN
12
+ @implementation.turn_off RED
13
+ end
14
+
15
+ def failed
16
+ @implementation.turn_on RED
17
+ @implementation.turn_off GREEN
18
+ end
19
+ end
20
+
21
+ class BottleRocket
22
+ def self.turn_on(unit, house='A')
23
+ send('on', unit, house)
24
+ end
25
+
26
+ def self.turn_off(unit, house='A')
27
+ send('off', unit, house)
28
+ end
29
+
30
+ private
31
+
32
+ def self.send(command, unit, house)
33
+ cmd = "br -v --house=#{house} --#{command}=#{unit}"
34
+ puts "sending X10 command -> #{cmd}" if $verbose
35
+ system cmd
36
+ raise "bottlerocket command failed with status code #{$?.exitstatus}" if $?.exitstatus > 0
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class CcNetTest < Test::Unit::TestCase
4
+ URI = "some uri"
5
+
6
+ def test_failed_jobs
7
+ parser = parser_for(URI, ["job 1", "Failed"], ["job 2", "Failed"])
8
+ scanner = BuildLights::CcNet.new(URI, parser)
9
+ assert_equal(["job 1", "job 2"], scanner.failed_jobs)
10
+ end
11
+
12
+ def test_successful_jobs
13
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Success"])
14
+ scanner = BuildLights::CcNet.new(URI, parser)
15
+ assert_equal([], scanner.failed_jobs)
16
+ end
17
+
18
+ def test_mixed_jobs
19
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Failed"])
20
+ scanner = BuildLights::CcNet.new(URI, parser)
21
+ assert_equal(["job 2"], scanner.failed_jobs)
22
+ end
23
+
24
+ def test_mixed_case
25
+ parser = parser_for(URI, ["job 1", "FAILED"], ["job 2", "SUCCESS"], ["job 3", "FAIL"])
26
+ scanner = BuildLights::CcNet.new(URI, parser)
27
+ assert_equal(["job 1", "job 3"], scanner.failed_jobs)
28
+ end
29
+
30
+ private
31
+
32
+ def parser_for(uri, *jobs)
33
+ projects = jobs.map do |j|
34
+ project = mock()
35
+ project.stubs(:[]).with(:name).returns(j[0])
36
+ project.stubs(:[]).with(:lastBuildStatus).returns(j[1])
37
+ project
38
+ end
39
+
40
+ doc = mock()
41
+ doc.expects(:search).with(:Project).returns(projects)
42
+
43
+ parser = mock()
44
+ parser.expects(:parse).with(uri).returns(doc)
45
+ parser
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class HudsonTest < Test::Unit::TestCase
4
+ URI = "some uri"
5
+
6
+ def test_all_successful
7
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)")
8
+ scanner = BuildLights::Hudson.new(URI, parser)
9
+ assert_equal([], scanner.failed_jobs)
10
+ end
11
+
12
+ def test_all_failed
13
+ parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #1 (FAILED)")
14
+ scanner = BuildLights::Hudson.new(URI, parser)
15
+ assert_equal(['job 1', 'job 2'], scanner.failed_jobs)
16
+ end
17
+
18
+ def test_mixed
19
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (FAILED)", "job 3 #1 (SUCCESS)")
20
+ scanner = BuildLights::Hudson.new(URI, parser)
21
+ assert_equal(['job 2'], scanner.failed_jobs)
22
+ end
23
+
24
+ def test_mixed_with_lower_case
25
+ parser = feed_parser_for(URI, "job 1 #1 (success)", "job 2 #1 (failed)", "job 3 #1 (success)")
26
+ scanner = BuildLights::Hudson.new(URI, parser)
27
+ assert_equal(['job 2'], scanner.failed_jobs)
28
+ end
29
+
30
+ private
31
+
32
+ def feed_parser_for(uri, *titles)
33
+ entries = stub(:entries => titles.map {|t| stub(:title => t)})
34
+ parser = mock()
35
+ parser.expects(:parse).with(uri).returns(entries)
36
+ parser
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class LightsTest < Test::Unit::TestCase
4
+ def test_successful_builds
5
+ impl = mock()
6
+ impl.expects(:turn_on).with(1)
7
+ impl.expects(:turn_off).with(2)
8
+
9
+ BuildLights::Lights.new(impl).success
10
+ end
11
+
12
+ def test_failed_builds
13
+ impl = mock()
14
+ impl.expects(:turn_on).with(2)
15
+ impl.expects(:turn_off).with(1)
16
+
17
+ BuildLights::Lights.new(impl).failed
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require 'buildlights'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildlights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darrin Holst
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-13 00:00:00 -05:00
13
+ default_executable: buildlights
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: simple-rss
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.2"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ version:
35
+ description:
36
+ email: darrinholst@gmail.com
37
+ executables:
38
+ - buildlights
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - bin/buildlights
52
+ - build-lights.gemspec
53
+ - buildlights.gemspec
54
+ - lib/buildlights.rb
55
+ - lib/ccnet.rb
56
+ - lib/hudson.rb
57
+ - lib/lights.rb
58
+ - test/ccnet_test.rb
59
+ - test/hudson_test.rb
60
+ - test/lights_test.rb
61
+ - test/test_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/darrinholst/buildlights
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: buildlights
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: build monitor that will trigger lights via x10
90
+ test_files:
91
+ - test/ccnet_test.rb
92
+ - test/hudson_test.rb
93
+ - test/lights_test.rb
94
+ - test/test_helper.rb