dev_commands 0.0.49 → 0.0.50
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.
- data/lib/{timer.rb → Timer.rb} +40 -40
- data/lib/analyze.rb +7 -7
- data/lib/array.rb +29 -29
- data/lib/command.rb +207 -203
- data/lib/doc.rb +8 -8
- data/lib/gemspec.rb +38 -38
- data/lib/git.rb +21 -21
- data/lib/hash.rb +20 -20
- data/lib/internet.rb +16 -16
- data/lib/publish.rb +21 -21
- data/lib/push.rb +8 -8
- data/lib/setup.rb +24 -24
- data/lib/text.rb +14 -14
- data/lib/timeout.rb +57 -53
- data/spec/command_spec.rb +148 -148
- data/spec/publish_spec.rb +27 -27
- data/spec/sln-vs12-example/rakefile.rb +11 -11
- data/spec/sln-vs9-example/rakefile.rb +11 -11
- data/spec/text_spec.rb +11 -11
- metadata +29 -20
- checksums.yaml +0 -7
data/lib/doc.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Doc < Array
|
2
|
-
def update
|
3
|
-
#cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
|
4
|
-
#cmd.execute
|
5
|
-
if(Command.exit_code('yard --version'))
|
6
|
-
add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
|
7
|
-
end
|
8
|
-
end
|
1
|
+
class Doc < Array
|
2
|
+
def update
|
3
|
+
#cmd=Command.new ({ :input => 'yard --version', :ignore_failure => true})
|
4
|
+
#cmd.execute
|
5
|
+
if(Command.exit_code('yard --version'))
|
6
|
+
add 'yard doc - LICENSE' if File.exists?('README.md') && File.exists?('LICENSE')
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/gemspec.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
class Gemspec
|
2
|
-
def self.update gemspec_file
|
3
|
-
Text.replace_in_file gemspec_file,
|
4
|
-
/('\d{4}-\d{2}-\d{2}')/,
|
5
|
-
"'#{Time.now.strftime('%Y-%m-%d')}'"
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.gemfile gemspec_file
|
9
|
-
spec=Gem::Specification.load(gemspec_file)
|
10
|
-
return "#{spec.name}-#{spec.version}.gem"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.version gemspec_file
|
14
|
-
spec=Gem::Specification.load(gemspec_file)
|
15
|
-
return spec.version.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.published_version gemspec_file
|
19
|
-
published_version=''
|
20
|
-
spec=Gem::Specification.load(gemspec_file)
|
21
|
-
begin
|
22
|
-
published_version = `gem list -r #{spec.name}`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
|
23
|
-
rescue
|
24
|
-
published_version=''
|
25
|
-
end
|
26
|
-
published_version
|
27
|
-
end
|
28
|
-
def self.published? gemspec_file
|
29
|
-
published_version(gemspec_file)==version(gemspec_file) ? true : false
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.normalize gemspec_file
|
33
|
-
spec=Gem::Specification.load(gemspec_file)
|
34
|
-
File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.upgrade gemspec_file
|
38
|
-
end
|
1
|
+
class Gemspec
|
2
|
+
def self.update gemspec_file
|
3
|
+
Text.replace_in_file gemspec_file,
|
4
|
+
/('\d{4}-\d{2}-\d{2}')/,
|
5
|
+
"'#{Time.now.strftime('%Y-%m-%d')}'"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.gemfile gemspec_file
|
9
|
+
spec=Gem::Specification.load(gemspec_file)
|
10
|
+
return "#{spec.name}-#{spec.version}.gem"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.version gemspec_file
|
14
|
+
spec=Gem::Specification.load(gemspec_file)
|
15
|
+
return spec.version.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.published_version gemspec_file
|
19
|
+
published_version=''
|
20
|
+
spec=Gem::Specification.load(gemspec_file)
|
21
|
+
begin
|
22
|
+
published_version = `gem list -r #{spec.name}`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
|
23
|
+
rescue
|
24
|
+
published_version=''
|
25
|
+
end
|
26
|
+
published_version
|
27
|
+
end
|
28
|
+
def self.published? gemspec_file
|
29
|
+
published_version(gemspec_file)==version(gemspec_file) ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.normalize gemspec_file
|
33
|
+
spec=Gem::Specification.load(gemspec_file)
|
34
|
+
File.open(gemspec_file,'w'){|f|f.write(spec.to_ruby)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.upgrade gemspec_file
|
38
|
+
end
|
39
39
|
end
|
data/lib/git.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
class Git
|
2
|
-
def self.branch
|
3
|
-
begin
|
4
|
-
`git branch`.scan(/\* ([.\w-]+)/)[0][0]
|
5
|
-
rescue
|
6
|
-
''
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.remote_origin directory=''
|
11
|
-
url=''
|
12
|
-
directory=Dir.pwd if directory.length == 0
|
13
|
-
Dir.chdir(directory) do
|
14
|
-
begin
|
15
|
-
url=`git remote show origin`.scan(/Fetch URL: ([\.\-:\/\w\d]+)/)[0]
|
16
|
-
rescue
|
17
|
-
url=''
|
18
|
-
end
|
19
|
-
end
|
20
|
-
url
|
21
|
-
end
|
1
|
+
class Git
|
2
|
+
def self.branch
|
3
|
+
begin
|
4
|
+
`git branch`.scan(/\* ([.\w-]+)/)[0][0]
|
5
|
+
rescue
|
6
|
+
''
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.remote_origin directory=''
|
11
|
+
url=''
|
12
|
+
directory=Dir.pwd if directory.length == 0
|
13
|
+
Dir.chdir(directory) do
|
14
|
+
begin
|
15
|
+
url=`git remote show origin`.scan(/Fetch URL: ([\.\-:\/\w\d]+)/)[0]
|
16
|
+
rescue
|
17
|
+
url=''
|
18
|
+
end
|
19
|
+
end
|
20
|
+
url
|
21
|
+
end
|
22
22
|
end
|
data/lib/hash.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
class Hash
|
2
|
-
def execute value=nil
|
3
|
-
self.each{|k,v|
|
4
|
-
v.update if v.respond_to?(:update)
|
5
|
-
if(v.is_a?(Array) && v.length==0)
|
6
|
-
self.delete k
|
7
|
-
else
|
8
|
-
#puts "executing #{k}"
|
9
|
-
|
10
|
-
v.execute(value) if v.respond_to?(:execute)
|
11
|
-
end
|
12
|
-
}
|
13
|
-
end
|
14
|
-
def to_html
|
15
|
-
[
|
16
|
-
'<div>',
|
17
|
-
map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
|
18
|
-
'</div>'
|
19
|
-
].join
|
20
|
-
end
|
1
|
+
class Hash
|
2
|
+
def execute value=nil
|
3
|
+
self.each{|k,v|
|
4
|
+
v.update if v.respond_to?(:update)
|
5
|
+
if(v.is_a?(Array) && v.length==0)
|
6
|
+
self.delete k
|
7
|
+
else
|
8
|
+
#puts "executing #{k}"
|
9
|
+
|
10
|
+
v.execute(value) if v.respond_to?(:execute)
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
def to_html
|
15
|
+
[
|
16
|
+
'<div>',
|
17
|
+
map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
|
18
|
+
'</div>'
|
19
|
+
].join
|
20
|
+
end
|
21
21
|
end
|
data/lib/internet.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
|
-
class Internet
|
4
|
-
|
5
|
-
@@available=nil
|
6
|
-
|
7
|
-
def self.available?
|
8
|
-
return @@available if !@@available.nil?
|
9
|
-
|
10
|
-
begin
|
11
|
-
@@available = true if open('http://www.google.com')
|
12
|
-
rescue
|
13
|
-
@@available = false
|
14
|
-
end
|
15
|
-
@@available
|
16
|
-
end
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
class Internet
|
4
|
+
|
5
|
+
@@available=nil
|
6
|
+
|
7
|
+
def self.available?
|
8
|
+
return @@available if !@@available.nil?
|
9
|
+
|
10
|
+
begin
|
11
|
+
@@available = true if open('http://www.google.com')
|
12
|
+
rescue
|
13
|
+
@@available = false
|
14
|
+
end
|
15
|
+
@@available
|
16
|
+
end
|
17
17
|
end
|
data/lib/publish.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require_relative('internet.rb')
|
2
|
-
class Publish < Array
|
3
|
-
def update
|
4
|
-
if(Internet.available?)
|
5
|
-
if(File.exists?('.git'))
|
6
|
-
if(`git branch`.include?('* master'))
|
7
|
-
Dir.glob('*.gemspec').each{|gemspec_file|
|
8
|
-
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
if(File.exists?('.svn'))
|
13
|
-
if(`svn info`.include?('/trunk'))
|
14
|
-
Dir.glob('*.gemspec').each{|gemspec_file|
|
15
|
-
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require_relative('internet.rb')
|
2
|
+
class Publish < Array
|
3
|
+
def update
|
4
|
+
if(Internet.available?)
|
5
|
+
if(File.exists?('.git'))
|
6
|
+
if(`git branch`.include?('* master'))
|
7
|
+
Dir.glob('*.gemspec').each{|gemspec_file|
|
8
|
+
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
if(File.exists?('.svn'))
|
13
|
+
if(`svn info`.include?('/trunk'))
|
14
|
+
Dir.glob('*.gemspec').each{|gemspec_file|
|
15
|
+
add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/push.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative('internet.rb')
|
2
|
-
class Push < Array
|
3
|
-
def update
|
4
|
-
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
5
|
-
add 'git config --global push.default simple'
|
6
|
-
self << 'git push' if Git.branch != 'develop' && Internet.available?
|
7
|
-
end
|
8
|
-
end
|
1
|
+
require_relative('internet.rb')
|
2
|
+
class Push < Array
|
3
|
+
def update
|
4
|
+
if(File.exists?('.git') && `git config --list`.include?('user.name='))
|
5
|
+
add 'git config --global push.default simple'
|
6
|
+
self << 'git push' if Git.branch != 'develop' && Internet.available?
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/setup.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
#
|
2
|
-
# use the SVN_EXPORTS hash to define svn exports destined for DEV_ROOT/dep
|
3
|
-
#
|
4
|
-
# SVN_EXPORT={ 'System.Data.SQLite/1.0.93.0' => 'https://third-party.googlecode.com/svn/trunk/System.Data.SQLite/1.0.93.0' }
|
5
|
-
#
|
6
|
-
class Setup < Array
|
7
|
-
def update
|
8
|
-
add 'bundle install' if(File.exists?('Gemfile'))
|
9
|
-
|
10
|
-
Dir.glob('*.gemspec').each{|gemspec_file|
|
11
|
-
add "<%Gemspec.update('#{gemspec_file}')%>"
|
12
|
-
}
|
13
|
-
|
14
|
-
if(defined?(SVN_EXPORTS))
|
15
|
-
SVN_EXPORTS.each{|k,v|
|
16
|
-
if(!File.exists?("#{Command.dev_root}/dep/#{k}"))
|
17
|
-
FileUtils.mkdir_p(File.dirname("#{Command.dev_root}/dep/#{k}")) if !File.exists?("#{Command.dev_root}/dep/#{k}")
|
18
|
-
dest="#{Command.dev_root}/dep/#{k}"
|
19
|
-
add "svn export #{v} #{Command.dev_root}/dep/#{k}" if !dest.include?("@")
|
20
|
-
add "svn export #{v} #{Command.dev_root}/dep/#{k}@" if dest.include?("@")
|
21
|
-
end
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
1
|
+
#
|
2
|
+
# use the SVN_EXPORTS hash to define svn exports destined for DEV_ROOT/dep
|
3
|
+
#
|
4
|
+
# SVN_EXPORT={ 'System.Data.SQLite/1.0.93.0' => 'https://third-party.googlecode.com/svn/trunk/System.Data.SQLite/1.0.93.0' }
|
5
|
+
#
|
6
|
+
class Setup < Array
|
7
|
+
def update
|
8
|
+
add 'bundle install' if(File.exists?('Gemfile'))
|
9
|
+
|
10
|
+
Dir.glob('*.gemspec').each{|gemspec_file|
|
11
|
+
add "<%Gemspec.update('#{gemspec_file}')%>"
|
12
|
+
}
|
13
|
+
|
14
|
+
if(defined?(SVN_EXPORTS))
|
15
|
+
SVN_EXPORTS.each{|k,v|
|
16
|
+
if(!File.exists?("#{Command.dev_root}/dep/#{k}"))
|
17
|
+
FileUtils.mkdir_p(File.dirname("#{Command.dev_root}/dep/#{k}")) if !File.exists?("#{Command.dev_root}/dep/#{k}")
|
18
|
+
dest="#{Command.dev_root}/dep/#{k}"
|
19
|
+
add "svn export #{v} #{Command.dev_root}/dep/#{k}" if !dest.include?("@")
|
20
|
+
add "svn export #{v} #{Command.dev_root}/dep/#{k}@" if dest.include?("@")
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
data/lib/text.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
class Text
|
2
|
-
def self.replace_in_glob(glob,search,replace)
|
3
|
-
Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.replace_in_file(filename,search,replace)
|
7
|
-
text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
|
8
|
-
#File.read(f,:encoding=>'UTF-8')
|
9
|
-
text2 = text1.gsub(search) { |str| str=replace }
|
10
|
-
unless text1==text2
|
11
|
-
File.open(filename,"w") { |f| f.puts text2 }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
1
|
+
class Text
|
2
|
+
def self.replace_in_glob(glob,search,replace)
|
3
|
+
Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.replace_in_file(filename,search,replace)
|
7
|
+
text1 = IO.read(filename).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
|
8
|
+
#File.read(f,:encoding=>'UTF-8')
|
9
|
+
text2 = text1.gsub(search) { |str| str=replace }
|
10
|
+
unless text1==text2
|
11
|
+
File.open(filename,"w") { |f| f.puts text2 }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
15
|
end
|
data/lib/timeout.rb
CHANGED
@@ -1,54 +1,58 @@
|
|
1
|
-
############################################################################
|
2
|
-
# The following code is based on code originally copied from
|
3
|
-
# https://gist.github.com/lpar/1032297
|
4
|
-
# Gist title: lpar/timeout.rb
|
5
|
-
############################################################################
|
6
|
-
# Runs a specified shell command in a separate thread.
|
7
|
-
# If it exceeds the given timeout in seconds, kills it.
|
8
|
-
# Returns any output produced by the command (stdout or stderr) as a String.
|
9
|
-
# Uses Kernel.select to wait up to the tick length (in seconds) between
|
10
|
-
# checks on the command's status
|
11
|
-
#
|
12
|
-
# If you've got a cleaner way of doing this, I'd be interested to see it.
|
13
|
-
# If you think you can do it with Ruby's Timeout module, think again.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
############################################################################
|
2
|
+
# The following code is based on code originally copied from
|
3
|
+
# https://gist.github.com/lpar/1032297
|
4
|
+
# Gist title: lpar/timeout.rb
|
5
|
+
############################################################################
|
6
|
+
# Runs a specified shell command in a separate thread.
|
7
|
+
# If it exceeds the given timeout in seconds, kills it.
|
8
|
+
# Returns any output produced by the command (stdout or stderr) as a String.
|
9
|
+
# Uses Kernel.select to wait up to the tick length (in seconds) between
|
10
|
+
# checks on the command's status
|
11
|
+
#
|
12
|
+
# If you've got a cleaner way of doing this, I'd be interested to see it.
|
13
|
+
# If you think you can do it with Ruby's Timeout module, think again.
|
14
|
+
<<<<<<< HEAD
|
15
|
+
def run_with_timeout(directory, command, timeout, tick)
|
16
|
+
=======
|
17
|
+
def run_with_timeout(directory,command, timeout, tick)
|
18
|
+
>>>>>>> 64a620397b11df71b841ad38df0941319776318a
|
19
|
+
output = ''
|
20
|
+
exit_code=1
|
21
|
+
begin
|
22
|
+
# Start task in another thread, which spawns a process
|
23
|
+
stdin, stderrout, thread = Open3.popen2e(command, :chdir=>directory)
|
24
|
+
# Get the pid of the spawned process
|
25
|
+
pid = thread[:pid]
|
26
|
+
start = Time.now
|
27
|
+
|
28
|
+
while (Time.now - start) < timeout and thread.alive?
|
29
|
+
# Wait up to `tick` seconds for output/error data
|
30
|
+
Kernel.select([stderrout], nil, nil, tick)
|
31
|
+
# Try to read the data
|
32
|
+
begin
|
33
|
+
output << stderrout.read_nonblock(BUFFER_SIZE)
|
34
|
+
rescue IO::WaitReadable
|
35
|
+
# A read would block, so loop around for another select
|
36
|
+
rescue EOFError
|
37
|
+
# Command has completed, not really an error...
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Give Ruby time to clean up the other thread
|
43
|
+
sleep 1
|
44
|
+
|
45
|
+
if thread.alive?
|
46
|
+
# We need to kill the process, because killing the thread leaves
|
47
|
+
# the process alive but detached, annoyingly enough.
|
48
|
+
Process.kill("TERM", pid)
|
49
|
+
else
|
50
|
+
exit_code=thread.value
|
51
|
+
end
|
52
|
+
|
53
|
+
ensure
|
54
|
+
stdin.close if stdin
|
55
|
+
stderrout.close if stderrout
|
56
|
+
end
|
57
|
+
return [output,exit_code]
|
54
58
|
end
|