dev 2.1.75 → 2.1.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +202 -202
- data/lib/apps/svn.rb +151 -151
- data/lib/apps/xcodebuild.rb +15 -15
- data/lib/base.rb +4 -4
- data/lib/base/dir.rb +98 -98
- data/lib/base/file.rb +34 -34
- data/lib/base/gemspec.rb +50 -50
- data/lib/base/hash.rb +20 -20
- data/lib/base/history.rb +38 -38
- data/lib/base/internet.rb +24 -24
- data/lib/base/project.rb +458 -458
- data/lib/base/string.rb +6 -6
- data/lib/base/text.rb +29 -29
- data/lib/base/timeout.rb +121 -121
- data/lib/base/timer.rb +44 -44
- data/lib/base/version.rb +82 -82
- data/lib/dev.config.rb +7 -7
- data/lib/tasks/clean.rb +9 -9
- data/lib/tasks/clobber.rb +25 -25
- data/lib/tasks/doc.rb +9 -9
- data/lib/tasks/info.rb +9 -9
- data/lib/tasks/publish.rb +33 -33
- data/lib/tasks/pull.rb +11 -11
- data/lib/tasks/update.rb +14 -14
- metadata +17 -3
data/lib/base/history.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
puts __FILE__ if defined?(DEBUG)
|
2
|
-
|
3
|
-
class History
|
4
|
-
attr_accessor :dev
|
5
|
-
|
6
|
-
def initialize dev=nil
|
7
|
-
@dev=dev
|
8
|
-
@dev=Dev.new if @dev.nil?
|
9
|
-
end
|
10
|
-
|
11
|
-
# .0. for 0 exit codes
|
12
|
-
# .X. for non 0 exit codes
|
13
|
-
# project name is contained in directory name
|
14
|
-
def get_commands pattern
|
15
|
-
commands=Array.new
|
16
|
-
Dir.chdir(@dev.log_dir) do
|
17
|
-
Dir.glob("*#{pattern.gsub('/','-')}*.*").each{|logfile|
|
18
|
-
commands << Command.new(JSON.parse(IO.read(logfile)))
|
19
|
-
}
|
20
|
-
end
|
21
|
-
commands
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_command command
|
25
|
-
code="0"
|
26
|
-
code="X" if command[:exit_code] !=0
|
27
|
-
directory=command[:directory].gsub(@dev.root_dir,'').gsub('/','-')
|
28
|
-
name="#{command[:input]}.#{code}.#{directory}.json"
|
29
|
-
filename="#{@dev.log_dir}/#{name}"
|
30
|
-
puts "add command #{filename}" if @dev.debug?
|
31
|
-
File.open(filename,'w'){|f|f.write(command.to_json)}
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_wrk_command project_fullname
|
35
|
-
commands=get_commands("#{project_fullname}".gsub('/','-'))
|
36
|
-
return commands[0] if commands.length > 0
|
37
|
-
nil
|
38
|
-
end
|
1
|
+
puts __FILE__ if defined?(DEBUG)
|
2
|
+
|
3
|
+
class History
|
4
|
+
attr_accessor :dev
|
5
|
+
|
6
|
+
def initialize dev=nil
|
7
|
+
@dev=dev
|
8
|
+
@dev=Dev.new if @dev.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
# .0. for 0 exit codes
|
12
|
+
# .X. for non 0 exit codes
|
13
|
+
# project name is contained in directory name
|
14
|
+
def get_commands pattern
|
15
|
+
commands=Array.new
|
16
|
+
Dir.chdir(@dev.log_dir) do
|
17
|
+
Dir.glob("*#{pattern.gsub('/','-')}*.*").each{|logfile|
|
18
|
+
commands << Command.new(JSON.parse(IO.read(logfile)))
|
19
|
+
}
|
20
|
+
end
|
21
|
+
commands
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_command command
|
25
|
+
code="0"
|
26
|
+
code="X" if command[:exit_code] !=0
|
27
|
+
directory=command[:directory].gsub(@dev.root_dir,'').gsub('/','-')
|
28
|
+
name="#{command[:input]}.#{code}.#{directory}.json"
|
29
|
+
filename="#{@dev.log_dir}/#{name}"
|
30
|
+
puts "add command #{filename}" if @dev.debug?
|
31
|
+
File.open(filename,'w'){|f|f.write(command.to_json)}
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_wrk_command project_fullname
|
35
|
+
commands=get_commands("#{project_fullname}".gsub('/','-'))
|
36
|
+
return commands[0] if commands.length > 0
|
37
|
+
nil
|
38
|
+
end
|
39
39
|
end
|
data/lib/base/internet.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
puts __FILE__ if defined?(DEBUG)
|
2
|
-
|
3
|
-
require 'open-uri'
|
4
|
-
require 'timeout'
|
5
|
-
class Internet
|
6
|
-
|
7
|
-
@@available=true
|
8
|
-
|
9
|
-
def self.available?
|
10
|
-
return @@available if !@@available.nil?
|
11
|
-
|
12
|
-
begin
|
13
|
-
index=open('http://www.google.com').read
|
14
|
-
if index.include?('<Title>Google')
|
15
|
-
@@available = true
|
16
|
-
else
|
17
|
-
puts "open('http://www.google.com') returned false"
|
18
|
-
end
|
19
|
-
rescue Exception => e
|
20
|
-
puts "open('http://www.google.com') raised an exception: #{e.to_s}"
|
21
|
-
@@available = false
|
22
|
-
end
|
23
|
-
@@available
|
24
|
-
end
|
1
|
+
puts __FILE__ if defined?(DEBUG)
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'timeout'
|
5
|
+
class Internet
|
6
|
+
|
7
|
+
@@available=true
|
8
|
+
|
9
|
+
def self.available?
|
10
|
+
return @@available if !@@available.nil?
|
11
|
+
|
12
|
+
begin
|
13
|
+
index=open('http://www.google.com').read
|
14
|
+
if index.include?('<Title>Google')
|
15
|
+
@@available = true
|
16
|
+
else
|
17
|
+
puts "open('http://www.google.com') returned false"
|
18
|
+
end
|
19
|
+
rescue Exception => e
|
20
|
+
puts "open('http://www.google.com') raised an exception: #{e.to_s}"
|
21
|
+
@@available = false
|
22
|
+
end
|
23
|
+
@@available
|
24
|
+
end
|
25
25
|
end
|
data/lib/base/project.rb
CHANGED
@@ -1,458 +1,458 @@
|
|
1
|
-
puts __FILE__ if defined?(DEBUG)
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
require 'rake'
|
5
|
-
require_relative('../apps/svn.rb')
|
6
|
-
require_relative('dir.rb')
|
7
|
-
require_relative('environment.rb')
|
8
|
-
require_relative('string.rb')
|
9
|
-
|
10
|
-
class Project < Hash
|
11
|
-
attr_accessor :filename,:env
|
12
|
-
|
13
|
-
def initialize value='',fullname=''
|
14
|
-
@filename=''
|
15
|
-
@env=Environment.new
|
16
|
-
self[:url]=Project.get_url
|
17
|
-
self[:fullname]=Project.get_fullname_from_url self[:url] if self[:url].length > 0
|
18
|
-
self[:timeout]=60*5
|
19
|
-
if value.is_a?(String)
|
20
|
-
self[:url] = value if value.is_a?(String) && value.length > 0
|
21
|
-
self[:fullname] = Project.get_fullname_from_url self[:url]
|
22
|
-
elsif(value.is_a?(Hash))
|
23
|
-
value.each{|k,v|self[k.to_sym]=v}
|
24
|
-
else
|
25
|
-
self[:fullname]=Project.get_fullname_from_url self[:url] if self[:url].length > 0
|
26
|
-
end
|
27
|
-
self[:fullname] = fullname if fullname.length > 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def set_timeout value
|
31
|
-
self[:timeout] = value if value.is_a? Numeric
|
32
|
-
self[:timeout] = value.gsub('m','').strip.to_f * 60 if value.include?('m')
|
33
|
-
self[:timeout] = value.gsub('s','').strip.to_f * 60 if value.include?('s')
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.get_url directory=Rake.application.original_dir
|
37
|
-
url=''
|
38
|
-
Dir.chdir(directory) do
|
39
|
-
url=`git config --get remote.origin.url`.strip if(File.exists?('.git'))
|
40
|
-
url= Svn.url.strip if(File.exists?('.svn'))
|
41
|
-
end
|
42
|
-
url
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.get_fullname directory
|
46
|
-
directory.gsub(@env.wrk_dir,'')
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.get_fullname_from_url url
|
50
|
-
return url.gsub('http://','').gsub('https://','').gsub('.com/','/').gsub('.git','')
|
51
|
-
end
|
52
|
-
|
53
|
-
def url; self[:url]; end
|
54
|
-
def fullname; self[:fullname]; end
|
55
|
-
|
56
|
-
def name
|
57
|
-
parts=fullname.split('/')
|
58
|
-
parts[parts.length-1]
|
59
|
-
end
|
60
|
-
|
61
|
-
def wrk_dir; "#{@env.wrk_dir}/#{self.fullname}"; end
|
62
|
-
def make_dir tag=''
|
63
|
-
"#{@env.make_dir}/#{self.fullname}" if tag.length==0
|
64
|
-
"#{@env.make_dir}/#{self.fullname}-#{tag}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def pull
|
68
|
-
if(File.exists?(wrk_dir) && File.exists?("#{wrk_dir}/.git"))
|
69
|
-
Dir.chdir(wrk_dir) do
|
70
|
-
puts "git pull (#{wrk_dir})"
|
71
|
-
puts `git pull`
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def clone
|
77
|
-
if(!File.exists?(wrk_dir) && self[:url].include?('.git'))
|
78
|
-
cmd=Command.new({ :input => "git clone #{self[:url]} #{self.wrk_dir}", :quiet => true,:ignore_failure => true})
|
79
|
-
cmd.execute
|
80
|
-
@env.out cmd.summary
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def checkout
|
85
|
-
if(!File.exists?(wrk_dir) && self[:url].include?('svn'))
|
86
|
-
cmd=Command.new({ :input => "svn checkout #{self.url} #{self.wrk_dir}", :quiet => true,:ignore_failure => true})
|
87
|
-
cmd.execute
|
88
|
-
@env.out cmd.summary
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def rake
|
93
|
-
if(!File.exists?(self.wrk_dir))
|
94
|
-
clone
|
95
|
-
checkout
|
96
|
-
end
|
97
|
-
if(File.exists?(self.wrk_dir))
|
98
|
-
Dir.chdir(self.wrk_dir) do
|
99
|
-
rake = Command.new({ :input => 'rake', :timeout => 300, :ignore_failure => true })
|
100
|
-
rake.execute
|
101
|
-
@env.out rake.summary
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
def latest_tag update=false
|
109
|
-
makedir="#{@env.make_dir}/#{self.fullname}"
|
110
|
-
FileUtils.mkdir_p(File.dirname(makedir)) if !File.exists?(File.dirname(makedir))
|
111
|
-
if(File.exists?(makedir))
|
112
|
-
Dir.chdir(makedir) do
|
113
|
-
Command.exit_code('git pull') if update
|
114
|
-
end
|
115
|
-
else
|
116
|
-
if(update)
|
117
|
-
clone=Command.new("git clone #{self.url} #{makedir}")
|
118
|
-
clone[:quiet]=true
|
119
|
-
clone[:ignore_failure]=true
|
120
|
-
clone.execute
|
121
|
-
end
|
122
|
-
end
|
123
|
-
if(File.exists?(makedir))
|
124
|
-
Dir.chdir(makedir) do
|
125
|
-
begin
|
126
|
-
return Git.latest_tag
|
127
|
-
rescue
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
''
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
def log_filenames tags=nil
|
137
|
-
tags=Array.new if tags.nil?
|
138
|
-
filenames=Array.new
|
139
|
-
Dir.chdir(@env.log_dir) do
|
140
|
-
dotname=fullname.gsub('/','.')
|
141
|
-
Dir.glob("#{dotname}*.json").each{|f|
|
142
|
-
if(tags.length==0)
|
143
|
-
filenames << "#{@env.log_dir}/#{f}"
|
144
|
-
else
|
145
|
-
has_tags=true
|
146
|
-
tags.each{|tag|
|
147
|
-
has_tags=false if !f.include? tag
|
148
|
-
}
|
149
|
-
filenames << "#{@env.log_dir}/#{f}" if has_tags
|
150
|
-
end
|
151
|
-
}
|
152
|
-
end
|
153
|
-
filenames
|
154
|
-
end
|
155
|
-
|
156
|
-
def command_history tags=nil
|
157
|
-
commands=Array.new
|
158
|
-
log_filenames(tags).each{|logfile|
|
159
|
-
begin
|
160
|
-
cmd=Command.new(JSON.parse(IO.read(logfile)))
|
161
|
-
commands << cmd
|
162
|
-
rescue
|
163
|
-
end
|
164
|
-
|
165
|
-
}
|
166
|
-
commands
|
167
|
-
end
|
168
|
-
|
169
|
-
def work_up_to_date?
|
170
|
-
if wrk_dir == Rake.application.original_dir
|
171
|
-
logfile=get_logfile ['up2date']
|
172
|
-
if File.exists? logfile
|
173
|
-
last_work_time=File.mtime(logfile)
|
174
|
-
last_file_changed=Dir.get_latest_mtime Rake.application.original_dir
|
175
|
-
if last_work_time > last_file_changed
|
176
|
-
CLEAN.include logfile
|
177
|
-
return true
|
178
|
-
else
|
179
|
-
puts " deleting #{logfile}" if @env.debug?
|
180
|
-
File.delete(logfile)
|
181
|
-
end
|
182
|
-
else
|
183
|
-
puts "logfile #{logfile} does NOT exist." if @env.debug?
|
184
|
-
end
|
185
|
-
else
|
186
|
-
puts "wrk_dir does not match Rake.application.original_dir" if @env.debug?
|
187
|
-
end
|
188
|
-
false
|
189
|
-
end
|
190
|
-
|
191
|
-
def mark_work_up_to_date
|
192
|
-
if wrk_dir == Rake.application.original_dir
|
193
|
-
logfile=get_logfile ['up2date']
|
194
|
-
puts " writing #{logfile}" if Environment.default.debug?
|
195
|
-
File.open(logfile,'w'){|f|f.write(' ')}
|
196
|
-
else
|
197
|
-
puts "wrk_dir does not match Rake.application.original_dir" if @env.debug?
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def get_logfile tags
|
202
|
-
tagstring=''
|
203
|
-
tagstring=tags if tags.kind_of?(String)
|
204
|
-
tagstring=tags.join('.') if tags.kind_of?(Array)
|
205
|
-
name="#{self.fullname}.#{tagstring}.json".gsub('/','.')
|
206
|
-
"#{@env.log_dir}/#{name}"
|
207
|
-
end
|
208
|
-
|
209
|
-
def list
|
210
|
-
history=command_history
|
211
|
-
if(history.length==0)
|
212
|
-
@env.out "? #{fullname}"
|
213
|
-
else
|
214
|
-
status=0
|
215
|
-
history.each{|c|
|
216
|
-
status=c.exit_code if c.exit_code != 0
|
217
|
-
}
|
218
|
-
if(status==0)
|
219
|
-
@env.out " #{fullname}"
|
220
|
-
else
|
221
|
-
if(@env.colorize?)
|
222
|
-
require 'ansi/code'
|
223
|
-
@env.out ANSI.red + ANSI.bright + "X #{fullname}" + ANSI.reset
|
224
|
-
else
|
225
|
-
@env.out "X #{fullname}"
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def out_brackets message
|
232
|
-
if(@env.colorize?)
|
233
|
-
require 'ansi/code'
|
234
|
-
@env.out "[" + ANSI.blue + ANSI.bright + message + ANSI.reset + ']'
|
235
|
-
else
|
236
|
-
@env.out "[#{message}]"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def out_cyan message
|
241
|
-
if(@env.colorize?)
|
242
|
-
require 'ansi/code'
|
243
|
-
@env.out ANSI.cyan + ANSI.bright + message + ANSI.reset
|
244
|
-
else
|
245
|
-
@env.out "#{message}"
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
def out_property name,value
|
250
|
-
if(@env.colorize?)
|
251
|
-
require 'ansi/code'
|
252
|
-
@env.out "#{name}: " + ANSI.white + ANSI.bold + value.to_s.strip + ANSI.reset
|
253
|
-
else
|
254
|
-
@env.out "#{name}: #{value}"
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
def info
|
259
|
-
infoCmd=Command.new({ :input => 'info', :exit_code => 0 })
|
260
|
-
#out_cyan '========================================================='
|
261
|
-
#out_cyan fullname
|
262
|
-
out_property "fullname".fix(15), fullname
|
263
|
-
out_property "url".fix(15), url
|
264
|
-
wrk_history=command_history ['work']
|
265
|
-
out_property "work status".fix(15), "?" if wrk_history.length == 0
|
266
|
-
out_property "work status".fix(15), wrk_history[0].summary if wrk_history.length > 0
|
267
|
-
if(wrk_history.length > 0)
|
268
|
-
@env.out wrk_history[0].info
|
269
|
-
end
|
270
|
-
make_history=command_history ['make', latest_tag]
|
271
|
-
out_property "make status".fix(15),"?" if make_history.length == 0
|
272
|
-
out_property "make status".fix(15), make_history[0].summary if make_history.length > 0
|
273
|
-
if(make_history.length >0)
|
274
|
-
@env.out make_history[0].info
|
275
|
-
end
|
276
|
-
infoCmd
|
277
|
-
end
|
278
|
-
|
279
|
-
def clobber
|
280
|
-
clobberCmd=Command.new('clobber')
|
281
|
-
clobberCmd[:exit_code]=0
|
282
|
-
if(File.exists?(wrk_dir))
|
283
|
-
Dir.remove wrk_dir,true
|
284
|
-
@env.out "removed #{wrk_dir}"
|
285
|
-
end
|
286
|
-
if(File.exists?(make_dir))
|
287
|
-
Dir.remove make_dir,true
|
288
|
-
@env.out "removed #{make_dir}"
|
289
|
-
end
|
290
|
-
clobberCmd
|
291
|
-
end
|
292
|
-
|
293
|
-
def work
|
294
|
-
clone
|
295
|
-
checkout
|
296
|
-
logfile=get_logfile ['work']
|
297
|
-
if(File.exists?(wrk_dir))
|
298
|
-
rake_default=Command.new({:input =>'rake default',:quiet => true,:ignore_failure => true})
|
299
|
-
if(last_work_mtime.nil? || last_work_mtime < Dir.get_latest_mtime(wrk_dir))
|
300
|
-
Dir.chdir(wrk_dir) do
|
301
|
-
|
302
|
-
@env.out fullname
|
303
|
-
|
304
|
-
if(!File.exists?'rakefile.rb')
|
305
|
-
rake_default[:exit_code]=1
|
306
|
-
rake_default[:error]="rakefile.rb not found."
|
307
|
-
rake_default[:start_time]=Time.now
|
308
|
-
rake_default[:end_time]=Time.now
|
309
|
-
else
|
310
|
-
#rake_default[:timeout] = self[:timeout]
|
311
|
-
rake_default.execute
|
312
|
-
end
|
313
|
-
rake_default.save logfile
|
314
|
-
update_status
|
315
|
-
@env.out rake_default.summary true
|
316
|
-
return rake_default
|
317
|
-
end
|
318
|
-
else
|
319
|
-
if(File.exists?(logfile))
|
320
|
-
rake_default.open logfile
|
321
|
-
@env.out rake_default.summary true if(rake_default[:exit_code] != 0 || @env.show_success?)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
rake_default
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def make tag=''
|
329
|
-
tag=latest_tag true if tag.length==0
|
330
|
-
#return if tag.length==0
|
331
|
-
raise 'no tag specified' if tag.length==0
|
332
|
-
|
333
|
-
rake_default=Command.new({:input => 'rake default',:quiet => true,:ignore_failure => true})
|
334
|
-
logfile=get_logfile ['make',tag]
|
335
|
-
if(File.exists?(logfile))
|
336
|
-
rake_default.open logfile
|
337
|
-
@env.out rake_default.summary true if(rake_default[:exit_code] != 0) || @env.show_success?
|
338
|
-
rake_default
|
339
|
-
else
|
340
|
-
makedir=make_dir tag
|
341
|
-
FileUtils.mkdir_p(File.dirname(makedir)) if !File.exists? File.dirname(makedir)
|
342
|
-
if(self[:url].include?('.git'))
|
343
|
-
if(!File.exists?(makedir))
|
344
|
-
clone=Command.new({:input=>"git clone #{self[:url]} #{makedir}",:quiet=>true})
|
345
|
-
clone.execute
|
346
|
-
end
|
347
|
-
end
|
348
|
-
if(File.exists?(makedir))
|
349
|
-
Dir.chdir(makedir) do
|
350
|
-
checkout=Command.new({:input=>"git checkout #{tag}",:quiet=>true})
|
351
|
-
checkout.execute
|
352
|
-
FileUtils.rm_r '.git'
|
353
|
-
if(!File.exists?'rakefile.rb')
|
354
|
-
rake_default[:exit_code]=1
|
355
|
-
rake_default[:error]="rakefile.rb not found."
|
356
|
-
rake_default[:start_time]=Time.now
|
357
|
-
rake_default[:end_time]=Time.now
|
358
|
-
else
|
359
|
-
#rake_default[:timeout] = self[:timeout]
|
360
|
-
rake_default.execute
|
361
|
-
end
|
362
|
-
rake_default.save logfile
|
363
|
-
update_status
|
364
|
-
@env.out rake_default.summary true
|
365
|
-
rake_default
|
366
|
-
end
|
367
|
-
else
|
368
|
-
puts "Project make make_dir #{makedir} does not exist." if @env.debug?
|
369
|
-
end
|
370
|
-
|
371
|
-
begin
|
372
|
-
FileUtils.rm_r makedir
|
373
|
-
rescue
|
374
|
-
end
|
375
|
-
rake_default
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
def last_work_mtime
|
380
|
-
logfile=get_logfile ['work']
|
381
|
-
return File.mtime(logfile) if File.exists? logfile
|
382
|
-
nil
|
383
|
-
end
|
384
|
-
|
385
|
-
def update_status
|
386
|
-
status_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.status.json"
|
387
|
-
status=Hash.new({'status'=>'?'})
|
388
|
-
wrk_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.json"
|
389
|
-
if(File.exists?(wrk_logfile))
|
390
|
-
rake_default=Command.new(JSON.parse(IO.read(wrk_logfile)))
|
391
|
-
status[:work_logfile]=wrk_logfile
|
392
|
-
status['status']='0'
|
393
|
-
status['status']='X' if rake_default[:exit_code] != 0
|
394
|
-
end
|
395
|
-
make_logfile="#{@env.root_dir}/log/#{self.fullname}/#{latest_tag}/#{@env.user}@#{@env.machine}.json"
|
396
|
-
if(File.exists?(make_logfile))
|
397
|
-
rake_default=Command.new(JSON.parse(IO.read(make_logfile)))
|
398
|
-
status[:make_logfile]=make_logfile
|
399
|
-
status['status']='0'
|
400
|
-
status['status']='X' if rake_default[:exit_code] != 0
|
401
|
-
else
|
402
|
-
status['status']='?'
|
403
|
-
end
|
404
|
-
FileUtils.mkdir_p(File.dirname(status_logfile)) if !File.exists?(File.dirname(status_logfile))
|
405
|
-
File.open(status_logfile,'w'){|f|f.write(status.to_json)}
|
406
|
-
end
|
407
|
-
|
408
|
-
def status
|
409
|
-
status_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.status.json"
|
410
|
-
update_status if !File.exists? status_logfile
|
411
|
-
if(File.exists?(status_logfile))
|
412
|
-
statusHash=JSON.parse(IO.read(status_logfile))
|
413
|
-
return statusHash['status'] if(statusHash.has_key?('status'))
|
414
|
-
end
|
415
|
-
'?'
|
416
|
-
end
|
417
|
-
|
418
|
-
def report
|
419
|
-
end
|
420
|
-
|
421
|
-
def update
|
422
|
-
clone
|
423
|
-
checkout
|
424
|
-
if(File.exists?(wrk_dir))
|
425
|
-
Dir.chdir(wrk_dir) do
|
426
|
-
if(File.exists?('.git'))
|
427
|
-
pull=Command.execute(Command.new({:input => 'git pull', :quiet => true, :ignore_failure => true}))
|
428
|
-
@env.out pull.summary true
|
429
|
-
return pull
|
430
|
-
end
|
431
|
-
if(File.exists?('.svn'))
|
432
|
-
updateCmd=Command.execute(Command.new({:input => 'svn update', :quiet => true, :ignore_failure => true}))
|
433
|
-
@env.out updateCmd.summary true
|
434
|
-
return updateCmd
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
438
|
-
return Command.new({:exit_code => 1})
|
439
|
-
end
|
440
|
-
|
441
|
-
def tags
|
442
|
-
tags=Array.new
|
443
|
-
if !File.exists? wrk_dir
|
444
|
-
clone=Command.new({:input=>'git clone #{self[:url]} #{wrk_dir}',:quiet=>true})
|
445
|
-
clone.execute
|
446
|
-
end
|
447
|
-
Dir.chdir(wrk_dir) do
|
448
|
-
Command.output('git tag').split('\n').each{|line|
|
449
|
-
tag=line.strip
|
450
|
-
tags << tag if tag.length < 0
|
451
|
-
}
|
452
|
-
end
|
453
|
-
tags
|
454
|
-
end
|
455
|
-
|
456
|
-
|
457
|
-
end
|
458
|
-
|
1
|
+
puts __FILE__ if defined?(DEBUG)
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'rake'
|
5
|
+
require_relative('../apps/svn.rb')
|
6
|
+
require_relative('dir.rb')
|
7
|
+
require_relative('environment.rb')
|
8
|
+
require_relative('string.rb')
|
9
|
+
|
10
|
+
class Project < Hash
|
11
|
+
attr_accessor :filename,:env
|
12
|
+
|
13
|
+
def initialize value='',fullname=''
|
14
|
+
@filename=''
|
15
|
+
@env=Environment.new
|
16
|
+
self[:url]=Project.get_url
|
17
|
+
self[:fullname]=Project.get_fullname_from_url self[:url] if self[:url].length > 0
|
18
|
+
self[:timeout]=60*5
|
19
|
+
if value.is_a?(String)
|
20
|
+
self[:url] = value if value.is_a?(String) && value.length > 0
|
21
|
+
self[:fullname] = Project.get_fullname_from_url self[:url]
|
22
|
+
elsif(value.is_a?(Hash))
|
23
|
+
value.each{|k,v|self[k.to_sym]=v}
|
24
|
+
else
|
25
|
+
self[:fullname]=Project.get_fullname_from_url self[:url] if self[:url].length > 0
|
26
|
+
end
|
27
|
+
self[:fullname] = fullname if fullname.length > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_timeout value
|
31
|
+
self[:timeout] = value if value.is_a? Numeric
|
32
|
+
self[:timeout] = value.gsub('m','').strip.to_f * 60 if value.include?('m')
|
33
|
+
self[:timeout] = value.gsub('s','').strip.to_f * 60 if value.include?('s')
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_url directory=Rake.application.original_dir
|
37
|
+
url=''
|
38
|
+
Dir.chdir(directory) do
|
39
|
+
url=`git config --get remote.origin.url`.strip if(File.exists?('.git'))
|
40
|
+
url= Svn.url.strip if(File.exists?('.svn'))
|
41
|
+
end
|
42
|
+
url
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_fullname directory
|
46
|
+
directory.gsub(@env.wrk_dir,'')
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_fullname_from_url url
|
50
|
+
return url.gsub('http://','').gsub('https://','').gsub('.com/','/').gsub('.git','')
|
51
|
+
end
|
52
|
+
|
53
|
+
def url; self[:url]; end
|
54
|
+
def fullname; self[:fullname]; end
|
55
|
+
|
56
|
+
def name
|
57
|
+
parts=fullname.split('/')
|
58
|
+
parts[parts.length-1]
|
59
|
+
end
|
60
|
+
|
61
|
+
def wrk_dir; "#{@env.wrk_dir}/#{self.fullname}"; end
|
62
|
+
def make_dir tag=''
|
63
|
+
"#{@env.make_dir}/#{self.fullname}" if tag.length==0
|
64
|
+
"#{@env.make_dir}/#{self.fullname}-#{tag}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def pull
|
68
|
+
if(File.exists?(wrk_dir) && File.exists?("#{wrk_dir}/.git"))
|
69
|
+
Dir.chdir(wrk_dir) do
|
70
|
+
puts "git pull (#{wrk_dir})"
|
71
|
+
puts `git pull`
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def clone
|
77
|
+
if(!File.exists?(wrk_dir) && self[:url].include?('.git'))
|
78
|
+
cmd=Command.new({ :input => "git clone #{self[:url]} #{self.wrk_dir}", :quiet => true,:ignore_failure => true})
|
79
|
+
cmd.execute
|
80
|
+
@env.out cmd.summary
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def checkout
|
85
|
+
if(!File.exists?(wrk_dir) && self[:url].include?('svn'))
|
86
|
+
cmd=Command.new({ :input => "svn checkout #{self.url} #{self.wrk_dir}", :quiet => true,:ignore_failure => true})
|
87
|
+
cmd.execute
|
88
|
+
@env.out cmd.summary
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def rake
|
93
|
+
if(!File.exists?(self.wrk_dir))
|
94
|
+
clone
|
95
|
+
checkout
|
96
|
+
end
|
97
|
+
if(File.exists?(self.wrk_dir))
|
98
|
+
Dir.chdir(self.wrk_dir) do
|
99
|
+
rake = Command.new({ :input => 'rake', :timeout => 300, :ignore_failure => true })
|
100
|
+
rake.execute
|
101
|
+
@env.out rake.summary
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
def latest_tag update=false
|
109
|
+
makedir="#{@env.make_dir}/#{self.fullname}"
|
110
|
+
FileUtils.mkdir_p(File.dirname(makedir)) if !File.exists?(File.dirname(makedir))
|
111
|
+
if(File.exists?(makedir))
|
112
|
+
Dir.chdir(makedir) do
|
113
|
+
Command.exit_code('git pull') if update
|
114
|
+
end
|
115
|
+
else
|
116
|
+
if(update)
|
117
|
+
clone=Command.new("git clone #{self.url} #{makedir}")
|
118
|
+
clone[:quiet]=true
|
119
|
+
clone[:ignore_failure]=true
|
120
|
+
clone.execute
|
121
|
+
end
|
122
|
+
end
|
123
|
+
if(File.exists?(makedir))
|
124
|
+
Dir.chdir(makedir) do
|
125
|
+
begin
|
126
|
+
return Git.latest_tag
|
127
|
+
rescue
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
''
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def log_filenames tags=nil
|
137
|
+
tags=Array.new if tags.nil?
|
138
|
+
filenames=Array.new
|
139
|
+
Dir.chdir(@env.log_dir) do
|
140
|
+
dotname=fullname.gsub('/','.')
|
141
|
+
Dir.glob("#{dotname}*.json").each{|f|
|
142
|
+
if(tags.length==0)
|
143
|
+
filenames << "#{@env.log_dir}/#{f}"
|
144
|
+
else
|
145
|
+
has_tags=true
|
146
|
+
tags.each{|tag|
|
147
|
+
has_tags=false if !f.include? tag
|
148
|
+
}
|
149
|
+
filenames << "#{@env.log_dir}/#{f}" if has_tags
|
150
|
+
end
|
151
|
+
}
|
152
|
+
end
|
153
|
+
filenames
|
154
|
+
end
|
155
|
+
|
156
|
+
def command_history tags=nil
|
157
|
+
commands=Array.new
|
158
|
+
log_filenames(tags).each{|logfile|
|
159
|
+
begin
|
160
|
+
cmd=Command.new(JSON.parse(IO.read(logfile)))
|
161
|
+
commands << cmd
|
162
|
+
rescue
|
163
|
+
end
|
164
|
+
|
165
|
+
}
|
166
|
+
commands
|
167
|
+
end
|
168
|
+
|
169
|
+
def work_up_to_date?
|
170
|
+
if wrk_dir == Rake.application.original_dir
|
171
|
+
logfile=get_logfile ['up2date']
|
172
|
+
if File.exists? logfile
|
173
|
+
last_work_time=File.mtime(logfile)
|
174
|
+
last_file_changed=Dir.get_latest_mtime Rake.application.original_dir
|
175
|
+
if last_work_time > last_file_changed
|
176
|
+
CLEAN.include logfile
|
177
|
+
return true
|
178
|
+
else
|
179
|
+
puts " deleting #{logfile}" if @env.debug?
|
180
|
+
File.delete(logfile)
|
181
|
+
end
|
182
|
+
else
|
183
|
+
puts "logfile #{logfile} does NOT exist." if @env.debug?
|
184
|
+
end
|
185
|
+
else
|
186
|
+
puts "wrk_dir does not match Rake.application.original_dir" if @env.debug?
|
187
|
+
end
|
188
|
+
false
|
189
|
+
end
|
190
|
+
|
191
|
+
def mark_work_up_to_date
|
192
|
+
if wrk_dir == Rake.application.original_dir
|
193
|
+
logfile=get_logfile ['up2date']
|
194
|
+
puts " writing #{logfile}" if Environment.default.debug?
|
195
|
+
File.open(logfile,'w'){|f|f.write(' ')}
|
196
|
+
else
|
197
|
+
puts "wrk_dir does not match Rake.application.original_dir" if @env.debug?
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def get_logfile tags
|
202
|
+
tagstring=''
|
203
|
+
tagstring=tags if tags.kind_of?(String)
|
204
|
+
tagstring=tags.join('.') if tags.kind_of?(Array)
|
205
|
+
name="#{self.fullname}.#{tagstring}.json".gsub('/','.')
|
206
|
+
"#{@env.log_dir}/#{name}"
|
207
|
+
end
|
208
|
+
|
209
|
+
def list
|
210
|
+
history=command_history
|
211
|
+
if(history.length==0)
|
212
|
+
@env.out "? #{fullname}"
|
213
|
+
else
|
214
|
+
status=0
|
215
|
+
history.each{|c|
|
216
|
+
status=c.exit_code if c.exit_code != 0
|
217
|
+
}
|
218
|
+
if(status==0)
|
219
|
+
@env.out " #{fullname}"
|
220
|
+
else
|
221
|
+
if(@env.colorize?)
|
222
|
+
require 'ansi/code'
|
223
|
+
@env.out ANSI.red + ANSI.bright + "X #{fullname}" + ANSI.reset
|
224
|
+
else
|
225
|
+
@env.out "X #{fullname}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def out_brackets message
|
232
|
+
if(@env.colorize?)
|
233
|
+
require 'ansi/code'
|
234
|
+
@env.out "[" + ANSI.blue + ANSI.bright + message + ANSI.reset + ']'
|
235
|
+
else
|
236
|
+
@env.out "[#{message}]"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def out_cyan message
|
241
|
+
if(@env.colorize?)
|
242
|
+
require 'ansi/code'
|
243
|
+
@env.out ANSI.cyan + ANSI.bright + message + ANSI.reset
|
244
|
+
else
|
245
|
+
@env.out "#{message}"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def out_property name,value
|
250
|
+
if(@env.colorize?)
|
251
|
+
require 'ansi/code'
|
252
|
+
@env.out "#{name}: " + ANSI.white + ANSI.bold + value.to_s.strip + ANSI.reset
|
253
|
+
else
|
254
|
+
@env.out "#{name}: #{value}"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def info
|
259
|
+
infoCmd=Command.new({ :input => 'info', :exit_code => 0 })
|
260
|
+
#out_cyan '========================================================='
|
261
|
+
#out_cyan fullname
|
262
|
+
out_property "fullname".fix(15), fullname
|
263
|
+
out_property "url".fix(15), url
|
264
|
+
wrk_history=command_history ['work']
|
265
|
+
out_property "work status".fix(15), "?" if wrk_history.length == 0
|
266
|
+
out_property "work status".fix(15), wrk_history[0].summary if wrk_history.length > 0
|
267
|
+
if(wrk_history.length > 0)
|
268
|
+
@env.out wrk_history[0].info
|
269
|
+
end
|
270
|
+
make_history=command_history ['make', latest_tag]
|
271
|
+
out_property "make status".fix(15),"?" if make_history.length == 0
|
272
|
+
out_property "make status".fix(15), make_history[0].summary if make_history.length > 0
|
273
|
+
if(make_history.length >0)
|
274
|
+
@env.out make_history[0].info
|
275
|
+
end
|
276
|
+
infoCmd
|
277
|
+
end
|
278
|
+
|
279
|
+
def clobber
|
280
|
+
clobberCmd=Command.new('clobber')
|
281
|
+
clobberCmd[:exit_code]=0
|
282
|
+
if(File.exists?(wrk_dir))
|
283
|
+
Dir.remove wrk_dir,true
|
284
|
+
@env.out "removed #{wrk_dir}"
|
285
|
+
end
|
286
|
+
if(File.exists?(make_dir))
|
287
|
+
Dir.remove make_dir,true
|
288
|
+
@env.out "removed #{make_dir}"
|
289
|
+
end
|
290
|
+
clobberCmd
|
291
|
+
end
|
292
|
+
|
293
|
+
def work
|
294
|
+
clone
|
295
|
+
checkout
|
296
|
+
logfile=get_logfile ['work']
|
297
|
+
if(File.exists?(wrk_dir))
|
298
|
+
rake_default=Command.new({:input =>'rake default',:quiet => true,:ignore_failure => true})
|
299
|
+
if(last_work_mtime.nil? || last_work_mtime < Dir.get_latest_mtime(wrk_dir))
|
300
|
+
Dir.chdir(wrk_dir) do
|
301
|
+
|
302
|
+
@env.out fullname
|
303
|
+
|
304
|
+
if(!File.exists?'rakefile.rb')
|
305
|
+
rake_default[:exit_code]=1
|
306
|
+
rake_default[:error]="rakefile.rb not found."
|
307
|
+
rake_default[:start_time]=Time.now
|
308
|
+
rake_default[:end_time]=Time.now
|
309
|
+
else
|
310
|
+
#rake_default[:timeout] = self[:timeout]
|
311
|
+
rake_default.execute
|
312
|
+
end
|
313
|
+
rake_default.save logfile
|
314
|
+
update_status
|
315
|
+
@env.out rake_default.summary true
|
316
|
+
return rake_default
|
317
|
+
end
|
318
|
+
else
|
319
|
+
if(File.exists?(logfile))
|
320
|
+
rake_default.open logfile
|
321
|
+
@env.out rake_default.summary true if(rake_default[:exit_code] != 0 || @env.show_success?)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
rake_default
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def make tag=''
|
329
|
+
tag=latest_tag true if tag.length==0
|
330
|
+
#return if tag.length==0
|
331
|
+
raise 'no tag specified' if tag.length==0
|
332
|
+
|
333
|
+
rake_default=Command.new({:input => 'rake default',:quiet => true,:ignore_failure => true})
|
334
|
+
logfile=get_logfile ['make',tag]
|
335
|
+
if(File.exists?(logfile))
|
336
|
+
rake_default.open logfile
|
337
|
+
@env.out rake_default.summary true if(rake_default[:exit_code] != 0) || @env.show_success?
|
338
|
+
rake_default
|
339
|
+
else
|
340
|
+
makedir=make_dir tag
|
341
|
+
FileUtils.mkdir_p(File.dirname(makedir)) if !File.exists? File.dirname(makedir)
|
342
|
+
if(self[:url].include?('.git'))
|
343
|
+
if(!File.exists?(makedir))
|
344
|
+
clone=Command.new({:input=>"git clone #{self[:url]} #{makedir}",:quiet=>true})
|
345
|
+
clone.execute
|
346
|
+
end
|
347
|
+
end
|
348
|
+
if(File.exists?(makedir))
|
349
|
+
Dir.chdir(makedir) do
|
350
|
+
checkout=Command.new({:input=>"git checkout #{tag}",:quiet=>true})
|
351
|
+
checkout.execute
|
352
|
+
FileUtils.rm_r '.git'
|
353
|
+
if(!File.exists?'rakefile.rb')
|
354
|
+
rake_default[:exit_code]=1
|
355
|
+
rake_default[:error]="rakefile.rb not found."
|
356
|
+
rake_default[:start_time]=Time.now
|
357
|
+
rake_default[:end_time]=Time.now
|
358
|
+
else
|
359
|
+
#rake_default[:timeout] = self[:timeout]
|
360
|
+
rake_default.execute
|
361
|
+
end
|
362
|
+
rake_default.save logfile
|
363
|
+
update_status
|
364
|
+
@env.out rake_default.summary true
|
365
|
+
rake_default
|
366
|
+
end
|
367
|
+
else
|
368
|
+
puts "Project make make_dir #{makedir} does not exist." if @env.debug?
|
369
|
+
end
|
370
|
+
|
371
|
+
begin
|
372
|
+
FileUtils.rm_r makedir
|
373
|
+
rescue
|
374
|
+
end
|
375
|
+
rake_default
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def last_work_mtime
|
380
|
+
logfile=get_logfile ['work']
|
381
|
+
return File.mtime(logfile) if File.exists? logfile
|
382
|
+
nil
|
383
|
+
end
|
384
|
+
|
385
|
+
def update_status
|
386
|
+
status_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.status.json"
|
387
|
+
status=Hash.new({'status'=>'?'})
|
388
|
+
wrk_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.json"
|
389
|
+
if(File.exists?(wrk_logfile))
|
390
|
+
rake_default=Command.new(JSON.parse(IO.read(wrk_logfile)))
|
391
|
+
status[:work_logfile]=wrk_logfile
|
392
|
+
status['status']='0'
|
393
|
+
status['status']='X' if rake_default[:exit_code] != 0
|
394
|
+
end
|
395
|
+
make_logfile="#{@env.root_dir}/log/#{self.fullname}/#{latest_tag}/#{@env.user}@#{@env.machine}.json"
|
396
|
+
if(File.exists?(make_logfile))
|
397
|
+
rake_default=Command.new(JSON.parse(IO.read(make_logfile)))
|
398
|
+
status[:make_logfile]=make_logfile
|
399
|
+
status['status']='0'
|
400
|
+
status['status']='X' if rake_default[:exit_code] != 0
|
401
|
+
else
|
402
|
+
status['status']='?'
|
403
|
+
end
|
404
|
+
FileUtils.mkdir_p(File.dirname(status_logfile)) if !File.exists?(File.dirname(status_logfile))
|
405
|
+
File.open(status_logfile,'w'){|f|f.write(status.to_json)}
|
406
|
+
end
|
407
|
+
|
408
|
+
def status
|
409
|
+
status_logfile="#{@env.root_dir}/log/#{self.fullname}/#{@env.user}@#{@env.machine}.status.json"
|
410
|
+
update_status if !File.exists? status_logfile
|
411
|
+
if(File.exists?(status_logfile))
|
412
|
+
statusHash=JSON.parse(IO.read(status_logfile))
|
413
|
+
return statusHash['status'] if(statusHash.has_key?('status'))
|
414
|
+
end
|
415
|
+
'?'
|
416
|
+
end
|
417
|
+
|
418
|
+
def report
|
419
|
+
end
|
420
|
+
|
421
|
+
def update
|
422
|
+
clone
|
423
|
+
checkout
|
424
|
+
if(File.exists?(wrk_dir))
|
425
|
+
Dir.chdir(wrk_dir) do
|
426
|
+
if(File.exists?('.git'))
|
427
|
+
pull=Command.execute(Command.new({:input => 'git pull', :quiet => true, :ignore_failure => true}))
|
428
|
+
@env.out pull.summary true
|
429
|
+
return pull
|
430
|
+
end
|
431
|
+
if(File.exists?('.svn'))
|
432
|
+
updateCmd=Command.execute(Command.new({:input => 'svn update', :quiet => true, :ignore_failure => true}))
|
433
|
+
@env.out updateCmd.summary true
|
434
|
+
return updateCmd
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
return Command.new({:exit_code => 1})
|
439
|
+
end
|
440
|
+
|
441
|
+
def tags
|
442
|
+
tags=Array.new
|
443
|
+
if !File.exists? wrk_dir
|
444
|
+
clone=Command.new({:input=>'git clone #{self[:url]} #{wrk_dir}',:quiet=>true})
|
445
|
+
clone.execute
|
446
|
+
end
|
447
|
+
Dir.chdir(wrk_dir) do
|
448
|
+
Command.output('git tag').split('\n').each{|line|
|
449
|
+
tag=line.strip
|
450
|
+
tags << tag if tag.length < 0
|
451
|
+
}
|
452
|
+
end
|
453
|
+
tags
|
454
|
+
end
|
455
|
+
|
456
|
+
|
457
|
+
end
|
458
|
+
|