darrinholst-build-lights 0.0.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/.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
+ = build-lights
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 = "build-lights"
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/build-lights"
12
+ gem.authors = ["Darrin Holst"]
13
+ gem.rubyforge_project = "build-lights"
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.0
data/bin/buildlights ADDED
@@ -0,0 +1,32 @@
1
+ #!ruby
2
+
3
+ require 'rubygems'
4
+ require 'build-lights'
5
+
6
+ config = BuildLights::Config.new
7
+
8
+ failed_jobs = []
9
+
10
+ url = config.ccnet_url
11
+
12
+ if(url)
13
+ puts "checking #{url}"
14
+ failed_jobs << BuildLights::CcNetXmlScanner.new(url)
15
+ else
16
+ puts "skipping ccnet, ccnet_url not found"
17
+ end
18
+
19
+ url = config.hudson_url
20
+
21
+ if(url)
22
+ puts "checking #{url}"
23
+ failed_jobs << BuildLights::HudsonFeedScanner.new(url)
24
+ else
25
+ puts "skipping hudson, hudson_url not found"
26
+ end
27
+
28
+ if(failed_jobs.compact.empty?)
29
+ BuildLights::Lights.new.success
30
+ else
31
+ BuildLights::Lights.new.failed
32
+ end
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{build-lights}
5
+ s.version = "0.0.0"
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-12}
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/bottle_rocket.rb",
27
+ "lib/build_lights.rb",
28
+ "lib/ccnet_xml_scanner.rb",
29
+ "lib/config.rb",
30
+ "lib/feed_parser.rb",
31
+ "lib/hudson_feed_scanner.rb",
32
+ "lib/lights.rb",
33
+ "lib/xml_parser.rb",
34
+ "test/ccnet_xml_scanner_test.rb",
35
+ "test/config_test.rb",
36
+ "test/hudson_feed_scanner_test.rb",
37
+ "test/lights_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/darrinholst/build-lights}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubyforge_project = %q{build-lights}
44
+ s.rubygems_version = %q{1.3.5}
45
+ s.summary = %q{build monitor that will trigger lights via x10}
46
+ s.test_files = [
47
+ "test/ccnet_xml_scanner_test.rb",
48
+ "test/config_test.rb",
49
+ "test/hudson_feed_scanner_test.rb",
50
+ "test/lights_test.rb",
51
+ "test/test_helper.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<simple-rss>, [">= 1.2"])
60
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
61
+ else
62
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
63
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<simple-rss>, [">= 1.2"])
67
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ class BuildLights::BottleRocket
2
+ def self.turn_on(unit, house='A')
3
+ send('on', unit, house)
4
+ end
5
+
6
+ def self.turn_off(unit, house='A')
7
+ send('off', unit, house)
8
+ end
9
+
10
+ private
11
+
12
+ def self.send(command, unit, house)
13
+ puts `br -v --house=#{house} --#{command}=#{unit}`
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module BuildLights
2
+ end
3
+
4
+ require 'config'
5
+ require 'ccnet_xml_scanner'
6
+ require 'hudson_feed_scanner'
7
+ require 'lights'
@@ -0,0 +1,13 @@
1
+ require 'xml_parser'
2
+
3
+ class BuildLights::CcNetXmlScanner
4
+ def initialize(uri, parser = BuildLights::XmlParser)
5
+ @doc = parser.parse(uri)
6
+ end
7
+
8
+ def failed_jobs
9
+ @doc.search(:Project).map do |project|
10
+ project[:name] if project[:lastBuildStatus] =~ /FAIL/i
11
+ end.compact
12
+ end
13
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'build-lights'
2
+ require 'yaml'
3
+
4
+ class BuildLights::Config
5
+ HOME_LOCATION = "#{ENV['HOME']}"
6
+ SYSTEM_LOCATION = "/etc"
7
+
8
+ def initialize
9
+ [HOME_LOCATION, SYSTEM_LOCATION].each do |path|
10
+ config_file = File.join(path, ".buildlights")
11
+ puts config_file
12
+ if File.exists?(config_file) && File.file?(config_file)
13
+ config = YAML.load_file(config_file)
14
+
15
+ if(config)
16
+ config.each_pair do |key, value|
17
+ self.class.send(:attr_reader, key.to_sym)
18
+ instance_variable_set("@#{key}".to_sym, value)
19
+ end
20
+ end
21
+
22
+ return
23
+ end
24
+ end
25
+
26
+ raise "No configuration file found"
27
+ end
28
+
29
+ def method_missing(*args)
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ require 'simple-rss'
2
+ require 'open-uri'
3
+
4
+ class BuildLights::FeedParser
5
+ def self.parse(uri)
6
+ SimpleRSS.parse(open(uri))
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ require 'feed_parser'
2
+
3
+ class BuildLights::HudsonFeedScanner
4
+ def initialize(uri, parser = BuildLights::FeedParser)
5
+ @feed = parser.parse uri
6
+ end
7
+
8
+ def failed_jobs
9
+ @feed.entries.each.map do |entry|
10
+ match = /(.*) #\d+ (.*)/.match(entry.title)
11
+ raise "Invalid rss title #{entry.title}" unless match
12
+ match[1] if /FAIL/i.match(match[2])
13
+ end.compact
14
+ end
15
+ end
data/lib/lights.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'bottle_rocket'
2
+
3
+ class BuildLights::Lights
4
+ GREEN = 1
5
+ RED = 2
6
+
7
+ def initialize(implementation = BuildLights::BottleRocket)
8
+ @implementation = implementation
9
+ end
10
+
11
+ def success
12
+ @implementation.turn_on GREEN
13
+ @implementation.turn_off RED
14
+ end
15
+
16
+ def failed
17
+ @implementation.turn_on RED
18
+ @implementation.turn_off GREEN
19
+ end
20
+ end
data/lib/xml_parser.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ class BuildLights::XmlParser
5
+ def self.parse(uri)
6
+ Hpricot::XML(open(uri))
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'ccnet_xml_scanner'
3
+
4
+ class CcNetXmlScannerTest < Test::Unit::TestCase
5
+ URI = "some uri"
6
+
7
+ def test_failed_jobs
8
+ parser = parser_for(URI, ["job 1", "Failed"], ["job 2", "Failed"])
9
+ scanner = CcNetXmlScanner.new(URI, parser)
10
+ assert_equal(["job 1", "job 2"], scanner.failed_jobs)
11
+ end
12
+
13
+ def test_successful_jobs
14
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Success"])
15
+ scanner = CcNetXmlScanner.new(URI, parser)
16
+ assert_equal([], scanner.failed_jobs)
17
+ end
18
+
19
+ def test_mixed_jobs
20
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Failed"])
21
+ scanner = CcNetXmlScanner.new(URI, parser)
22
+ assert_equal(["job 2"], scanner.failed_jobs)
23
+ end
24
+
25
+ def test_mixed_case
26
+ parser = parser_for(URI, ["job 1", "FAILED"], ["job 2", "SUCCESS"], ["job 3", "FAIL"])
27
+ scanner = CcNetXmlScanner.new(URI, parser)
28
+ assert_equal(["job 1", "job 3"], scanner.failed_jobs)
29
+ end
30
+
31
+ private
32
+
33
+ def parser_for(uri, *jobs)
34
+ projects = jobs.map do |j|
35
+ project = mock()
36
+ project.stubs(:[]).with(:name).returns(j[0])
37
+ project.stubs(:[]).with(:lastBuildStatus).returns(j[1])
38
+ project
39
+ end
40
+
41
+ doc = mock()
42
+ doc.expects(:search).with(:Project).returns(projects)
43
+
44
+ parser = mock()
45
+ parser.expects(:parse).with(uri).returns(doc)
46
+ parser
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+ require 'config'
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ class BuildLights::Config
7
+ HOME_LOCATION = File.join(Dir.tmpdir, "buildlights_unittests", "home")
8
+ SYSTEM_LOCATION = File.join(Dir.tmpdir, "buildlights_unittests", "system")
9
+ end
10
+
11
+ class ConfigTest < Test::Unit::TestCase
12
+ def setup
13
+ FileUtils.rm_rf BuildLights::Config::HOME_LOCATION
14
+ FileUtils.rm_rf BuildLights::Config::SYSTEM_LOCATION
15
+ FileUtils.mkdir_p BuildLights::Config::HOME_LOCATION
16
+ FileUtils.mkdir_p BuildLights::Config::SYSTEM_LOCATION
17
+ end
18
+
19
+ def test_no_config_found
20
+ assert_raise RuntimeError do
21
+ BuildLights::Config.new
22
+ end
23
+ end
24
+
25
+ def test_config_found_in_home_dir
26
+ add_file_to_home
27
+ assert_home_file_used
28
+ end
29
+
30
+ def test_config_found_in_home_dir_is_used_first
31
+ add_file_to_home
32
+ add_file_to_system
33
+ assert_home_file_used
34
+ end
35
+
36
+ def test_config_found_in_system_dir
37
+ add_file_to_system
38
+ assert_system_file_used
39
+ end
40
+
41
+ private
42
+
43
+ def add_file_to_home
44
+ File.open(File.join(BuildLights::Config::HOME_LOCATION, ".buildlights"), "w") do |f|
45
+ f.puts "ccnet_url: ccnet_url_from_home"
46
+ f.puts "hudson_url: hudson_url_from_home"
47
+ end
48
+ end
49
+
50
+ def add_file_to_system
51
+ File.open(File.join(BuildLights::Config::SYSTEM_LOCATION, ".buildlights"), "w") do |f|
52
+ f.puts "ccnet_url: ccnet_url_from_system"
53
+ f.puts "hudson_url: hudson_url_from_system"
54
+ end
55
+ end
56
+
57
+ def assert_home_file_used
58
+ assert_attributes(BuildLights::Config.new, "home")
59
+ end
60
+
61
+ def assert_system_file_used
62
+ assert_attributes(BuildLights::Config.new, "system")
63
+ end
64
+
65
+ def assert_attributes(config, home_or_system)
66
+ assert_equal("hudson_url_from_#{home_or_system}", config.hudson_url)
67
+ assert_equal("ccnet_url_from_#{home_or_system}", config.ccnet_url)
68
+ assert_equal(nil, config.foo_url)
69
+ end
70
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'hudson_feed_scanner'
3
+
4
+ class HudsonFeedScannerTest < Test::Unit::TestCase
5
+ URI = "some uri"
6
+
7
+ def test_all_successful
8
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)")
9
+ scanner = HudsonFeedScanner.new(URI, parser)
10
+ assert_equal([], scanner.failed_jobs)
11
+ end
12
+
13
+ def test_all_failed
14
+ parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #1 (FAILED)")
15
+ scanner = HudsonFeedScanner.new(URI, parser)
16
+ assert_equal(['job 1', 'job 2'], scanner.failed_jobs)
17
+ end
18
+
19
+ def test_mixed
20
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (FAILED)", "job 3 #1 (SUCCESS)")
21
+ scanner = HudsonFeedScanner.new(URI, parser)
22
+ assert_equal(['job 2'], scanner.failed_jobs)
23
+ end
24
+
25
+ def test_mixed_with_lower_case
26
+ parser = feed_parser_for(URI, "job 1 #1 (success)", "job 2 #1 (failed)", "job 3 #1 (success)")
27
+ scanner = HudsonFeedScanner.new(URI, parser)
28
+ assert_equal(['job 2'], scanner.failed_jobs)
29
+ end
30
+
31
+ private
32
+
33
+ def feed_parser_for(uri, *titles)
34
+ entries = stub(:entries => titles.map {|t| stub(:title => t)})
35
+ parser = mock()
36
+ parser.expects(:parse).with(uri).returns(entries)
37
+ parser
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'lights'
3
+
4
+ class LightsTest < Test::Unit::TestCase
5
+ def test_successful_builds
6
+ impl = mock()
7
+ impl.expects(:turn_on).with(1)
8
+ impl.expects(:turn_off).with(2)
9
+
10
+ Lights.new(impl).success
11
+ end
12
+
13
+ def test_failed_builds
14
+ impl = mock()
15
+ impl.expects(:turn_on).with(2)
16
+ impl.expects(:turn_off).with(1)
17
+
18
+ Lights.new(impl).failed
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+
8
+ class Test::Unit::TestCase
9
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darrinholst-build-lights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Darrin Holst
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-12 00:00:00 -07: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
+ - lib/bottle_rocket.rb
54
+ - lib/build_lights.rb
55
+ - lib/ccnet_xml_scanner.rb
56
+ - lib/config.rb
57
+ - lib/feed_parser.rb
58
+ - lib/hudson_feed_scanner.rb
59
+ - lib/lights.rb
60
+ - lib/xml_parser.rb
61
+ - test/ccnet_xml_scanner_test.rb
62
+ - test/config_test.rb
63
+ - test/hudson_feed_scanner_test.rb
64
+ - test/lights_test.rb
65
+ - test/test_helper.rb
66
+ has_rdoc: false
67
+ homepage: http://github.com/darrinholst/build-lights
68
+ licenses:
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project: build-lights
89
+ rubygems_version: 1.3.5
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: build monitor that will trigger lights via x10
93
+ test_files:
94
+ - test/ccnet_xml_scanner_test.rb
95
+ - test/config_test.rb
96
+ - test/hudson_feed_scanner_test.rb
97
+ - test/lights_test.rb
98
+ - test/test_helper.rb