parallel_run 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parallel_run (0.1)
5
+ peach (>= 0.4)
6
+ popen4 (>= 0.1.2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ Platform (0.4.0)
12
+ open4 (1.3.0)
13
+ peach (0.4)
14
+ popen4 (0.1.2)
15
+ Platform (>= 0.4.0)
16
+ open4 (>= 0.4.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ parallel_run!
data/Readme.markdown ADDED
File without changes
data/bin/parallel_run ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'parallel_run'
@@ -0,0 +1,101 @@
1
+ require 'optparse'
2
+ require 'peach'
3
+ require 'popen4'
4
+
5
+ DEFAULT_TIME_FORMAT = "%H:%M:%S"
6
+ DEFAULT_PADDING_SIZE = 20
7
+
8
+ $options = {}
9
+
10
+ optparse = OptionParser.new do|opts|
11
+ opts.banner = "Usage: parallel_run [options] values"
12
+
13
+ $options[:verbose] = false
14
+ opts.on('-v', '--verbose', 'Output more information' ) do
15
+ $options[:verbose] = true
16
+ end
17
+
18
+ $options[:command] = "%v"
19
+ opts.on('-c', '--command COMMAND', "Command to execute. You can use values (see below). Default value is '%v'." ) do |c|
20
+ $options[:command] = c
21
+ end
22
+
23
+ $options[:prefix] = "%v"
24
+ opts.on('-p', '--prefix PREFIX', "Prefix for each line. You can use values (see below). Default value is '%v'." ) do |c|
25
+ $options[:prefix] = c
26
+ end
27
+
28
+ $options[:time_format] = DEFAULT_TIME_FORMAT
29
+ opts.on('-t', '--time_format TIME_FORMAT', "Time format to use for each line. Default value is #{DEFAULT_TIME_FORMAT}" ) do |c|
30
+ $options[:time_format] = c
31
+ end
32
+
33
+ $options[:padding_size] = DEFAULT_PADDING_SIZE
34
+ opts.on('--padding-size PADDING_SIZE', "Padding size for prefix. Default value is #{DEFAULT_PADDING_SIZE}}" ) do |c|
35
+ $options[:padding_size] = c.to_i
36
+ end
37
+
38
+ opts.on('-h', '--help', 'Display this screen' ) do
39
+ puts opts
40
+ puts "Values can be used directly in command or prefix directly by using %v."
41
+ puts "You can apply some function in values before using it :"
42
+ puts "* %v no function"
43
+ puts "* %b apply basename function"
44
+ puts "* %d apply dirname function"
45
+ puts "* %k return the index of value in command line values"
46
+ exit
47
+ end
48
+ end
49
+
50
+ optparse.parse!
51
+
52
+ if ARGV.size == 0
53
+ puts "Please specify at least one value"
54
+ exit
55
+ end
56
+
57
+ def output content, pname, flow = ""
58
+ start = "#{pname}::#{flow}".ljust($options[:padding_size])
59
+ puts "[#{start} #{Time.now.strftime($options[:time_format])}] #{content}"
60
+ end
61
+
62
+ def replace s, value, k
63
+ s = s.gsub(/%v/, value)
64
+ s = s.gsub(/%b/, File.basename(value))
65
+ s = s.gsub(/%d/, File.dirname(value))
66
+ s = s.gsub(/%k/, k.to_s)
67
+ s
68
+ end
69
+
70
+ result = {}
71
+ ARGV.each_with_index.to_a.peach do |f, index|
72
+ c = replace $options[:command], f, index
73
+ prefix = replace $options[:prefix], f, index
74
+ output("Lauching command for #{f} : #{c}", prefix) if $options[:verbose]
75
+ status = POpen4::popen4(c, 'r') do |stdout, stderr, stdin, pid|
76
+ [stdout, stderr].peach do |io|
77
+ flow = io == stderr ? "err" : "out"
78
+ while !io.eof?
79
+ output io.readline, prefix, flow
80
+ end
81
+ end
82
+ end
83
+ result[f] = {
84
+ :command => c,
85
+ :status => status,
86
+ }
87
+ output("End of command for #{f} : #{c}", prefix) if $options[:verbose]
88
+ end
89
+
90
+ ok = true
91
+ result.each do |k, v|
92
+ if v[:status].exitstatus != 0
93
+ ok = false
94
+ output "Command failed : #{k} [#{v[:command]}] : exit code #{v[:status].exitstatus}", "master"
95
+ end
96
+ end
97
+ if ok
98
+ output "All #{result.size} commands run ok", "master"
99
+ else
100
+ abort
101
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+
6
+ s.name = "parallel_run"
7
+ s.version = "0.1"
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Bertrand Paquet"]
10
+ s.email = ["bertrand.paquet@gmail.com"]
11
+ s.homepage = "http://github.com/bpaquet/parallel_run"
12
+ s.summary = "Launch shell commands in parallel, capturing stdout and stderr"
13
+ s.description = "Launch shell commands in parallel, capturing stdout and stderr"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.extra_rdoc_files = [
19
+ "Readme.markdown"
20
+ ]
21
+
22
+ s.specification_version = 3
23
+ s.add_runtime_dependency(%q<popen4>, [">= 0.1.2"])
24
+ s.add_runtime_dependency(%q<peach>, [">= 0.4"])
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parallel_run
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Bertrand Paquet
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-06-02 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: popen4
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 31
28
+ segments:
29
+ - 0
30
+ - 1
31
+ - 2
32
+ version: 0.1.2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: peach
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ - 4
47
+ version: "0.4"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: Launch shell commands in parallel, capturing stdout and stderr
51
+ email:
52
+ - bertrand.paquet@gmail.com
53
+ executables:
54
+ - parallel_run
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - Readme.markdown
59
+ files:
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - Readme.markdown
63
+ - bin/parallel_run
64
+ - lib/parallel_run.rb
65
+ - parallel_run.gemspec
66
+ homepage: http://github.com/bpaquet/parallel_run
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.15
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Launch shell commands in parallel, capturing stdout and stderr
99
+ test_files: []
100
+