dev_commands 0.0.33 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03a79f802142e9b59901a5a5df4ec62c6da72917
4
+ data.tar.gz: 88f07b604d98e548cd50a762461c9e4df96a57a9
5
+ SHA512:
6
+ metadata.gz: b4b68133b1963be964b68ca2b87b824edaa3d317a9a3d7802f3dde39029727c437ff9109215f9002d4c4af5c4afc9e43be0cab009268c0a52d3f16cdf76a8e66
7
+ data.tar.gz: 5c40038e5cf493efebcab64c8687deef9a4e02d8d53e91cf06da6baee452a81509124ec5c73250ffb4388218cc1b82b855a2eb483ed0b7d37a84c801463890e5
data/lib/analyze.rb CHANGED
@@ -1,8 +1,8 @@
1
- class Analyze < Array
2
- def update
3
- if(`gem list countloc`.include?('countloc ('))
4
- FileUtils.mkdir('doc') if(!File.exists?('doc'))
5
- add 'countloc -r * --html doc/countloc.html'
6
- end
7
- end
1
+ class Analyze < Array
2
+ def update
3
+ if(`gem list countloc`.include?('countloc ('))
4
+ FileUtils.mkdir('doc') if(!File.exists?('doc'))
5
+ add 'countloc -r * --html doc/countloc.html'
6
+ end
7
+ end
8
8
  end
data/lib/array.rb CHANGED
@@ -1,25 +1,25 @@
1
- class Array
2
- def execute
3
- i=0
4
- while i < self.length
5
- self[i]=Command.new(self[i]) if(self[i].is_a?(String))
6
- self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
7
- self[i].execute if(self[i].is_a?(Command))
8
- i=i+1
9
- end
10
- end
11
-
12
- def add command
13
- self << command if(!include?(command))
14
- end
15
-
16
- def to_html
17
- html=Array.new
18
- html << '<div>'
19
- self.each{|e|
20
- html << e.to_html if e.respond_to?(:to_html)
21
- }
22
- html << '</div>'
23
- html.join
24
- end
1
+ class Array
2
+ def execute
3
+ i=0
4
+ while i < self.length
5
+ self[i]=Command.new(self[i]) if(self[i].is_a?(String))
6
+ self[i]=Command.new(self[i]) if(self[i].is_a?(Hash) && !self[i].is_a?(Command))
7
+ self[i].execute if(self[i].is_a?(Command))
8
+ i=i+1
9
+ end
10
+ end
11
+
12
+ def add command
13
+ self << command if(!include?(command))
14
+ end
15
+
16
+ def to_html
17
+ html=Array.new
18
+ html << '<div>'
19
+ self.each{|e|
20
+ html << e.to_html if e.respond_to?(:to_html)
21
+ }
22
+ html << '</div>'
23
+ html.join
24
+ end
25
25
  end
