dev_commands 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +1,41 @@
1
- class Timer
2
- attr_accessor :start_time
3
-
4
- def initialize
5
- @start_time=Time.now
6
- end
7
-
8
- def elapsed # in seconds
9
- return Time.now-@start_time
10
- end
11
-
12
- def elapsed_str
13
- elapsed_str="[" + "%.0f" %(elapsed) + "s]"
14
- end
15
-
16
- def self.elapsed_exceeds?(name,duration_seconds)
17
- if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
18
- return true
19
- end
20
- return false
21
- end
22
-
23
- def self.get_elapsed(name)
24
- timestamp=get_timestamp(name)
25
- return Time.now-timestamp if(!timestamp.nil?)
26
- nil
27
- end
28
-
29
- def self.get_timestamp(name)
30
- dir=Rake.application.original_dir
31
- if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
32
- return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
33
- end
34
- nil
35
- end
36
-
37
- def self.set_timestamp(name)
38
- Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
39
- File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
40
- end
1
+ class Timer
2
+ attr_accessor :start_time
3
+
4
+ def initialize
5
+ @start_time=Time.now
6
+ end
7
+
8
+ def elapsed # in seconds
9
+ return Time.now-@start_time
10
+ end
11
+
12
+ def elapsed_str
13
+ elapsed_str="[" + "%.0f" %(elapsed) + "s]"
14
+ end
15
+
16
+ def self.elapsed_exceeds?(name,duration_seconds)
17
+ if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
18
+ return true
19
+ end
20
+ return false
21
+ end
22
+
23
+ def self.get_elapsed(name)
24
+ timestamp=get_timestamp(name)
25
+ return Time.now-timestamp if(!timestamp.nil?)
26
+ nil
27
+ end
28
+
29
+ def self.get_timestamp(name)
30
+ dir=Rake.application.original_dir
31
+ if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
32
+ return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
33
+ end
34
+ nil
35
+ end
36
+
37
+ def self.set_timestamp(name)
38
+ Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
39
+ File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
40
+ end
41
41
  end
