Permalink
Browse files

use open3.capture2 to fork off the source commands

  • Loading branch information...
1 parent f1b5371 commit b5d751ec38ad60e3a415ed2a583f0e5d21ec726a Sven Fuchs committed Apr 9, 2012
@@ -0,0 +1,7 @@
+require 'ansi/core'
+
+class String
+ def deansi
+ gsub(ANSI::Code::PATTERN, '')
+ end
+end
@@ -29,14 +29,14 @@ def run
class Scope < Action
def run
project.repos.scope = scope
- Events.trigger(:finish)
+ Events.notify(:finish)
end
end
class Unscope < Action
def run
project.repos.scope = nil
- Events.trigger(:finish)
+ Events.notify(:finish)
end
end
end
View
@@ -13,7 +13,6 @@ def initialize(name)
end
def run
- log 'foo'
screen.display
project.refresh
cli_loop
View
@@ -20,25 +20,22 @@ def subscribe(observer, *types)
subscriptions << Subscription.new(observer, types)
end
- def trigger(event)
- notify(event)
- end
-
def flush
event = events.first
events.clear
notify(event, false) if event
end
def notify(event)
+ # log event
subscriptions.each do |subscription|
subscription.notify(event)
end
end
end
- def trigger(*args)
- Events.trigger(*args)
+ def notify(*args)
+ Events.notify(*args)
end
end
end
@@ -16,13 +16,17 @@ def registered
end
def register(source)
- events.trigger(:start) if sources.empty?
+ Thread.exclusive do
+ events.notify(:start) if sources.empty?
sources << source
+ end
end
def unregister(source)
+ Thread.exclusive do
sources.delete(source)
- events.trigger(:finish) if sources.empty?
+ events.notify(:finish) if sources.empty?
+ end
end
end
end
View
@@ -45,7 +45,7 @@ def refresh
def update(key, result)
results[key] = result
- trigger(:update)
+ notify(:update)
end
end
end
@@ -1,11 +1,13 @@
-require 'ansi/code'
+require 'open3'
+require 'core_ext/string/deansi'
module Space
module Source
class Command
class << self
- def execute(command)
- `#{command}`
+ def execute(dir, command)
+ log "#{File.basename(dir)} $ #{command}"
+ Open3.capture2e("cd #{dir}; #{command}").first
end
end
@@ -36,17 +38,14 @@ def chain
end
def execute
- log "#{File.basename(source.path)} $ #{command}"
- self.class.execute(command)
+ self.class.execute(source.path, command)
end
def filters
[
Events.sources.method(:registered),
method(:update),
- Thread.method(:exclusive),
method(:clean),
- method(:chdir),
::Bundler.method(:with_clean_env)
]
end
@@ -64,7 +63,7 @@ def chdir(&block)
end
def strip_ansi(string)
- string.gsub(ANSI::Code::PATTERN, '')
+ string.deansi
end
end
end
View
@@ -0,0 +1,22 @@
+require 'open3'
+
+dirs = %w(travis-pro-ci travis-pro-hub travis-pro-listener travis-pro-core travis-ci travis-hub travis-listener travis-core travis-support)
+base_dir = '~/Development/projects/travis'
+
+1.times do
+ dirs.each do |dir|
+ Thread.new do
+ result = nil
+ pid = fork do
+ Dir.chdir(File.expand_path(dir, base_dir)) do
+ result = `pwd`
+ p result
+ end
+ end
+ Process.waitpid(pid)
+ p result
+ end
+ end
+end
+
+sleep
View
@@ -0,0 +1,15 @@
+require 'open3'
+
+dirs = %w(travis-pro-ci travis-pro-hub travis-pro-listener travis-pro-core travis-ci travis-hub travis-listener travis-core travis-support)
+base_dir = '~/Development/projects/travis'
+
+10.times do
+ dirs.each do |dir|
+ Thread.new do
+ result, status = Open3.capture2("cd #{File.expand_path(dir, base_dir)} && pwd")
+ p [dir, File.basename(result.chomp)]
+ end
+ end
+end
+
+sleep

0 comments on commit b5d751e

Please sign in to comment.