sweatshop_gears 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c674ba7dbd21928d11433b49f7ba0ff722a5d976
4
- data.tar.gz: c3fafd46ef7a1f223fdf58ec6cc40a0e7d681e89
3
+ metadata.gz: fc3432f3f0c58de91d6369534b3e2c36f21d92c4
4
+ data.tar.gz: e108f43c71799209c4b1291122b78c38d8f22880
5
5
  SHA512:
6
- metadata.gz: 8ec3981a117a1229536b823f2f25766a274e21d54f5a3432a87a551bcf646563103d91d12438f4d517de4b28ebef627a8a60c5dc87a50c5c867e43086d319d15
7
- data.tar.gz: 21aaf7fcab481a610792499c29bd3799a2a214def189ce688a813389d0bfeb87a5606dce0c08e100cfa6e30bda0dce4514ce6ef6f45fd79e85b280d6c513ccfc
6
+ metadata.gz: bcc421e65836a289b4535c9c785cc8446cbee10e7fe49954112130225fe511130bf172a17969a187864fa335db23275db7c9dcb54e5104ec34fc15fe6120b755
7
+ data.tar.gz: b4cc260bc7680a529737ab17e9fa1c884a68273980d2bb05137c8744b960d72eaa2777ccda30ed1c9f966274957354072bb010e4af3f09316b5a0ce5a93dc494
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sweatshop_gears (1.0.2)
4
+ sweatshop_gears (1.0.4)
5
5
  bundler
6
6
  commander
7
7
  contracts
data/Rakefile CHANGED
@@ -1,17 +1,7 @@
1
+ require 'terminal-announce'
1
2
  require 'rake'
2
3
  require 'rake/testtask'
3
4
 
4
- task :bats do
5
- `sweatshop stop`
6
- $stdout.sync = true
7
- puts 'sweatshop-gears'
8
- IO.popen "bats #{__dir__}/test --pretty" do |io_stream|
9
- while line = io_stream.gets
10
- puts line
11
- end
12
- end
13
- end
14
-
15
5
  task :riot do
16
6
  Dir.glob('test/*_test.rb').each do |path|
17
7
  require_relative path
@@ -19,11 +9,10 @@ task :riot do
19
9
  end
20
10
 
21
11
  task :build do
22
- print 'Building and installing local gem..'
23
- `gem build sweatshop_gears.gemspec --force`
24
- print '.'
25
- `gem install sweatshop_gears-*.gem`
26
- puts 'Done.'
12
+ Announce.info 'Building and installing local gem...'
13
+ puts `rm -rf sweatshop_gears-*.gem`
14
+ puts `gem build sweatshop_gears.gemspec --force`
15
+ puts `gem install sweatshop_gears-*.gem`
27
16
  end
28
17
 
29
18
  task default: :test
data/bin/sweatshop-gears CHANGED
@@ -5,7 +5,7 @@ require 'commander/import'
5
5
  require 'robot_sweatshop/gears'
6
6
 
7
7
  program :name, 'Sweatshop Gears'
8
- program :version, '1.0.3'
8
+ program :version, '1.0.4'
9
9
  program :description, 'Package management for Robot Sweatshop'
10
10
  program :help, 'Author', 'Justin Scott <jvscott@gmail.com>'
11
11
 
@@ -19,6 +19,7 @@ command :init do |c|
19
19
  options.default path: '/usr/local/gears'
20
20
  FileUtils.mkpath options.path
21
21
  Gears::Metadata.download to_path: options.path
22
+ # TODO: create_runtime_paths not obvious
22
23
  Gears::Metadata.create_runtime_paths # TODO: ensure robot_sweatshop ran and the compiled config exists? Only errors in Services
23
24
  end
24
25
  end
@@ -27,15 +27,8 @@ module Gears
27
27
  def self.create_runtime_paths
28
28
  config_path = File.expand_path '~/.robot_sweatshop/compiled_config.yaml'
29
29
  config = YAML.load_file config_path
