dev 2.0.268 → 2.0.269

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 313d2e1a3959cd2a061d6da9c2e38e2172cdf50e
4
- data.tar.gz: ff3e2cff769253f5e0f17cffaefe483944bfd44e
3
+ metadata.gz: 0b589fd7c6e934568a25fedd9390eb9eb34c249b
4
+ data.tar.gz: f3120161faf84cb33c7ecde90ca3a36f69d0e378
5
5
  SHA512:
6
- metadata.gz: 0a18b7d175c5068791fcf29800def536abccf08c44ba4a90a89fe2919535954b3da7266bc9f1284c157a52bc0aafc48dac908cfa0be8ecd13e533c00fad6db8d
7
- data.tar.gz: b8922ab20d26b1ba881c0f1fb94022db185b867d12132adb5c90057e0d3d4e48009b500d838ab0ee34c2af9a205155c665684194303b9a6c7d2d9935d764b0bc
6
+ metadata.gz: 4a1005b6587fe75f6552d75f47753651b71f9968a8cfd4a75499d1252ccc4ccec35ce7599322ebb79c9d440613f337b4e65f2ec3bd215d00e5af37cceab91aae
7
+ data.tar.gz: cdd95c1496bdbca9e0d5cc90fc44a252ab5b51ce391f56fd932b848044316ede3488d7332c6df9d8ab42a5426c8b2e54e2295987eb98595f491a5ae29123c46f
data/bin/dev CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/evn ruby
2
2
  require 'dev'
3
3
  DEV.execute ARGV
@@ -1,7 +1,14 @@
1
- puts __FILE__ if defined?(DEBUG)
2
-
1
+ require_relative('environment.rb')
3
2
  class Array
3
+ attr_accessor :env
4
+ def intialize env=nil
5
+ @env=env
6
+ @env=Environment.new() if @env.nil?
7
+ @env=Environmnet.new() if !@env.kind_of?(Environment)
8
+ end
9
+
4
10
  def execute value=nil
11
+ @env=Environment.new() if @env.nil?
5
12
  i=0
6
13
  while i < self.length
7
14
  self[i]=Command.new(self[i]) if(self[i].is_a?(String))
@@ -11,13 +18,36 @@ class Array
11
18
  value.each{|k,v|self[i][k]=v}
12
19
  end
13
20
 
14
- self[i].execute if(self[i].is_a?(Command))
21
+ #self[i].execute if(self[i].is_a?(Command))
22
+ if(self[i].is_a?(Command))
23
+ self[i].execute
24
+ @env.out self[i].summary
25
+ end
26
+
15
27
  i=i+1
16
28
  end
17
29
  end
18
30
 
19
31
  def add command
20
- self << command if(!include?(command))
32
+ self << command if !has_command? command
33
+ end
34
+
35
+ def has_command? command
36
+ return true if(command.kind_of?(String) && !include?(command))
37
+ if(command.kind_of?(Command))
38
+ self.each{|c|
39
+ return true if(c[:input] == command[:input])
40
+ }
41
+ end
42
+ false
43
+ end
44
+
45
+ def add_quiet command
46
+ add Command.new({ :input => command, :quiet => true })
47
+ end
48
+
49
+ def add_passive command
50
+ add Command.new({ :input => command, :quiet => true, :ignore_failure => true })
21
51
  end
22
52
 
23
53
  def to_html
@@ -1,10 +1,12 @@
1
- puts __FILE__ if defined?(DEBUG)
2
-
1
+ require 'time'
3
2
  require 'open3'
4
3
  require_relative('timeout.rb')
5
4
  require_relative('timer.rb')
6
5
  require_relative('array.rb')
7
6
  require_relative('hash.rb')
7
+ require_relative('string.rb')
8
+ require_relative('environment.rb')
9
+ require_relative('dir.rb')
8
10
  BUFFER_SIZE=1024 if(!defined?(BUFFER_SIZE))
9
11
 
10
12
  # = Command
@@ -51,6 +53,10 @@ class Command < Hash
51
53
  end
52
54
  end
53
55
 
