houcho 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,155 @@
1
+ # -*- encoding: utf-8 -*-
2
+ class RoleHandle
3
+ require 'yaml'
4
+ require 'tempfile'
5
+ require 'find'
6
+ end
7
+
8
+ class RoleHandle
9
+ class YamlLoader
10
+ attr_reader :data
11
+
12
+ def initialize(yaml_file)
13
+ @data = YAML.load_file(yaml_file)
14
+ @data ||= {}
15
+ end
16
+ end
17
+
18
+ class YamlEditor < YamlLoader
19
+ attr_accessor :data
20
+
21
+ def initialize(yaml_file)
22
+ super
23
+ @yaml_file = yaml_file
24
+ end
25
+
26
+ def save_to_file
27
+ open(@yaml_file, 'w') do |f|
28
+ YAML.dump(@data, f)
29
+ end
30
+ end
31
+ end
32
+
33
+ class ElementHandler
34
+ def initialize(yaml)
35
+ @elements = YamlEditor.new(yaml)
36
+ end
37
+
38
+ def elements(index = nil)
39
+ if index
40
+ (@elements.data[index]||[]).uniq
41
+ else
42
+ @elements.data.values.flatten.uniq
43
+ end
44
+ end
45
+
46
+ def attach(index, element)
47
+ @elements.data[index] ||= []
48
+ @elements.data[index] << element
49
+ @elements.save_to_file
50
+ end
51
+
52
+ def detach(index, element)
53
+ @elements.data[index].delete(element)
54
+ @elements.save_to_file
55
+ end
56
+
57
+ def attached?(index, element)
58
+ return false if ! @elements.data.has_key?(index)
59
+ @elements.data[index].include?(element)
60
+ end
61
+
62
+ # roleを消そうとしているオブジェクトからの問い合わせ用
63
+ def has_data?(index)
64
+ return false if ! @elements.data.has_key?(index)
65
+ @elements.data[index].size != 0
66
+ end
67
+
68
+ def indexes(element)
69
+ return [] if ! @elements.data.values.flatten.include?(element)
70
+ @elements.data.select {|index, elems|elems.include?(element)}.keys
71
+ end
72
+ end
73
+
74
+ class RoleHandler
75
+ def initialize(yaml)
76
+ @roles = YamlEditor.new(yaml)
77
+ end
78
+
79
+ def create(role)
80
+ @roles.data[(@roles.data.keys.max||0) + 1] = role
81
+ @roles.save_to_file
82
+ end
83
+
84
+ def delete(id)
85
+ @roles.data.delete(id)
86
+ @roles.save_to_file
87
+ end
88
+
89
+ def rename(id, name)
90
+ @roles.data[id] = name
91
+ @roles.save_to_file
92
+ end
93
+
94
+ def index(role)
95
+ @roles.data.invert[role]
96
+ end
97
+
98
+ def indexes_regexp(role)
99
+ @roles.data.select {|index, rolename| rolename =~ role }.keys
100
+ end
101
+
102
+ def name(id)
103
+ @roles.data[id]
104
+ end
105
+ end
106
+
107
+ class CfLoader
108
+ attr_reader :role_hosts
109
+
110
+ def initialize(yaml_file)
111
+ @role_hosts = {}
112
+ elements = {}
113
+ group = []
114
+ File.open(yaml_file) do |f|
115
+ f.each do |l|
116
+ if l =~ /^---/
117
+ if l =~ /^---\s+#(.+)$/
118
+ group << $1.gsub(/\s/, '_')
119
+ else
120
+ group << 'NOGROUPNAME'
121
+ end
122
+ end
123
+ end
124
+ end
125
+ File.open(yaml_file) do |f|
126
+ i=0
127
+ YAML.load_documents(f) do |data|
128
+ elements[group[i]] ||= []
129
+ elements[group[i]].concat data['servers']
130
+ i+=1
131
+ end
132
+ end
133
+
134
+ elements.each do |groupname, data|
135
+ current_label = 'NOCATEGORYNAME'
136
+
137
+ data.each do |d|
138
+ if ! d['label'].nil?
139
+ label = d['label'].gsub(/\s/, '_')
140
+ current_label = label if current_label != label
141
+ end
142
+
143
+ d['hosts'].map! do |host|
144
+ host = host.split(' ')
145
+ host = host.size == 1 ? host[0] : host[1]
146
+ end
147
+
148
+ r = groupname + '::' + current_label + '::' + d['config'].sub(/\.yaml$/, '')
149
+ ary = (@role_hosts[r] || []) | d['hosts']
150
+ @role_hosts[r] = ary.uniq
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,5 @@
1
+ require "houcho/version"
2
+
3
+ module Houcho
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Houcho
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Houcho" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'houcho'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: houcho
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi SUZUKI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parallel_tests
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: systemu
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: serverspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: covering to run serverspec
98
+ email:
99
+ - studio3104.com@gmail.com
100
+ executables:
101
+ - houcho
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/houcho
111
+ - houcho.gemspec
112
+ - lib/CI.rb
113
+ - lib/Conductor.rb
114
+ - lib/RoleHandle.rb
115
+ - lib/houcho.rb
116
+ - lib/houcho/version.rb
117
+ - spec/houcho_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/studio3104/houcho
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.3
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: covering to run serverspec
143
+ test_files:
144
+ - spec/houcho_spec.rb
145
+ - spec/spec_helper.rb