30
- FileUtils.mkpath config[:logfile_path]
31
- FileUtils.mkpath config[:pidfile_path]
32
- end
33
-
34
- def self.download_and_install(package_name, from_path:)
35
- metadata_path = "#{from_path}/#{package_name}.yaml"
36
- fail "#{package_name} not found" unless File.exist? metadata_path
37
- metadata = YAML.load_file metadata_path
38
- Gears::Package.install_from metadata
30
+ FileUtils.mkpath "#{config[:logfile_path]}/gears"
31
+ FileUtils.mkpath "#{config[:pidfile_path]}/gears"
39
32
  end
40
33
  end
41
34
  end
@@ -4,31 +4,43 @@ require 'terminal-announce'
4
4
  module Gears
5
5
  module Packages
6
6
  def self.clone(git_repo, to_path:)
7
+ return if Dir.exist? to_path
7
8
  Git.clone git_repo, File.basename(to_path), path: File.dirname(to_path)
8
9
  end
9
10
 
10
- def self.packages(gears_path)
11
- paths = Dir["#{gears_path}/*"].select { |path| File.directory? path }
12
- paths.map { |path| File.expand_path path }
11
+ def self.metadata_for(package_name, path)
12
+ metadata_file = "#{path}/#{package_name}.yaml"
13
+ fail "Metadata for '#{package_name}' not found" unless File.exist? metadata_file
14
+ YAML.load_file metadata_file
13
15
  end
14
16
 
15
- def self.data_for(package_name, path)
16
- install_path = "#{path}/#{package_name}"
17
- metadata_path = "#{path}/#{package_name}.yaml"
18
- fail "Metadata for '#{package_name}' not found" unless File.exist? metadata_path
19
- [install_path, YAML.load_file(metadata_path)]
17
+ def self.install_to(install_path)
18
+ case metadata['type']
19
+ when 'script'
20
+ Gears::Scripts.expose from_path: install_path
21
+ when 'service'
22
+ Gears::Services.load from_path: install_path
23
+ else
24
+ fail 'Unknown package type'
25
+ end
26
+ end
27
+
28
+ def self.expose(plural_type, from_path:)
29
+ namespace = Gears.const_get plural_type.capitalize.to_sym
30
+ namespace.send :expose, from_path: from_path
20
31
  end
21
32
 
22
33
  def self.install(package_name, from_path:)
23
- install_path, metadata = data_for package_name, from_path
34
+ metadata = metadata_for package_name, from_path
35
+ plural_type = "#{metadata['type']}s"
36
+ install_path = "#{from_path}/#{plural_type}/#{package_name}"
24
37
  clone metadata['repo'], to_path: install_path
25
- Announce.success "#{package_name} downloaded"
26
38
  Gears::Dependencies.install from_path: install_path
27
- Gears::Binaries.expose from_path: install_path if metadata['type'] == 'binary'
28
- Gears::Services.load from_path: install_path if metadata['type'] == 'service'
39
+ expose plural_type, from_path: install_path
40
+ Announce.success "#{package_name} installed"
29
41
  rescue
30
42
  Announce.failure 'Error occurred, rolling back installation'
31
- FileUtils.rm_rf "#{from_path}/#{package_name}"
43
+ FileUtils.rm_rf install_path
32
44
  end
33
45
  end
34
46
  end
@@ -2,17 +2,17 @@ require 'fileutils'
2
2
  require 'terminal-announce'
3
3
 
4
4
  module Gears
5
- # Installs binary Gears packages
6
- module Binaries
5
+ # Installs Gears script packages
6
+ module Scripts
7
7
  def self.expose(from_path:)
8
- binary_name = File.basename from_path
9
- original_binary = File.expand_path "#{from_path}/#{binary_name}"
10
- binary_link = File.expand_path "#{scripts_path}/#{binary_name}"
8
+ script_name = File.basename from_path
9
+ original_script = File.expand_path "#{from_path}/#{script_name}"
10
+ script_link = File.expand_path "#{scripts_path}/#{script_name}"
11
11
  begin
12
- FileUtils.symlink original_binary, binary_link
13
- Announce.success "Symlinked #{binary_name}"
12
+ FileUtils.symlink original_script, script_link
13
+ Announce.success "Symlinked #{script_name}"
14
14
  rescue