56
+ def save filename
57
+ File.open(filename,'w'){|f|f.write(to_json)}
58
+ end
59
+
54
60
  def open filename=''
55
61
  @filename=filename if filename.length > 0
56
62
  self.clear
@@ -63,6 +69,17 @@ class Command < Hash
63
69
  (self.has_key?(:quiet) && self[:quiet])
64
70
  end
65
71
 
72
+ def exit_code
73
+ self[:exit_code]
74
+ end
75
+
76
+ def output
77
+ self[:output]
78
+ end
79
+ def error
80
+ self[:error]
81
+ end
82
+
66
83
  def execute value=nil
67
84
 
68
85
  if(!value.nil? && value.is_a?(Hash))
@@ -105,11 +122,14 @@ class Command < Hash
105
122
  self[:elapsed] = timer.elapsed_str
106
123
  self[:end_time] = Time.now
107
124
  else
125
+ #puts "command execute with timeout #{self[:timeout]}"
108
126
  require_relative 'timeout.rb'
109
127
  result=run_with_timeout(self[:directory],self[:input], self[:timeout],2)
128
+ #puts "result #{result}"
110
129
  self[:output]=result[0]
111
- self[:error]=result[1]
112
- self[:exit_code]=result[2]
130
+ self[:exit_code]=result[1]
131
+ #self[:error]=result[1]
132
+ #self[:exit_code]=result[2]
113
133
 
114
134
  self[:elapsed] = timer.elapsed_str
115
135
  self[:end_time] = Time.now
@@ -174,10 +194,19 @@ class Command < Hash
174
194
  return dir
175
195
  end
176
196
 
197
+ #def self.execute_quiet command
198
+ # cmd=Command.new({ :input => command, :quiet => true, :ignore_failure => true})
199
+ # cmd.execute
200
+ # cmd
201
+ #end
202
+
177
203
  def self.execute command
178
- cmd = Command.new(command)
204
+ cmd = Command.new({ :input => command, :quiet => true}) if command.kind_of?(String)
205
+ cmd = command if command.kind_of?(Command)
206
+ cmd = Command.new(command) if command.kind_of?(Hash)
179
207
  cmd.execute
180
208
  cmd[:exit_code]
209
+ cmd
181
210
  end
182
211
 
183
212
  def self.exit_code command
@@ -205,17 +234,77 @@ class Command < Hash
205
234
  end
206
235
 
207
236
  def getFormattedTimeSpan timespan
237
+ result=''
208
238
  seconds = timespan.round
209
- seconds.to_s + " sec"
239
+ if(seconds > 99)
240
+ minutes=(seconds/60).round
241
+ result="#{minutes}m"
242
+ else
243
+ result="#{seconds}s" # 99s
244
+ end
245
+ result.fix(3)
210
246
  end
211
247
 
212
- def summary
248
+ def summary include_directory=false
213
249
  duration=""
