hackboxen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ module HackBoxen
2
+
3
+ class ConfigValidator
4
+
5
+ # This makes sure the "requires" are met by the "provides"
6
+ # in the hackbox config. Failures are stored in <tt>fails</tt>.
7
+ def self.failed_requirements
8
+ p = WorkingConfig['provides']
9
+ r = WorkingConfig['requires']
10
+ fails = []
11
+ if r != nil
12
+ if not r.class == Hash or not p.class == Hash
13
+ fails << "'requires' and 'provides' must be Hash"
14
+ else
15
+ fails += self.match_requirements r, p
16
+ end
17
+ end
18
+ fails
19
+ end
20
+
21
+ # Recursive. r and p must be hashes.
22
+ def self.match_requirements r,p,path=""
23
+ fails = []
24
+ r.keys.each { |k|
25
+ if not p.has_key? k
26
+ fails << "Missing #{path}/#{k}"
27
+ else
28
+ if r[k].class == Hash
29
+ if p[k].class != Hash
30
+ fails << "'provides' #{path}/#{k} should be a hash because 'requires' is."
31
+ else
32
+ fails += self.match_requirements r[k],p[k],"#{path}/#{k}"
33
+ end
34
+ end
35
+ end
36
+ }
37
+ fails
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,39 @@
1
+ require 'log4r'
2
+
3
+ module HackBoxen
4
+ module Logging
5
+ include Log4r
6
+ include Paths
7
+
8
+ def logs_to *args
9
+ @log = Logger.new('hackbox_logger')
10
+ @log.outputters = args.map do |location|
11
+ l = create_log(location)
12
+ l.formatter = default_format
13
+ l
14
+ end
15
+ def log
16
+ @log
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def default_format
23
+ PatternFormatter.new(:pattern =>"[%l] %d :: %m")
24
+ end
25
+
26
+ def default_file
27
+ { :filename => File.join(path_to(:log_dir), 'hb-log'), :trunc => false }
28
+ end
29
+
30
+ def create_log location
31
+ case location
32
+ when STDOUT then Outputter.stdout
33
+ when STDERR then Outputter.stderr
34
+ when 'file' then FileOutputter.new('hb_log_file', default_file)
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,66 @@
1
+ require 'pathname'
2
+
3
+ module HackBoxen
4
+
5
+ module Paths
6
+
7
+ def paths
8
+ @paths ||= default_paths
9
+ end
10
+
11
+ def path_to *pathsegs
12
+ path = Pathname.new path_to_helper(*pathsegs)
13
+ path.absolute? ? File.expand_path(path) : path.to_s
14
+ end
15
+
16
+ def output_dirs
17
+ [
18
+ path_to(:hb_dataroot),
19
+ path_to(:env_dir),
20
+ path_to(:fixd_dir),
21
+ path_to(:log_dir),
22
+ path_to(:ripd_dir),
23
+ path_to(:rawd_dir),
24
+ path_to(:data_dir)
25
+ ]
26
+ end
27
+
28
+ def default_paths
29
+ {
30
+ # root directories
31
+ :home => ENV['HOME'],
32
+ :data_root => WorkingConfig[:dataroot],
33
+ :code_root => WorkingConfig[:coderoot],
34
+ # local hackbox directories
35
+ :hb_current => [:code_root, HackBoxen.current],
36
+ :hb_engine => [:hb_current, 'engine'],
37
+ :hb_config => [:hb_current, 'config'],
38
+ # output directories
39
+ :hb_dataroot => [:data_root, HackBoxen.current],
40
+ :ripd_dir => [:hb_dataroot, 'ripd'],
41
+ :rawd_dir => [:hb_dataroot, 'rawd'],
42
+ :fixd_dir => [:hb_dataroot, 'fixd'],
43
+ :pkgd_dir => [:hb_dataroot, 'pkgd'],
44
+ :log_dir => [:hb_dataroot, 'log'],
45
+ :env_dir => [:hb_dataroot, 'env'],
46
+ :data_dir => [:fixd_dir, 'data'],
47
+ :code_dir => [:fixd_dir, 'code']
48
+ }
49
+
50
+ end
51
+
52
+ private
53
+ def path_to_helper *pathsegs
54
+ expanded = pathsegs.flatten.compact.map do |pathseg|
55
+ case
56
+ when pathseg.is_a?(Symbol) && paths.include?(pathseg) then path_to(paths[pathseg])
57
+ when pathseg.is_a?(Symbol) then raise "No path expansion set for #{pathseg.inspect}"
58
+ else pathseg
59
+ end
60
+ end
61
+ File.join(*expanded)
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,36 @@
1
+ require 'rspec'
2
+ require 'rake'
3
+
4
+ describe "rake config task" do
5
+ before :each do
6
+ @rake = Rake::Application.new
7
+ Rake.application = @rake
8
+ @rake.rake_require(File.expand_path File.join(File.dirname(__FILE__), '..', 'test'))
9
+ @task_name = 'config'
10
+ @cfg_file = File.join(ENV['HOME'],'.hackbox', 'hackbox.yaml')
11
+ end
12
+
13
+ it "should create the config file '/.hackbox/hackbox.yaml' in your home directory" do
14
+ @rake[@task_name].invoke
15
+ File.exists? @cfg_file
16
+ end
17
+
18
+ it "should populate the config file with default keys for dataroot, coderoot, s3_filesystem, and requires" do
19
+ @default_keys = %w[ dataroot coderoot s3_filesystem requires ]
20
+ @rake[@task_name].invoke
21
+ @test_hash = YAML.load File.read(@cfg_file)
22
+ @default_keys.each do |key|
23
+ @test_hash.keys.should include key
24
+ end
25
+ end
26
+
27
+ it "should be able to set the dataroot and coderoot value in the config file" do
28
+ dataroot = "/data/foo"
29
+ coderoot = "/code/foo"
30
+ @rake[@task_name].invoke(dataroot, coderoot)
31
+ @test_hash = YAML.load File.read(@cfg_file)
32
+ @test_hash['dataroot'].should == dataroot
33
+ @test_hash['coderoot'].should == coderoot
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hackboxen
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - kornypoet
14
+ - Ganglion
15
+ - bollacker
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-06-30 00:00:00 -05:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 4
34
+ version: 0.0.4
35
+ type: :runtime
36
+ name: swineherd
37
+ prerelease: false
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ - 4
49
+ - 6
50
+ version: 0.4.6
51
+ type: :runtime
52
+ name: configliere
53
+ prerelease: false
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 8
65
+ - 7
66
+ version: 0.8.7
67
+ type: :runtime
68
+ name: rake
69
+ prerelease: false
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :development
82
+ name: shoulda
83
+ prerelease: false
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 23
92
+ segments:
93
+ - 1
94
+ - 0
95
+ - 0
96
+ version: 1.0.0
97
+ type: :development
98
+ name: bundler
99
+ prerelease: false
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ hash: 7
108
+ segments:
109
+ - 1
110
+ - 5
111
+ - 2
112
+ version: 1.5.2
113
+ type: :development
114
+ name: jeweler
115
+ prerelease: false
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ type: :development
128
+ name: rcov
129
+ prerelease: false
130
+ version_requirements: *id007
131
+ description: A simple framework to assist in standardizing the data-munging input/output process.
132
+ email: travis@infochimps.com
133
+ executables:
134
+ - hb-install
135
+ - hb-scaffold
136
+ - hb-runner
137
+ extensions: []
138
+
139
+ extra_rdoc_files:
140
+ - LICENSE.txt
141
+ - README.textile
142
+ files:
143
+ - CHANGELOG.textile
144
+ - Gemfile
145
+ - Gemfile.lock
146
+ - LICENSE.txt
147
+ - README.textile
148
+ - Rakefile
149
+ - VERSION
150
+ - bin/describe.rb
151
+ - bin/hb-install
152
+ - bin/hb-runner
153
+ - bin/hb-scaffold
154
+ - hackboxen.gemspec
155
+ - lib/gemfiles/Gemfile.jruby-1.6.2.default
156
+ - lib/gemfiles/Gemfile.ruby-1.8.7.default
157
+ - lib/gemfiles/Gemfile.ruby-1.9.2.default
158
+ - lib/hackboxen.rb
159
+ - lib/hackboxen/tasks.rb
160
+ - lib/hackboxen/tasks/endpoint.rb
161
+ - lib/hackboxen/tasks/icss.rb
162
+ - lib/hackboxen/tasks/init.rb
163
+ - lib/hackboxen/tasks/install.rb
164
+ - lib/hackboxen/tasks/mini.rb
165
+ - lib/hackboxen/tasks/scaffold.rb
166
+ - lib/hackboxen/template.rb
167
+ - lib/hackboxen/template/Rakefile.erb
168
+ - lib/hackboxen/template/config.yaml.erb
169
+ - lib/hackboxen/template/endpoint.rb.erb
170
+ - lib/hackboxen/template/icss.yaml.erb
171
+ - lib/hackboxen/template/main.erb
172
+ - lib/hackboxen/utils.rb
173
+ - lib/hackboxen/utils/README_ConfigValidator.textile
174
+ - lib/hackboxen/utils/config_validator.rb
175
+ - lib/hackboxen/utils/logging.rb
176
+ - lib/hackboxen/utils/paths.rb
177
+ - spec/install_spec.rb
178
+ has_rdoc: true
179
+ homepage: http://github.com/infochimps/hackboxen
180
+ licenses:
181
+ - MIT
182
+ post_install_message:
183
+ rdoc_options: []
184
+
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: 3
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ hash: 3
202
+ segments:
203
+ - 0
204
+ version: "0"
205
+ requirements: []
206
+
207
+ rubyforge_project:
208
+ rubygems_version: 1.3.7
209
+ signing_key:
210
+ specification_version: 3
211
+ summary: A simple framework to assist in standardizing the data-munging input/output process.
212
+ test_files:
213
+ - spec/install_spec.rb