15
- Announce.warning "#{binary_name} already exists"
15
+ Announce.warning "#{script_name} already exists"
16
16
  end
17
17
  end
18
18
 
@@ -3,27 +3,38 @@ require 'terminal-announce'
3
3
  require 'erubis'
4
4
 
5
5
  module Gears
6
- # Installs service Gears packages
6
+ # Installs Gears service packages
7
7
  module Services
8
- def self.load(from_path:)
8
+ def self.expose(from_path:)
9
9
  service = File.basename from_path
10
- dynamically_load_eye service, from_path
10
+ dynamically_load_eye from_path
11
11
  Announce.success "Loaded #{service} into Eye"
12
12
  end
13
13
 
14
14
  def self.write_and_load(eye_config)
15
15
  eye_file = '/tmp/.sweatshop_gears.eye'
16
16
  File.write eye_file, eye_config
17
- puts eye_config
18
17
  puts `eye load #{eye_file}`
19
18
  puts `eye stop sweatshop_gears`
20
19
  File.delete eye_file
21
20
  end
22
21
 
23
- def self.dynamically_load_eye(service, gears_path)
22
+ def self.services_installed_to(install_path)
23
+ paths = Dir["#{install_path}/*"].select { |path| File.directory? path }
24
+ paths.map { |path| File.basename path }
25
+ end
26
+
27
+ def self.parent_path_of(install_path)
28
+ File.expand_path "#{install_path}/.."
29
+ end
30
+
31
+ def self.dynamically_load_eye(install_path)
32
+ context = {
33
+ services: services_installed_to(parent_path_of(install_path)),
34
+ install_path: File.expand_path(install_path)
35
+ }
24
36
  input = File.read "#{__dir__}/sweatshop_gears.eye.eruby"
25
37
  eruby = Erubis::Eruby.new input
26
- context = { service: service, gears_path: File.expand_path(gears_path) }
27
38
  write_and_load eruby.result(context)
28
39
  end
29
40
  end
@@ -15,10 +15,12 @@ Eye.application :sweatshop_gears do
15
15
  check :cpu, every: 10.seconds, below: 100, times: 3
16
16
  working_dir CONFIG[:working_path]
17
17
 
18
+ <% for service in services %>
18
19
  process :'<%= service %>' do
19
20
  pid_file "#{PID_PATH}/gears/<%= service %>.pid"
20
21
  stdall "#{LOG_PATH}/gears/<%= service %>.log"
21
- start_command "<%= gears_path %>/<%= service %>"
22
+ start_command "<%= install_path %>/<%= service %>"
22
23
  daemonize true
23
24
  end
25
+ <% end %>
24
26
  end
@@ -1,5 +1,5 @@
1
1
  require_relative 'gears/metadata'
2
2
  require_relative 'gears/packages'
3
3
  require_relative 'gears/dependencies'
4
- require_relative 'gears/binaries'
4
+ require_relative 'gears/scripts'
5
5
  require_relative 'gears/services'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sweatshop_gears'
3
- gem.version = '1.0.3'
3
+ gem.version = '1.0.4'
4
4
  gem.licenses = 'MIT'
5
5
  gem.authors = ['Justin Scott']
6
6
  gem.email = 'jvscott@gmail.com'
data/test/init_test.rb CHANGED
@@ -7,5 +7,5 @@ context 'sweatshop-gears init' do
7
7
  setup { `bin/sweatshop-gears init --path #{PACKAGES_PATH}` }
8
8
  denies_topic('the output').empty
9
9
  asserts('metadata is downloaded') { File.exist? "#{PACKAGES_PATH}/git-sync.yaml" }
10
- denies('packages are downloaded') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/git-sync" }
10
+ denies('packages are downloaded') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/scripts/git-sync" }
11
11
  end
data/test/install_test.rb CHANGED
@@ -3,14 +3,14 @@ require_relative 'teststrap'
3
3
  context 'sweatshop-gears install' do
4
4
  setup do
