battlestation 0.0.1 → 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/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ tmp
6
+ Battlestation
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fd -c
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Battle Stations!
2
+
3
+ [![Build Status](https://secure.travis-ci.org/ariejan/battlestation.png?branch=master)](http://travis-ci.org/ariejan/battlestation)
4
+
5
+ Battle Station allows you to get your development environment up-and-running *fast*. This is still a work in progress.
6
+
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: run rspec'
5
+ task default: :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new
@@ -21,5 +21,7 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rake"
23
23
  s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "rest-client"
24
+ s.add_development_dependency "guard-rspec"
25
+
26
+ s.add_runtime_dependency "thor"
25
27
  end
data/bin/battlestation ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'battlestation'
3
+
4
+ require 'battlestation/cli'
5
+ Battlestation::CLI.start
@@ -0,0 +1,6 @@
1
+ Battlestation.plan do
2
+ dependency :redis do
3
+ executable 'redis-server'
4
+ process 'redis-server'
5
+ end
6
+ end
data/lib/battlestation.rb CHANGED
@@ -1,5 +1,24 @@
1
+ require 'thor'
2
+
1
3
  require "battlestation/version"
4
+ require 'battlestation/plan'
5
+ require 'battlestation/dependency'
6
+ require 'battlestation/ui'
7
+ require 'battlestation/cli'
2
8
 
3
9
  module Battlestation
4
- # Your code goes here...
10
+
11
+ class << self
12
+ attr_writer :ui
13
+
14
+ # Plans a new battlestation
15
+ def plan(opts = {}, &block)
16
+ return Plan.new opts, &block
17
+ end
18
+
19
+ def ui
20
+ @ui ||= UI.new
21
+ end
22
+ end
23
+
5
24
  end
@@ -0,0 +1,40 @@
1
+ module Battlestation
2
+ class CLI < Thor
3
+ include Thor::Actions
4
+
5
+ def initialize(*)
6
+ super
7
+
8
+ the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
9
+ Battlestation.ui = UI::Shell.new(the_shell)
10
+ end
11
+
12
+ check_unknown_options!
13
+
14
+ default_task :check
15
+ class_option "no-color", :type => :boolean, :banner => "Disable colorization in output"
16
+
17
+ def help
18
+ Battlestation.ui.info "Create 'Battlestatio'n in the root of your project and run 'battlestation check'"
19
+ end
20
+
21
+ desc :check, "Checks your system for all dependencies"
22
+ long_desc <<-D
23
+ Checks if you have all the necessary dependencies installed and running
24
+ in order to run this project.
25
+ D
26
+ def check
27
+ if !File.exists?("Battlestation")
28
+ Battlestation.ui.error "Could not read your Battlestation file"
29
+ exit 1
30
+ end
31
+
32
+ # Parse/evaluate Battlestation
33
+ plan = eval(File.read("Battlestation"))
34
+
35
+ plan.execute.each do |result|
36
+ Battlestation.ui.info result
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ module Battlestation
2
+ class Dependency
3
+ attr_accessor :name
4
+ attr_accessor :executables
5
+
6
+ def initialize(name, &block)
7
+ @name = name
8
+ @executables = []
9
+
10
+ instance_eval &block if block_given?
11
+ end
12
+
13
+ def executable(filename)
14
+ executables << filename
15
+ end
16
+
17
+ def execute
18
+ result = []
19
+
20
+ executables.each do |executable|
21
+ if system("/usr/bin/env which #{executable}")
22
+ result << "#{executable} found"
23
+ else
24
+ result << "#{executable} not found"
25
+ end
26
+ end
27
+
28
+ result
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module Battlestation
2
+ class Plan
3
+ attr_accessor :dependencies
4
+
5
+ def initialize(opts = {}, &block)
6
+ @dependencies = {}
7
+
8
+ instance_eval &block if block_given?
9
+ end
10
+
11
+ def dependency(name, &block)
12
+ dependencies[name] = Battlestation::Dependency.new(name, &block)
13
+ end
14
+
15
+ def execute
16
+ results = []
17
+ dependencies.each_pair { |name, dep| results << dep.execute }
18
+ results.flatten
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,67 @@
1
+ require 'rubygems/user_interaction'
2
+
3
+ module Battlestation
4
+ class UI
5
+ def warn(message, newline = nil)
6
+ end
7
+
8
+ def debug(message, newline = nil)
9
+ end
10
+
11
+ def error(message, newline = nil)
12
+ end
13
+
14
+ def info(message, newline = nil)
15
+ end
16
+
17
+ def confirm(message, newline = nil)
18
+ end
19
+
20
+ class Shell < UI
21
+ attr_writer :shell
22
+
23
+ def initialize(shell)
24
+ @shell = shell
25
+ @quiet = false
26
+ end
27
+
28
+ def warn(message, newline = nil)
29
+ tell_me(message, :yellow, newline)
30
+ end
31
+
32
+ def debug(message, newline = nil)
33
+ tell_me(message, nil, newline) if debug?
34
+ end
35
+
36
+ def error(message, newline = nil)
37
+ tell_me(message, :red, newline)
38
+ end
39
+
40
+ def info(message, newline = nil)
41
+ tell_me(message, nil, newline) if !@quiet
42
+ end
43
+
44
+ def confirm(message, newline = nil)
45
+ tell_me(message, :green, newline) if !@quiet
46
+ end
47
+
48
+ def debug?
49
+ !!@debug && !@quiet
50
+ end
51
+
52
+ def debug!
53
+ @debug = true
54
+ end
55
+
56
+ def be_quiet!
57
+ @quiet = true
58
+ end
59
+
60
+ private
61
+ def tell_me(msg, color = nil, newline = nil)
62
+ newline.nil? ? @shell.say(msg, color) : @shell.say(msg, color, newline)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
@@ -1,3 +1,3 @@
1
1
  module Battlestation
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Battlestation do
4
+ it "generates a Battlestation::Plan" do
5
+ plan = Battlestation::plan {}
6
+ plan.should be_a(Battlestation::Plan)
7
+ end
8
+ end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Battlestation::CLI do
4
+ context "without a valid Battlestation file" do
5
+ before do
6
+ remove_battlefile
7
+ end
8
+
9
+ it "write an error" do
10
+ battlestation :check
11
+ out.should eql("Could not read your Battlestation file")
12
+ end
13
+
14
+ it "exits with status 1" do
15
+ battlestation(:check, exitstatus: true).should == 1
16
+ end
17
+ end
18
+
19
+ context "with a failing executable-check" do
20
+ it "reports success" do
21
+ check_battlefile <<-B
22
+ Battlestation.plan do
23
+ dependency :some_dep do
24
+ executable 'ls'
25
+ end
26
+ end
27
+ B
28
+
29
+ out.should =~ /ls found/i
30
+ end
31
+
32
+ it "reports an error" do
33
+ check_battlefile <<-B
34
+ Battlestation.plan do
35
+ dependency :some_dep do
36
+ executable 'unknown-executable-name'
37
+ end
38
+ end
39
+ B
40
+
41
+ out.should =~ /unknown-executable-name not found/i
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Battlestation::Dependency do
4
+ context "executables" do
5
+ subject {
6
+ Battlestation::Dependency.new :test_dep do
7
+ executable 'autoexec.bat'
8
+ end
9
+ }
10
+
11
+ it "can be added" do
12
+ subject.executables.should be_an(Array)
13
+ subject.executables.should have(1).element
14
+ subject.executables.should include('autoexec.bat')
15
+ end
16
+
17
+ it "can be executed" do
18
+ subject.should_receive(:system).with('/usr/bin/env which autoexec.bat')
19
+ subject.execute
20
+ end
21
+
22
+ it "returns a result when succesful" do
23
+ subject.should_receive(:system).with('/usr/bin/env which autoexec.bat').and_return(true)
24
+ result = subject.execute
25
+
26
+ result.should be_an(Array)
27
+ result.should have(1).element
28
+ result.should include("autoexec.bat found")
29
+ end
30
+
31
+ it "returns a result when not succesful" do
32
+ subject.should_receive(:system).with('/usr/bin/env which autoexec.bat').and_return(false)
33
+ result = subject.execute
34
+
35
+ result.should be_an(Array)
36
+ result.should have(1).elements
37
+ result.should include("autoexec.bat not found")
38
+ end
39
+ end
40
+ end
41
+
data/spec/plan_spec.rb ADDED
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Battlestation::Plan do
4
+ context "depencies" do
5
+ subject { Battlestation.plan { dependency :postgres } }
6
+
7
+ it "are added" do
8
+ subject.dependencies.should be_an(Hash)
9
+ subject.dependencies[:postgres].should be_a(Battlestation::Dependency)
10
+ end
11
+
12
+ it "are executed" do
13
+ subject.dependencies[:postgres].should_receive(:execute).once
14
+ subject.execute
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'battlestation'
7
+
8
+ Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
9
+ require file unless file =~ /fakeweb\/.*\.rb/
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.include Spec::Path
14
+ config.include Spec::Helpers
15
+
16
+ original_wd = Dir.pwd
17
+
18
+ config.before :each do
19
+ reset!
20
+ in_app_root
21
+ end
22
+
23
+ config.after :each do
24
+ Dir.chdir(original_wd)
25
+ end
26
+ end
@@ -0,0 +1,78 @@
1
+ module Spec
2
+ module Helpers
3
+ def reset!
4
+ @in_p, @out_p, @err_p = nil, nil, nil
5
+ end
6
+
7
+ attr_reader :out, :err, :exitstatus
8
+
9
+ def battlestation(cmd, options = {})
10
+ expect_err = options.delete(:expect_err)
11
+ exitstatus = options.delete(:exitstatus)
12
+ options["no-color"] = true unless options.key?("no-color")
13
+
14
+ battlestation_bin = File.expand_path('../../../bin/battlestation', __FILE__)
15
+
16
+ args = options.map do |k,v|
17
+ v == true ? " --#{k}" : " --#{k} #{v}" if v
18
+ end.join
19
+
20
+ cmd = "#{Gem.ruby} -I#{lib} #{battlestation_bin} #{cmd}#{args}"
21
+
22
+ if exitstatus
23
+ sys_status(cmd)
24
+ else
25
+ sys_exec(cmd, expect_err) { |i| yield i if block_given? }
26
+ end
27
+ end
28
+
29
+ def lib
30
+ File.expand_path("../../../lib", __FILE__)
31
+ end
32
+
33
+ # Execute a command and get stdout and stderr filled
34
+ def sys_exec(cmd, expect_err = false)
35
+ Open3.popen3(cmd.to_s) do |stdin, stdout, stderr|
36
+ @in_p, @out_p, @err_p = stdin, stdout, stderr
37
+
38
+ yield @in_p if block_given?
39
+ @in_p.close
40
+
41
+ @out = @out_p.read_available_bytes.strip
42
+ @err = @err_p.read_available_bytes.strip
43
+ end
44
+
45
+ puts @err unless expect_err || @err.empty?
46
+ @out
47
+ end
48
+
49
+ # Execute a command and retrieve the exitstatus
50
+ def sys_status(cmd)
51
+ @err = nil
52
+ @out = %x{#{cmd}}.strip
53
+ @exitstatus = $?.exitstatus
54
+ end
55
+
56
+ def remove_battlefile
57
+ path = app("Battlestation")
58
+ FileUtils.rm_rf(path)
59
+ end
60
+
61
+ def battlefile(str)
62
+ path = app("Battlestation")
63
+ path.dirname.mkpath
64
+ File.open(path.to_s, "w") do |f|
65
+ f.puts str
66
+ end
67
+ end
68
+
69
+ def check_battlefile(str)
70
+ battlefile(str)
71
+ battlestation :check
72
+ end
73
+
74
+ def in_app_root(&block)
75
+ Dir.chdir(app, &block)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+
3
+ module Spec
4
+ module Path
5
+ def root
6
+ @root ||= Pathname.new(File.expand_path("../../..", __FILE__))
7
+ end
8
+
9
+ def tmp(*path)
10
+ root.join("tmp", *path)
11
+ end
12
+
13
+ def app(*path)
14
+ root = tmp.join("spec_app")
15
+ FileUtils.mkdir_p(root)
16
+ root.join(*path)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class IO
2
+ def read_available_bytes(chunk_size = 16384, select_timeout = 0.02)
3
+ buffer = []
4
+
5
+ return "" if closed? || eof?
6
+ # IO.select cannot be used here due to the fact that it
7
+ # just does not work on windows
8
+ while true
9
+ begin
10
+ IO.select([self], nil, nil, select_timeout)
11
+ break if eof? # stop raising :-(
12
+ buffer << self.readpartial(chunk_size)
13
+ rescue(EOFError)
14
+ break
15
+ end
16
+ end
17
+
18
+ return buffer.join
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battlestation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70176431339220 !ruby/object:Gem::Requirement
16
+ requirement: &70112074127740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70176431339220
24
+ version_requirements: *70112074127740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70176431337460 !ruby/object:Gem::Requirement
27
+ requirement: &70112074151900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,20 +32,61 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70176431337460
35
+ version_requirements: *70112074151900
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &70112074174300 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70112074174300
47
+ - !ruby/object:Gem::Dependency
48
+ name: thor
49
+ requirement: &70112074179700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70112074179700
36
58
  description: Get your battle station up and running fast
37
59
  email:
38
60
  - ariejan@ariejan.net
39
- executables: []
61
+ executables:
62
+ - battlestation
40
63
  extensions: []
41
64
  extra_rdoc_files: []
42
65
  files:
43
66
  - .gitignore
67
+ - .rspec
68
+ - .travis.yml
44
69
  - Gemfile
70
+ - Guardfile
71
+ - README.md
45
72
  - Rakefile
46
73
  - battlestation.gemspec
74
+ - bin/battlestation
75
+ - examples/redis_plan.rb
47
76
  - lib/battlestation.rb
77
+ - lib/battlestation/cli.rb
78
+ - lib/battlestation/dependency.rb
79
+ - lib/battlestation/plan.rb
80
+ - lib/battlestation/ui.rb
48
81
  - lib/battlestation/version.rb
82
+ - spec/battle_station_spec.rb
83
+ - spec/cli_spec.rb
84
+ - spec/dependency_spec.rb
85
+ - spec/plan_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/support/helpers.rb
88
+ - spec/support/path.rb
89
+ - spec/support/ruby_ext.rb
49
90
  homepage: ''
50
91
  licenses: []
51
92
  post_install_message:
@@ -60,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
101
  version: '0'
61
102
  segments:
62
103
  - 0
63
- hash: -995067587077229256
104
+ hash: -4191635253255446564
64
105
  required_rubygems_version: !ruby/object:Gem::Requirement
65
106
  none: false
66
107
  requirements:
@@ -69,11 +110,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
110
  version: '0'
70
111
  segments:
71
112
  - 0
72
- hash: -995067587077229256
113
+ hash: -4191635253255446564
73
114
  requirements: []
74
115
  rubyforge_project: battlestation
75
116
  rubygems_version: 1.8.11
76
117
  signing_key:
77
118
  specification_version: 3
78
119
  summary: Get your battle station up and running fast
79
- test_files: []
120
+ test_files:
121
+ - spec/battle_station_spec.rb
122
+ - spec/cli_spec.rb
123
+ - spec/dependency_spec.rb
124
+ - spec/plan_spec.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/helpers.rb
127
+ - spec/support/path.rb
128
+ - spec/support/ruby_ext.rb