data/lib/command.rb CHANGED
@@ -1,152 +1,152 @@
1
- require 'open3'
2
- require_relative('./array.rb')
3
- require_relative('./hash.rb')
4
- require_relative('./timer.rb')
5
-
6
- class Command < Hash
7
- def initialize command
8
-
9
- self[:input] = ''
10
- self[:timeout] = 0
11
- self[:directory] = ''
12
- self[:exit_code] = 0
13
- self[:output] = ''
14
- self[:error] = ''
15
- self[:machine] = ''
16
- self[:user] = ''
17
- self[:start_time] = nil
18
- self[:end_time] = nil
19
-
20
- if(command.kind_of?(String))
21
- self[:input] = command
22
- end
23
-
24
- if(command.kind_of?(Hash))
25
- command.each{|k,v|
26
- self[k.to_sym]=v
27
- }
28
- end
29
- end
30
-
31
- def execute
32
- puts "#{self[:input]}" if(!self.has_key?(:quiet) || !self[:quiet])
33
- pwd=Dir.pwd
34
- Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
35
- self[:directory] = pwd if(self[:directory].length==0)
36
-
37
- self[:machine] = Command.machine
38
- self[:user] = Command.user
39
-
40
- self[:start_time]=Time.now
41
- timer=Timer.new
42
- if self[:input].include?('<%') && self[:input].include?('%>')
43
- ruby = self[:input].gsub("<%","").gsub("%>","")
44
-
45
- begin
46
- self[:output]=eval(ruby)
47
- rescue
48
- self[:exit_code]=1
49
- self[:error]="unable to eval(#{ruby})"
50
- end
51
-
52
- self[:elapsed] = timer.elapsed_str
53
- self[:end_time] = Time.now
54
- else
55
- begin
56
- self[:output],self[:error],status= Open3.capture3(self[:input])
57
- self[:exit_code]=status.to_i
58
- self[:elapsed] = timer.elapsed_str
59
- self[:end_time] = Time.now
60
- rescue Exception => e
61
- self[:elapsed] = timer.elapsed_str
62
- self[:end_time] = Time.now
63
- self[:error] = "Exception: " + e.to_s
64
- self[:exit_code]=1
65
- end
66
- end
67
-
68
- Dir.chdir(pwd) if pwd != Dir.pwd
69
-
70
- if(self[:exit_code] != 0)
71
- if(!self.has_key?(:quiet) || !self[:quiet])
72
- puts ' '
73
- puts "exit_code=#{self[:exit_code]}"
74
- puts ' '
75
- puts self[:output]
76
- puts self[:error]
77
- puts ' '
78
- end
79
- if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
80
- raise "#{self[:input]} failed"
81
- end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
82
- end
83
- end
84
-
85
- def self.machine
86
- if !ENV['COMPUTERNAME'].nil?
87
- return ENV['COMPUTERNAME']
88
- end
89
-
90
- machine = `hostname`
91
- machine = machine.split('.')[0] if machine.include?('.')
92
- return machine.strip
93
- end
94
-
95
- def self.user
96
- ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
97
- end
98
-
99
- def self.home
100
- ["USERPROFILE","HOME"].each {|v|
101
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
102
- }
103
- dir="~"
104
- dir=ENV["HOME"] unless ENV["HOME"].nil?
105
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
106
- return dir
107
- end
108
-
109
- def self.dev_root
110
- ["DEV_HOME","DEV_ROOT"].each {|v|
111
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
112
- }
113
- dir=home
114
- #dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?
115
- return dir
116
- end
117
-
118
- def self.exit_code command
119
- cmd = Command.new(command)
120
- cmd[:ignore_failure]=true
121
- cmd[:quiet]=true
122
- cmd.execute
123
- cmd[:exit_code]
124
- end
125
-
126
- def self.output command
127
- cmd = Command.new(command)
128
- cmd[:ignore_failure]=true
129
- cmd[:quiet]=true
130
- cmd.execute
131
- cmd[:output]
132
- end
133
-
134
- def to_html
135
- if self[:exit_code] == 0
136
- [
137
- '<div><table><tr><td width="20"></td><td><pre>',
138
- self[:input],
139
- '</pre></td></tr></table></div>'
140
- ].join
141
- else
142
- [
143
- '<div><table><tr><td width="20"></td><td><pre>',
144
- self[:input],
145
- '</pre><table><tr><td width="20"></td><td><table>',
146
- map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
147
- '</table>',
148
- '</td></tr></table></td></tr></table></div>'
149
- ].join
150
- end
151
- end
1
+ require 'open3'
2
+ require_relative('./array.rb')
3
+ require_relative('./hash.rb')
4
+ require_relative('./timer.rb')
5
+
6
+ class Command < Hash
7
+ def initialize command
8
+
9
+ self[:input] = ''
10
+ self[:timeout] = 0
11
+ self[:directory] = ''
12
+ self[:exit_code] = 0
13
+ self[:output] = ''
14
+ self[:error] = ''
15
+ self[:machine] = ''
16
+ self[:user] = ''
17
+ self[:start_time] = nil
18
+ self[:end_time] = nil
19
+
20
+ if(command.kind_of?(String))
21
+ self[:input] = command
22
+ end
23
+
24
+ if(command.kind_of?(Hash))
25
+ command.each{|k,v|
26
+ self[k.to_sym]=v
27
+ }
28
+ end
29
+ end
30
+
31
+ def execute
32
+ puts "#{self[:input]}" if(!self.has_key?(:quiet) || !self[:quiet])
33
+ pwd=Dir.pwd
34
+ Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
35
+ self[:directory] = pwd if(self[:directory].length==0)
36
+
37
+ self[:machine] = Command.machine
38
+ self[:user] = Command.user
39
+
40
+ self[:start_time]=Time.now
41
+ timer=Timer.new
42
+ if self[:input].include?('<%') && self[:input].include?('%>')
43
+ ruby = self[:input].gsub("<%","").gsub("%>","")
44
+
45
+ begin
46
+ self[:output]=eval(ruby)
47
+ rescue
48
+ self[:exit_code]=1
49
+ self[:error]="unable to eval(#{ruby})"
50
+ end
51
+
52
+ self[:elapsed] = timer.elapsed_str
53
+ self[:end_time] = Time.now
54
+ else
55
+ begin
56
+ self[:output],self[:error],status= Open3.capture3(self[:input])
57
+ self[:exit_code]=status.to_i
58
+ self[:elapsed] = timer.elapsed_str
59
+ self[:end_time] = Time.now
60
+ rescue Exception => e
61
+ self[:elapsed] = timer.elapsed_str
62
+ self[:end_time] = Time.now
63
+ self[:error] = "Exception: " + e.to_s
64
+ self[:exit_code]=1
65
+ end
66
+ end
67
+
68
+ Dir.chdir(pwd) if pwd != Dir.pwd
69
+
70
+ if(self[:exit_code] != 0)
71
+ if(!self.has_key?(:quiet) || !self[:quiet])
72
+ puts ' '
73
+ puts "exit_code=#{self[:exit_code]}"
74
+ puts ' '
75
+ puts self[:output]
76
+ puts self[:error]
77
+ puts ' '
78
+ end
79
+ if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
80
+ raise "#{self[:input]} failed"
81
+ end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
82
+ end
83
+ end
84
+
85
+ def self.machine
86
+ if !ENV['COMPUTERNAME'].nil?
87
+ return ENV['COMPUTERNAME']
88
+ end
89
+
90
+ machine = `hostname`
91
+ machine = machine.split('.')[0] if machine.include?('.')
92
+ return machine.strip
93
+ end
94
+
95
+ def self.user
96
+ ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
97
+ end
98
+
99
+ def self.home
100
+ ["USERPROFILE","HOME"].each {|v|
101
+ return ENV[v].gsub('\\','/') unless ENV[v].nil?
102
+ }
103
+ dir="~"
104
+ dir=ENV["HOME"] unless ENV["HOME"].nil?
105
+ dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
106
+ return dir
107
+ end
108
+
109
+ def self.dev_root
110
+ ["DEV_HOME","DEV_ROOT"].each {|v|
111
+ return ENV[v].gsub('\\','/') unless ENV[v].nil?
112
+ }
113
+ dir=home
114
+ #dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?
115
+ return dir
116
+ end
117
+
118
+ def self.exit_code command
119
+ cmd = Command.new(command)
120
+ cmd[:ignore_failure]=true
121
+ cmd[:quiet]=true
122
+ cmd.execute
123
+ cmd[:exit_code]
124
+ end
125
+
126
+ def self.output command
127
+ cmd = Command.new(command)
128
+ cmd[:ignore_failure]=true
129
+ cmd[:quiet]=true
130
+ cmd.execute
131
+ cmd[:output]
132
+ end
133
+
134
+ def to_html
135
+ if self[:exit_code] == 0
136
+ [
137
+ '<div><table><tr><td width="20"></td><td><pre>',
138
+ self[:input],
139
+ '</pre></td></tr></table></div>'
140
+ ].join
141
+ else
142
+ [
143
+ '<div><table><tr><td width="20"></td><td><pre>',
144
+ self[:input],
145
+ '</pre><table><tr><td width="20"></td><td><table>',
146
+ map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
147
+ '</table>',
148
+ '</td></tr></table></td></tr></table></div>'
149
+ ].join
150
+ end
151
+ end
152
152
  end
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,36 +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
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
36
39
  end