5
5
  clean_up_paths
6
- %w(git-sync big-green-button).each do |package|
6
+ %w(git-sync big-green-button reporter).each do |package|
7
7
  `sweatshop-gears install #{package} --path #{PACKAGES_PATH}`
8
8
  end
9
9
  end
10
10
  denies_topic('the output').empty
11
- asserts('packages are downloaded') { File.exist? "#{PACKAGES_PATH}/git-sync" }
12
- asserts('binaries are symlinked') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/git-sync" }
11
+ asserts('packages are downloaded') { File.exist? "#{PACKAGES_PATH}/scripts/git-sync" }
12
+ asserts('scripts are symlinked') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/git-sync" }
13
13
  denies('services are symlinked') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/big-green-button" }
14
- asserts('services are loaded into Eye') { not `eye info | grep big-green-button`.empty? }
14
+ asserts('all services are loaded into Eye') { `eye info | grep --extended-regexp 'big-green-button|reporter'`.lines.count == 2 }
15
15
  # asserts('dependencies are installed') { ??? }
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweatshop_gears
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Scott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,18 +166,15 @@ files:
166
166
  - Rakefile
167
167
  - bin/sweatshop-gears
168
168
  - lib/robot_sweatshop/gears.rb
169
- - lib/robot_sweatshop/gears/binaries.rb
170
169
  - lib/robot_sweatshop/gears/dependencies.rb
171
170
  - lib/robot_sweatshop/gears/metadata.rb
172
171
  - lib/robot_sweatshop/gears/packages.rb
172
+ - lib/robot_sweatshop/gears/scripts.rb
173
173
  - lib/robot_sweatshop/gears/services.rb
174
174
  - lib/robot_sweatshop/gears/sweatshop_gears.eye.eruby
175
175
  - sweatshop_gears.gemspec
176
- - test/cli.bats
177
176
  - test/help_test.rb
178
- - test/init.bats
179
177
  - test/init_test.rb
180
- - test/install.bats
181
178
  - test/install_test.rb
182
179
  - test/teststrap.rb
183
180
  homepage: http://www.github.com/jscott/sweatshop-gears-cli/
data/test/cli.bats DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # gem build sweatshop-gears.gemspec --quiet
4
- # gem install robot_sweatshop-gears-*.gem
5
-
6
- @test "Runs" {
7
- run sweatshop-gears
8
- [ $status = 0 ]
9
- }
data/test/init.bats DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- @test "Downloads the Gears packages" {
4
- run sweatshop-gears init --path .test_download_path
5
- [ -f .test_download_path/README.md ]
6
- }
7
-
8
- @test "Doesn't download any packages" {
9
- run sweatshop-gears init --path .test_download_path
10
- [ ! -f .test_download_path/packages/big-green-button/README.md ]
11
- }
12
-
13
- teardown() {
14
- rm -rf .test_download_path
15
- }
data/test/install.bats DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- @test "Exposes package binaries" {
4
- run sweatshop-gears install git-sync --path .test_download_path
5
- scripts_path=.robot_sweatshop/scripts
6
- [ -f $scripts_path/git-sync ]
7
- }
8
-
9
- @test "Doesn't expose services" {
10
- run sweatshop-gears install big-green-button --path .test_download_path
11
- scripts_path=.robot_sweatshop/scripts
12
- [ ! -f $scripts_path/big-green-button ]
13
- }
14
-
15
- @test "Loads services into Eye" {
16
- eye stop big-green-button
17
- run sweatshop-gears install big-green-button --path .test_download_path
18
- eye start big-green-button
19
- sleep 3
20
- [[ $(eye info | grep big-green-button) =~ up ]]
21
- }
22
-
23
- @test "Installs dependencies" {
24
- skip "I need a gem to be installed that isn't used by Sweatshop or Gears"
25
- yes | gem uninstall SOME_GEM --all
26
- sweatshop-gears install git-sync --path .test_download_path
27
- [[ $(gem list) =~ "SOME_GEM " ]]
28
- }
29
-
30
- teardown() {
31
- rm -rf .test_download_path
32
- }