214
- duration=getFormattedTimeSpan(self[:end_time]-self[:start_time])# + " - " if(!self[:end_time].nil?)
215
- #duration + "#{self[:exit_code].to_s} #{self[:input]} (#{self[:directory]})"
216
- status="OK "
217
- status="Error" if(!self.has_key?(:exit_code) || self[:exit_code] != 0)
218
- "#{status} '#{self[:input]}' (#{self[:directory]}) #{self[:exit_code].to_s} [#{duration}]"
250
+ duration=getFormattedTimeSpan(self[:end_time]-self[:start_time])
251
+ if(Environment.default.colorize?)
252
+ require 'ansi/code'
253
+ cduration = ANSI.reset + duration
254
+ #code=ANSI.green + '+ ' + ANSI.reset
255
+ #code=ANSI.red + '- ' + ANSI.reset if exit_code != 0
256
+ cinput = ANSI.reset + self[:input] + ANSI.reset
257
+ cinput = ANSI.red + self[:input] + ANSI.reset if exit_code != 0
258
+ cdirectory = ''
259
+ cdirectory = "(#{self[:directory]})" if include_directory
260
+ " #{cduration} #{cinput} #{cdirectory}"
261
+ else
262
+ code=' '
263
+ code='X' if exit_code != 0
264
+ sdirectory = ''
265
+ sdirectory = "(#{self[:directory]})" if include_directory
266
+ "#{code} #{duration} #{self[:input]} #{sdirectory}"
267
+ end
268
+ end
269
+
270
+ def format_property name,value
271
+ if(Environment.default.colorize?)
272
+ require 'ansi/code'
273
+ return "#{name}: " + ANSI.yellow + ANSI.bright + value.to_s.strip + ANSI.reset
274
+ else
275
+ return "#{name}: #{value}"
276
+ end
277
+ end
278
+
279
+ def info
280
+ result=format_property('input'.fix(15),self[:input]) + "\n"
281
+ result=result + format_property('directory'.fix(15),self[:directory]) + "\n"
282
+ result=result + format_property('exit_code'.fix(15),self[:exit_code]) + "\n"
283
+ result=result + format_property('duration'.fix(15),getFormattedTimeSpan(self[:end_time]-self[:start_time])) + "\n"
284
+ output=['']
285
+ output=self[:output].strip.split("\n") if !self[:output].nil?
286
+ if(output.length <= 1)
287
+ result=result + format_property('output'.fix(15),output[0]) + "\n"
288
+ #result=result + format_property('output'.fix(15),'') + "\n" if(output.length==0)
289
+ #result=result + format_property('output'.fix(15),output) + "\n" if(output.length==1)
290
+ else
291
+ result=result + format_property('output'.fix(15),'') + "\n"
292
+ output.each{|line|
293
+ result=result + ' '.fix(16) + line + "\n"
294
+ }
295
+ end
296
+ error=['']
297
+ error=self[:error].strip.split("\n") if !self[:error].nil?
298
+ if(error.length <= 1)
299
+ result=result + format_property('error'.fix(15),error[0]) + "\n"
300
+ #result=result + format_property('error'.fix(15),'') + "\n" if(error.length==0)
301
+ #result=result + format_property('error'.fix(15),error) + "\n" if(error.length==1)
302
+ else
303
+ result=result + format_property('error'.fix(15),'') + "\n"
304
+ error.each{|line|
305
+ result=result + ' '.fix(16) + line + "\n"
306
+ }
307
+ end
219
308
  end
220
309
 
221
310
  def to_html
@@ -1,18 +1,24 @@
1
- puts __FILE__ if defined?(DEBUG)
2
-
3
1
  require 'fileutils'
4
2
 
5
3
  class Dir
6
4
  def self.make directory
7
5
  FileUtils.mkdir_p directory if !File.exists? directory
8
6
  end
9
- def self.remove directory
10
- if(File.exists?(directory))
11
- begin
12
- FileUtils.rm_rf directory
13
- FileUtils.rm_r directory
14
- rescue
7
+ def self.remove directory, remove_empty_parents=false
8
+ begin
9
+ FileUtils.rm_rf directory if(!Dir.empty?(directory))
10
+ FileUtils.rm_r directory if(File.exists?(directory))
11
+ if(remove_empty_parents)
12
+ parent_dir=File.dirname(directory)
13
+ Dir.remove parent_dir, true if(Dir.empty?(parent_dir))
15
14
  end
15
+ rescue
16
+ end
17
+ end
18
+ def self.empty? directory
19
+ if((Dir.entries(directory) - %w{ . .. }).empty?)
20
+ return true
16
21
  end
22
+ false
17
23
  end
18
24
  end
@@ -3,60 +3,177 @@ puts __FILE__ if defined?(DEBUG)
3
3
  require_relative('string.rb')
4
4
 
5
5
  class Environment < Hash
6
+ attr_accessor :output
7
+ @@default=nil
8
+ def self.default
9
+ @@default=Environment.new if @@default.nil?
10
+ @@default
11
+ end
6
12
 
7
- @@debug=true if defined?(DEBUG)
8
- @@debug=false if !defined?(DEBUG)
9
- @@development_root=nil
13
+ def initialize env=nil
14
+ @output=''
15
+ @env=Hash.new
16
+ @env_aliases={'HOME' => ['USERPROFILE'],
17
+ 'DEV_ROOT' => ['DEV_HOME','HOME','USERPROFILE'],
18
+ 'USERNAME' => ['USER','USR']
19
+ }
20
+ env.each{|k,v| @env[k.to_s]=v} if !env.nil?
21
+ @@default=self if @@default.nil?
22
+ end
10
23
 
