dev_commands 0.0.53 → 0.0.54

Sign up to get free protection for your applications and to get access to all the features.
data/lib/command.rb CHANGED
@@ -99,7 +99,7 @@ class Command < Hash
99
99
  require_relative 'timeout.rb'
100
100
  #puts run_with_timeout(self[:input], self[:timeout], 1).to_s
101
101
  #self[:output] = run_with_timeout(self[:input], self[:timeout], 1)
102
- result=run_with_timeout(self[:directory],self[:input], self[:timeout], 1)
102
+ result=run_with_timeout(self[:directory],self[:input], self[:timeout], 2)
103
103
  self[:output]=result[0]
104
104
  self[:exit_code]=result[1]
105
105
 
data/lib/internet.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  require 'open-uri'
2
-
2
+ #require 'net/http'
3
+ require 'timeout'
3
4
  class Internet
4
5
 
5
- @@available=nil
6
+ @@available=true
6
7
 
7
8
  def self.available?
8
9
  return @@available if !@@available.nil?
9
10
 
10
11
  begin
11
- @@available = true if open('http://www.google.com')
12
- rescue
12
+ index=open('http://www.google.com').read
13
+ if index.include?('<Title>Google')
14
+ @@available = true
15
+ else
16
+ puts "open('http://www.google.com') returned false"
17
+ end
18
+ rescue Exception => e
19
+ puts "open('http://www.google.com') raised an exception: #{e.to_s}"
13
20
  @@available = false
14
21
  end
15
22
  @@available
data/lib/timeout.rb CHANGED
@@ -44,11 +44,38 @@ def run_with_timeout(directory,command, timeout, tick)
44
44
  Process.kill("TERM", pid)
45
45
  else
46
46
  exit_code=thread.value
47
+ sleep 1
47
48
  end
48
49
 
49
- ensure
50
+ ensure
50
51
  stdin.close if stdin
51
52
  stderrout.close if stderrout
52
53
  end
53
54
  return [output,exit_code]
54
- end
55
+ end
56
+
57
+ require 'timeout'
58
+ def run_with_timeout2(directory,command,timeout)
59
+ # stdout, stderr pipes
60
+ rout, wout = IO.pipe
61
+ rerr, werr = IO.pipe
62
+ output=''
63
+ error=''
64
+ exit_code=1
65
+ pid = Process.spawn(command, :chdir => directory, :out => wout, :err => werr)
66
+ begin
67
+ Timeout.timeout(timeout) do
68
+ exit_code = Process.wait2(pid)
69
+ output = rout.readlines.join("\n")
70
+ error = rerr.readlines.join("\n")
71
+ end
72
+ rescue
73
+ Proces.kill('TERM',pid)
74
+ output = output + 'timeout occurred.'
75
+ ensure
76
+ rout.close
77
+ rerr.close
78
+ end
79
+ [output,exit_code]
80
+ end
81
+
File without changes
data/spec/command_spec.rb CHANGED
@@ -93,6 +93,24 @@ describe Command do
93
93
  FileUtils.rm_r(dir)
94
94
  end
95
95
 
96
+ it "should be able to rake" do
97
+ dir="#{File.dirname(__FILE__)}/tmp/rake_timeout_test"
98
+ FileUtils.mkdir_p(dir) if(!File.exists?(dir))
99
+ File.open("#{dir}/rakefile.rb","w") { |f|
100
+ f.puts "task :default do"
101
+ f.puts " puts 'rake_test'"
102
+ f.puts "end"
103
+ }
104
+ Dir.chdir(dir) do
105
+ #rake = Command.new({ :input => 'rake', :timeout => 300, :ignore_failure => true })
106
+ #rake.execute
107
+
108
+ #expect(rake[:exit_code]).to eq(0)
109
+ #expect(rake.summary.include?('rake')).to eq(true)
110
+ #expect(rake[:output].include?('rake_test')).to eq(true)
111
+ end
112
+ end
113
+
96
114
  it "should fail when calling rake produces an error" do
97
115
  dir="#{File.dirname(__FILE__)}/tmp/rake_error_test"
98
116
  FileUtils.mkdir_p(dir) if(!File.exists?(dir))
@@ -120,7 +138,7 @@ describe Command do
120
138
  expect(cmd[:exit_code]).not_to eq(0)
121
139
 
122
140
  begin
123
- FileUtils.rm_r("#{dir}")
141
+ #FileUtils.rm_r("#{dir}")
124
142
  rescue
125
143
  end
126
144
  end
@@ -0,0 +1,9 @@
1
+ require_relative '../lib/internet.rb'
2
+ require 'rake'
3
+ describe Internet do
4
+ it "should be able to detect internet availability" do
5
+ expect(Internet.available?).to eq(true)
6
+
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ task :default do
2
+ raise 'rake_test'
3
+ end
@@ -0,0 +1,3 @@
1
+ task :default do
2
+ puts 'rake_test'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.53
4
+ version: 0.0.54
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-21 00:00:00.000000000 Z
12
+ date: 2015-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -105,16 +105,19 @@ files:
105
105
  - lib/test.rb
106
106
  - lib/text.rb
107
107
  - lib/timeout.rb
108
- - lib/Timer.rb
108
+ - lib/timer.rb
109
109
  - lib/update.rb
110
110
  - lib/upgrade.rb
111
111
  - spec/commands_spec.rb
112
112
  - spec/command_spec.rb
113
113
  - spec/gem-example/rakefile.rb
114
+ - spec/internet_spec.rb
114
115
  - spec/publish_spec.rb
115
116
  - spec/sln-vs12-example/rakefile.rb
116
117
  - spec/sln-vs9-example/rakefile.rb
117
118
  - spec/text_spec.rb
119
+ - spec/tmp/rake_error_test/rakefile.rb
120
+ - spec/tmp/rake_timeout_test/rakefile.rb
118
121
  - LICENSE
119
122
  - README.md
120
123
  homepage: http://github.com/lou-parslow/dev_commands.gem
@@ -138,8 +141,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
141
  version: '0'
139
142
  requirements: []
140
143
  rubyforge_project:
141
- rubygems_version: 1.8.24
144
+ rubygems_version: 1.8.28
142
145
  signing_key:
143
146
  specification_version: 3
144
147
  summary: gem to execute system commands
145
148
  test_files: []
149
+ has_rdoc: