Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
switching to use mixlib-shellout for running commands
  • Loading branch information
Will Fisher committed Sep 28, 2015
1 parent b467ed9 commit 4e2d961
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@ log/*
.DS_Store
.workers
pkg
.conveyor
.conveyor
data_test
23 changes: 14 additions & 9 deletions Gemfile.lock
@@ -1,22 +1,23 @@
PATH
remote: .
specs:
gina-conveyor (0.2.3)
gina-conveyor (1.0.0)
activemodel (~> 4.1.0)
activesupport (~> 4.1.0)
em-websocket (~> 0.5.1)
eventmachine (~> 1.0.0)
listen (~> 2.10)
mixlib-shellout (~> 2.2.1)
rainbow (~> 2.0.0)
rb-readline (~> 0.5.0)

GEM
remote: http://rubygems.org/
specs:
activemodel (4.1.12)
activesupport (= 4.1.12)
activemodel (4.1.13)
activesupport (= 4.1.13)
builder (~> 3.1)
activesupport (4.1.12)
activesupport (4.1.13)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
Expand All @@ -28,25 +29,26 @@ GEM
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
eventmachine (1.0.7)
eventmachine (1.0.8)
ffi (1.9.10)
hitimes (1.2.2)
hitimes (1.2.3)
http_parser.rb (0.6.0)
i18n (0.7.0)
json (1.8.3)
listen (2.10.1)
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
minitest (5.7.0)
minitest (5.8.1)
mixlib-shellout (2.2.1)
rainbow (2.0.0)
rake (10.3.2)
rb-fsevent (0.9.5)
rb-fsevent (0.9.6)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rb-readline (0.5.3)
thread_safe (0.3.5)
timers (4.0.1)
timers (4.0.4)
hitimes
tzinfo (1.2.2)
thread_safe (~> 0.1)
Expand All @@ -57,3 +59,6 @@ PLATFORMS
DEPENDENCIES
gina-conveyor!
rake

BUNDLED WITH
1.10.6
1 change: 1 addition & 0 deletions bin/conveyor
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'conveyor'

Conveyor.start
1 change: 1 addition & 0 deletions conveyor.gemspec
Expand Up @@ -27,4 +27,5 @@ Gem::Specification.new do |gem|
gem.add_dependency('rb-readline', '~> 0.5.0')
gem.add_dependency('eventmachine', '~> 1.0.0')
gem.add_dependency('em-websocket', '~> 0.5.1')
gem.add_dependency('mixlib-shellout', '~> 2.2.1')
end
1 change: 1 addition & 0 deletions lib/conveyor.rb
Expand Up @@ -16,6 +16,7 @@
require 'eventmachine'
require 'em-websocket'
require "conveyor/version"
require "mixlib/shellout"

module Conveyor
extend ActiveSupport::Autoload
Expand Down
2 changes: 1 addition & 1 deletion lib/conveyor/version.rb
@@ -1,3 +1,3 @@
module Conveyor
VERSION = "0.2.4"
VERSION = "1.0.0"
end
69 changes: 37 additions & 32 deletions lib/conveyor/workers/syntax.rb
@@ -1,18 +1,18 @@
module Conveyor
module Workers
module Syntax

# Will return a string of any method returned that isn't handled
# ex: match extension txt => match(extension("foo"))
def method_missing(method, value = nil)
return method.to_s
end
end

# Returns a recursive file glob string for the passed in string
def file(glob)
"**/#{glob}"
end

# Returns an extension glob string for passed in string
def extension(glob)
"*.#{glob}"
Expand All @@ -22,7 +22,7 @@ def extension(glob)
def any
'*'
end

# Returns a list of files that have the same basename but different extension
# in the same directory
def like(name)
Expand All @@ -34,7 +34,7 @@ def like(name)
def filename
@filename
end

# Which directories to watch for file change events.
def watch(*args, &block)
yield
Expand All @@ -44,42 +44,47 @@ def watch(*args, &block)
def match(glob, &block)
yield @filename
end

# Run the system sync command
def sync
run 'sync', :quiet => true
end

# Change current working directory, optionally takes a block
# NOTE: Consider removing this as it can cause problems with threaded workers
def chdir(dir, &block)
Dir.chdir(File.expand_path(dir), &block)
end
# Run the system command, and make sure that any errors are caught and returne

# Run the system command, and make sure that any errors are caught
# up the status change
def run(*cmd)
opts = cmd.extract_options!
def run(*params)
opts = params.extract_options!
command = Array.wrap(params).join(' ')
info command unless opts[:quiet]

begin
info cmd.join(' ') unless opts[:quiet]
output,err,thr = Open3.capture3(Array.wrap(cmd).join(' '))
info output.chomp unless output.chomp.length == 0
if thr.success?
if err.chomp.length > 0
cmdrunner = Mixlib::ShellOut.new(command)
cmdrunner.run_command()

info cmdrunner.stdout.chomp unless cmdrunner.stdout.chomp.length == 0

if cmdrunner.error!
error "Error running: `#{command}`", cmdrunner.stderr.chomp
@status.fail!
else
if cmdrunner.stderr.chomp.length > 0
warning "Error output recieved, but no error code recieved"
warning err.chomp
warning cmdrunner.stderr.chomp
end
else
error "Error running: `#{cmd.join(' ')}`", err.chomp
@status.fail!
end
return thr.success?

return !cmdrunner.error!
rescue => e
error e.class, e.message, e.backtrace.join("\n")
end
end

# Deletes passed in files
def delete(files)
# sync before we delete
Expand All @@ -90,38 +95,38 @@ def delete(files)
error "#{f} wasn't removed" if File.exists?(f)
end
end

# Create a new directory
def mkdir(dir)
FileUtils.mkdir_p(File.expand_path(dir))
FileUtils.mkdir_p(File.expand_path(dir))
@status.fail! unless File.exists?(File.expand_path(dir))
end

# Copy files to destination
def copy(src = [], dest = nil)
destination = dest unless dest.nil?
source = src unless src.empty?

if source && destination
verified_copy(source, destination)
end
end
end

# Move files to destination
def move(src=[], dest = nil)
destination = dest unless dest.nil?
source = src unless src.empty?

if source && destination
verified_move(source, destination)
end
end

# Scp files to destination
# See: man scp
def scp(src, dest)
run "scp #{Array.wrap(src).join(' ')} #{dest}"
end
end
end
end
end

0 comments on commit 4e2d961

Please sign in to comment.