11
- def initialize
12
- self[:home]=Environment.home
13
- self[:machine]=Environment.machine
14
- self[:user]=Environment.user
24
+ #####Begin LEGACY support
25
+ def self.dev_root
26
+ default.root_dir
15
27
  end
16
28
 
17
- def self.set_development_root value
18
- @@development_root=value
19
- if(!value.nil?)
20
- FileUtils.mkdir_p value if(!File.exists?(value))
21
- ['bin','data','log','make','publish','test'].each{|dir|
22
- #FileUtils.mkdir_p("#{value}/#{dir}") if !File.exists? "#{value}/#{dir}"
23
- }
29
+ #####End LEGACY support
30
+ def root_dir
31
+ get_env('DEV_ROOT')
32
+ end
33
+
34
+ def home_dir
35
+ get_env('HOME')
36
+ end
37
+
38
+ def log_dir
39
+ dir="#{get_env('DEV_ROOT')}/log/#{user}@#{machine}"
40
+ FileUtils.mkdir_p dir if !File.exists? dir
41
+ dir
42
+ end
43
+
44
+ def make_dir
45
+ dir="#{get_env('DEV_ROOT')}/make"
46
+ FileUtils.mkdir_p dir if !File.exists? dir
47
+ dir
48
+ end
49
+
50
+ def publish_dir
51
+ dir="#{get_env('DEV_ROOT')}/publish"
52
+ FileUtils.mkdir_p dir if !File.exists? dir
53
+ dir
54
+ end
55
+
56
+ def wrk_dir
57
+ dir="#{get_env('DEV_ROOT')}/wrk"
58
+ FileUtils.mkdir_p dir if !File.exists? dir
59
+ dir
60
+ end
61
+
62
+ def machine
63
+ return ENV['COMPUTERNAME'] if !ENV['COMPUTERNAME'].nil?
64
+ machine = `hostname`
65
+ machine = machine.split('.')[0] if machine.include?('.')
66
+ return machine.strip
67
+ end
68
+
69
+ def user
70
+ get_env('USERNAME')
71
+ #return ENV['USER'] if !ENV['USER'].nil? #on Unix
72
+ #ENV['USERNAME']
73
+ end
74
+
75
+ def get_env key
76
+ if(!@env.nil? && @env.has_key?(key))
77
+ return @env[key]
78
+ end
79
+ value = ENV[key]
80
+ if(value.nil?)
81
+ if(@env_aliases.has_key?(key))
82
+ @env_aliases[key].each{|akey|
83
+ value=get_env(akey) if value.nil?
84
+ }
85
+ end
24
86
  end
87
+ value
25
88
  end
26
89
 
27
- def self.debug
28
- @@debug
90
+ def set_env key,value
91
+ @env[key]=value
29
92
  end
30
93
 
31
- def self.home
32
- ["USERPROFILE","HOME"].each {|v|
33
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
34
- }
35
- dir="~"
36
- dir=ENV["HOME"] unless ENV["HOME"].nil?
37
- dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
38
- return dir
94
+ def debug?
95
+ return true if get_env('DEBUG')=='true'
96
+ false
39
97
  end
40
98
 
41
- def self.configuration
42
- config="#{Environment.home}/dev.config.rb"
43
- if(!File.exists?(config))
44
- text=IO.read("#{File.dirname(__FILE__)}/../dev.config.rb")
45
- File.open(config,'w'){|f|f.write(text)}
99
+ def colorize?
100
+ colorize=true
101
+ if windows?
102
+ if(`gem list win32console`.include?('win32console'))
103
+ require 'ansi/code'
104
+ else
105
+ colorize=false
106
+ end
46
107
  end
47
- config
108
+ colorize
109
+ end
110
+
111
+ def out message
112
+ puts message if !get_env('SUPPRESS_CONSOLE_OUTPUT')
113
+ @output=@output+message+'\n'
48
114
  end