data/lib/add.rb CHANGED
@@ -1,9 +1,20 @@
1
- class Add < Array
2
- def update
3
- if(File.exists?('.gitignore'))
4
- add 'git add --all'
5
- else
6
-
7
- end
8
- end
1
+ class Add < Array
2
+ def update
3
+ if(File.exists?('.gitignore'))
4
+ add 'git add --all'
5
+ else
6
+ if(defined?(SOURCE))
7
+ if(File.exists?('.svn'))
8
+ SOURCE.each{|f|
9
+ add "svn add #{f}" if `svn status #{f}`.include?('?')
10
+ }
11
+ end
12
+ if(File.exists?('.git'))
13
+ SOURCE.each{|f|
14
+ add "git add #{f} -v" if `git status #{f}`.include?('untracked')
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
9
20
  end
@@ -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
@@ -1,7 +1,31 @@
1
- class Build < Array
2
- def update
3
- Dir.glob('*.gemspec'){|gemspec|
4
- add "gem build #{gemspec}"
5
- }
6
- end
7
- end
1
+ class Build < Array
2
+ def update
3
+ Dir.glob('*.gemspec'){|gemspec|
4
+ add "gem build #{gemspec}"
5
+ }
6
+ Dir.glob('**/*.sln'){|sln_file|
7
+ vs_version=MSBuild.get_vs_version(sln_file)
8
+ }
9
+
10
+
11
+
12
+ end
13
+ end
14
+
15
+
16
+ #glob='**/*.{gemspec,sln}'
17
+ #glob=DEV_TASKS[:build_glob] if(defined?(DEV_TASKS)) && DEV_TASKS.has_key?(:build_glob)
18
+ # DEV_TASKS[:files][:build].each {|f|
19
+ # self.add "gem build #{f}" if(f.include?('.gemspec'))
20
+ # if(f.include?('.sln'))
21
+ # vs_version=MSBuild.get_vs_version(f)
22
+ # if File.exists? msbuild[vs_version]
23
+ # MSBuild.get_configurations(f).each{ |configuration|
24
+ # MSBuild.get_platforms(f).each{|platform|
25
+ # Console.debug "configuration='#{configuration}', platform='#{platform}'"
26
+ # self.add "\"#{msbuild[vs_version]}\" \"#{f}\" /nologo /p:Configuration=#{configuration} /p:Platform=\"#{platform}\""
27
+ # }
28
+ # }
29
+ # end
30
+ # end
31
+ # }
@@ -1,14 +1,14 @@
1
- class Clean < Array
2
- def update
3
- ['.yardoc','log','tmp','obj'].each{|dir|
4
- CLEAN.include(dir) if File.exists?(dir)
5
- }
6
-
7
- #CLEAN.include('.yardoc','log','tmp','*.gem','obj')
8
- CLEAN.include('*.gem')
9
- CLEAN.include('**/*.{suo,sdf}')
10
-
11
- add '<%Rake::Task[:clean].reenable%>'
12
- add '<%Rake::Task[:clean].invoke%>'
13
- end
1
+ class Clean < Array
2
+ def update
3
+ ['.yardoc','log','tmp','obj'].each{|dir|
4
+ CLEAN.include(dir) if File.exists?(dir)
5
+ }
6
+
7
+ #CLEAN.include('.yardoc','log','tmp','*.gem','obj')
8
+
9
+ CLEAN.include('**/*.{suo,sdf}')
10
+
11
+ add '<%Rake::Task[:clean].reenable%>'
12
+ add '<%Rake::Task[:clean].invoke%>'
13
+ end
14
14
  end
@@ -1,13 +1,14 @@
1
- class Clobber < Array
2
- def update
3
- ['bin','lib'].each{|dir|
4
- CLEAN.include(dir) if File.exists?(dir)
5
- }
6
-
7
- clean=Clean.new
8
- clean.update
9
-
10
- add '<%Rake::Task[:clobber].reenable%>'
11
- add '<%Rake::Task[:clobber].invoke%>'
12
- end
1
+ class Clobber < Array
2
+ def update
3
+ ['bin','lib'].each{|dir|
4
+ CLOBBER.include(dir) if File.exists?(dir)
5
+ }
6
+
7
+ clean=Clean.new
8
+ clean.update
9
+
10
+ CLOBBER.include('*.gem')
11
+ add '<%Rake::Task[:clobber].reenable%>'
12
+ add '<%Rake::Task[:clobber].invoke%>'
13
+ end
13
14
  end
@@ -1,129 +1,129 @@
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]}"
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
- puts ' '
72
- puts "exit_code=#{self[:exit_code]}"
73
- puts ' '
74
- puts self[:output]
75
- puts self[:error]
76
- puts ' '
77
- if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
78
- raise "#{self[:input]} failed"
79
- end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
80
- end
81
- end
82
-
83
- def self.machine
84
- if !ENV['COMPUTERNAME'].nil?
85
- return ENV['COMPUTERNAME']
86
- end
87
-
88
- machine = `hostname`
89
- machine = machine.split('.')[0] if machine.include?('.')
90
- return machine.strip
91
- end
92
-
93
- def self.user
94
- ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
95
- end
96
-
97
- def self.exit_code command
98
- cmd = Command.new(command)
99
- cmd[:ignore_failure]=true
100
- cmd.execute
101
- cmd[:exit_code]
102
- end
103
-
104
- def self.output command
105
- cmd = Command.new(command)
106
- cmd[:ignore_failure]=true
107
- cmd.execute
108
- cmd[:output]
109
- end
110
-
111
- def to_html
112
- if self[:exit_code] == 0
113
- [
114
- '<div><table><tr><td width="20"></td><td><pre>',
115
- self[:input],
116
- '</pre></td></tr></table></div>'
117
- ].join
118
- else
119
- [
120
- '<div><table><tr><td width="20"></td><td><pre>',
121
- self[:input],
122
- '</pre><table><tr><td width="20"></td><td><table>',
123
- 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>"] },
124
- '</table>',
125
- '</td></tr></table></td></tr></table></div>'
126
- ].join
127
- end
128
- 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]}"
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
+ puts ' '
72
+ puts "exit_code=#{self[:exit_code]}"
73
+ puts ' '
74
+ puts self[:output]
75
+ puts self[:error]
76
+ puts ' '
77
+ if(!self.has_key?(:ignore_failure) || !self[:ignore_failure])
78
+ raise "#{self[:input]} failed"
79
+ end #unless (self.has_key?(:ignore_failure) && self[:ignore_failure]==true)
80
+ end
81
+ end
82
+
83
+ def self.machine
84
+ if !ENV['COMPUTERNAME'].nil?
85
+ return ENV['COMPUTERNAME']
86
+ end
87
+
88
+ machine = `hostname`
89
+ machine = machine.split('.')[0] if machine.include?('.')
90
+ return machine.strip
91
+ end
92
+
93
+ def self.user
94
+ ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
95
+ end
96
+
97
+ def self.exit_code command
98
+ cmd = Command.new(command)
99
+ cmd[:ignore_failure]=true
100
+ cmd.execute
101
+ cmd[:exit_code]
102
+ end
103
+
104
+ def self.output command
105
+ cmd = Command.new(command)
106
+ cmd[:ignore_failure]=true
107
+ cmd.execute
108
+ cmd[:output]
109
+ end
110
+
111
+ def to_html
112
+ if self[:exit_code] == 0
113
+ [
114
+ '<div><table><tr><td width="20"></td><td><pre>',
115
+ self[:input],
116
+ '</pre></td></tr></table></div>'
117
+ ].join
118
+ else
119
+ [
120
+ '<div><table><tr><td width="20"></td><td><pre>',
121
+ self[:input],
122
+ '</pre><table><tr><td width="20"></td><td><table>',
123
+ 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>"] },
124
+ '</table>',
125
+ '</td></tr></table></td></tr></table></div>'
126
+ ].join
127
+ end
128
+ end
129
129
  end