dev_commands 0.0.49 → 0.0.50

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
- def run_with_timeout(directory,command, timeout, tick)
15
- output = ''
16
- exit_code=1
17
- begin
18
- # Start task in another thread, which spawns a process
19
- stdin, stderrout, thread = Open3.popen2e(command, :chdir=>directory)
20
- # Get the pid of the spawned process
21
- pid = thread[:pid]
22
- start = Time.now
23
-
24
- while (Time.now - start) < timeout and thread.alive?
25
- # Wait up to `tick` seconds for output/error data
26
- Kernel.select([stderrout], nil, nil, tick)
27
- # Try to read the data
28
- begin
29
- output << stderrout.read_nonblock(BUFFER_SIZE)
30
- rescue IO::WaitReadable
31
- # A read would block, so loop around for another select
32
- rescue EOFError
33
- # Command has completed, not really an error...
34
- break
35
- end
36
- end
37
-
38
- # Give Ruby time to clean up the other thread
39
- sleep 1
40
-
41
- if thread.alive?
42
- # We need to kill the process, because killing the thread leaves
43
- # the process alive but detached, annoyingly enough.
44
- Process.kill("TERM", pid)
45
- else
46
- exit_code=thread.value
47
- end
48
-
49
- ensure
50
- stdin.close if stdin
51
- stderrout.close if stderrout
52
- end
53
- return [output,exit_code]
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