49
115
 
50
- def self.machine
51
- if !ENV['COMPUTERNAME'].nil?
52
- return ENV['COMPUTERNAME']
53
- end
116
+ def show_success?
117
+ true
118
+ end
54
119
 
55
- machine = `hostname`
56
- machine = machine.split('.')[0] if machine.include?('.')
57
- return machine.strip
120
+ def windows?
121
+ Gem.win_platform?
58
122
  end
59
123
 
124
+ #@@debug=true if defined?(DEBUG)
125
+ #@@debug=false if !defined?(DEBUG)
126
+ #@@development_root=nil
127
+
128
+ #def initialize
129
+ #self[:home]=Environment.home
130
+ #self[:machine]=Environment.machine
131
+ #self[:user]=Environment.user
132
+ #end
133
+
134
+ #def self.set_development_root value
135
+ # @@development_root=value
136
+ # if(!value.nil?)
137
+ # FileUtils.mkdir_p value if(!File.exists?(value))
138
+ # ['bin','data','log','make','publish','test'].each{|dir|
139
+ # #FileUtils.mkdir_p("#{value}/#{dir}") if !File.exists? "#{value}/#{dir}"
140
+ # }
141
+ # end
142
+ #end
143
+
144
+ #def self.debug
145
+ # @@debug
146
+ #end
147
+
148
+ #def self.home
149
+ # ["USERPROFILE","HOME"].each {|v|
150
+ # return ENV[v].gsub('\\','/') unless ENV[v].nil?
151
+ # }
152
+ # dir="~"
153
+ # dir=ENV["HOME"] unless ENV["HOME"].nil?
154
+ # dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
155
+ # return dir
156
+ #end
157
+
158
+ #def self.configuration
159
+ # config="#{Environment.home}/dev.config.rb"
160
+ # if(!File.exists?(config))
161
+ # text=IO.read("#{File.dirname(__FILE__)}/../dev.config.rb")
162
+ # File.open(config,'w'){|f|f.write(text)}
163
+ # end
164
+ # config
165
+ #end
166
+
167
+ #def self.machine
168
+ # if !ENV['COMPUTERNAME'].nil?
169
+ # return ENV['COMPUTERNAME']
170
+ # end
171
+
172
+ # machine = `hostname`
173
+ # machine = machine.split('.')[0] if machine.include?('.')
174
+ # return machine.strip
175
+ #end
176
+
60
177
  def self.remove directory
61
178
  if(File.exists?(directory))
62
179
  begin
@@ -67,21 +184,21 @@ class Environment < Hash
67
184
  end
68
185
  end
69
186
 
70
- def self.user
71
- return ENV['USER'] if !ENV['USER'].nil? #on Unix
72
- ENV['USERNAME']
73
- end
187
+ #def self.user
188
+ # return ENV['USER'] if !ENV['USER'].nil? #on Unix
189
+ # ENV['USERNAME']
190
+ #end
74
191
 
75
- def self.dev_root
76
- if(!@@development_root.nil?)
77
- return @@development_root
78
- end
79
- ["DEV_HOME","DEV_ROOT"].each {|v|
80
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
81
- }
82
- dir=home
83
- return dir
84
- end
192
+ #def self.dev_root
193
+ # if(!@@development_root.nil?)
194
+ # return @@development_root
195
+ # end
196
+ # ["DEV_HOME","DEV_ROOT"].each {|v|
197
+ # return ENV[v].gsub('\\','/') unless ENV[v].nil?
198
+ # }
199
+ # dir=home
200
+ # return dir
201
+ #end
85
202
 
86
203
  def self.check
87
204
  puts 'checking commands...'
@@ -132,7 +249,7 @@ class Environment < Hash
132
249
  end
133
250
 
134
251
  def self.get_latest_mtime directory
135
- mtime=nil
252
+ mtime=Time.new(1980)
136
253
  Dir.chdir(directory) do
137
254
  Dir.glob('**/*.*').each{|f|
138
255
  mtime=File.mtime(f) if mtime.nil? || File.mtime(f) > mtime