dev 1.0.247 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/dev/Scm.rb DELETED
@@ -1,125 +0,0 @@
1
- module Dev
2
- class Scm
3
- @@default=nil
4
-
5
- attr_accessor :scm_type
6
-
7
- def initialize
8
- puts_debug "initalizing Scm"
9
- call=Dev::SystemCall.new("svn info")
10
- @scm_type=nil
11
- @scm_type = "svn" if call.output.include?("Last Changed Date:")
12
- @scm_type = "svn" if @scm_type.nil? && File.exists?(".svn")
13
- if(@scm_type.nil?)
14
- call=Dev::SystemCall.new("git status")
15
- @scm_type = "git" if call.output.include?("#")
16
- @scm_type = "git" if @scm_type.nil? && File.exists?(".git")
17
- end
18
- puts_debug "scm_type = " + @scm_type.to_s
19
- end
20
-
21
- def file_tracked?(file)
22
- puts_debug "file_tracked?(" + file + ")"
23
- puts_debug "scm_type = #{@scm_type}"
24
- if @scm_type=="git"
25
- call=Dev::SystemCall.new("git ls-files #{file} --error-unmatch")
26
- puts_debug "call.output:"
27
- puts_debug call.output
28
- puts_debug "call.error"
29
- puts_debug call.error
30
- if call.status==0
31
- puts_debug "file IS tracked by git."
32
- puts_debug call.output
33
- return true
34
- else
35
- puts_debug "file is NOT tracked by git."
36
- #return false
37
- end
38
- #return true if call.status==0
39
- end
40
- #false
41
- end
42
-
43
- def add_file(file)
44
- #call=Dev::SystemCall.new("git add #{file}") if @scm_type=="git"
45
-
46
- if @scm_type=="svn"
47
- afile=file
48
- afile="#{file}@" if afile.include?('@')
49
-
50
- `svn info "#{afile}"`
51
- status=$?.exitstatus
52
- if(status != 0)
53
- call=Dev::SystemCall.new("svn add \"#{afile}\" --parents")
54
- call.puts_summary
55
- end
56
- end
57
-
58
- if @scm_type=="git"
59
- afile=file
60
-
61
- #`git status "#{afile}"`
62
- #status=$?.exitstatus
63
- #if(status != 0)
64
- if(file_tracked?(afile))
65
- puts_debug "file #{afile} is tracked by git"
66
- else
67
- call=Dev::SystemCall.new("git add \"#{afile}\"")
68
- call.puts_summary
69
- end
70
- end
71
- end
72
-
73
- def add_file_glob(glob)
74
- Dir.glob(glob).each { |f|
75
- if(!f.include?("/obj/") &&
76
- !f.include?("/bin/") &&
77
- !f.include?("/TestOutput/") &&
78
- f.index("obj/") != 0 &&
79
- f.index("bin/") != 0 )
80
- add_file(f)
81
- end
82
- }
83
- end
84
-
85
- def self.export(remote,local,scm)
86
- puts_debug "Scm.export, scm=#{scm}"
87
- if remote.include?("svn:") || scm=="svn"
88
- local_tmp=local.gsub('@','-')
89
- call=Dev::SystemCall.new("svn export \"#{remote}\" \"#{local_tmp}\"")
90
- call.puts_summary
91
- if(local_tmp != local)
92
- sleep 15
93
- File.rename(local_tmp,local) if File.exist?(local_tmp)
94
- sleep 15
95
- end
96
- end
97
- if scm=="git"
98
- call=Dev::SystemCall.new("git clone #{remote} #{local}")
99
- end
100
- end
101
-
102
- def self.update(local)
103
- end
104
-
105
- def self.get_default_scm_uri
106
-
107
- text=`svn info`
108
- if(!text.include?("not a working copy"))
109
- text.scan(/URL: ([\w:\/.-]+)/).each { |m|
110
- return m[0]
111
- }
112
- end
113
- return nil
114
- end
115
-
116
- def self.get_default_scm_type
117
- if @@default.nil?
118
- puts_debug "creating default instance of Scm"
119
- @@default=Scm.new
120
- end
121
- return @@default.scm_type
122
- end
123
-
124
- end # class Scm
125
- end # module Dev
data/lib/dev/Svn.rb DELETED
@@ -1,55 +0,0 @@
1
- module Dev
2
- class Svn
3
-
4
- def self.last_changed_revision(url)
5
- call=Dev::SystemCall.new("svn info #{url}")
6
- if call.status == 0
7
- call.output.each_line { |line|
8
- words=line.split(':')
9
- return words[1].strip if(words.length==2 && words[0] == "Last Changed Rev")
10
- }
11
- end
12
- return "0"
13
- end
14
-
15
- def self.update_revision_variable(filename,variable_name,url)
16
- if File.exist?(filename)
17
- revision=Dev::Svn::last_changed_revision(url)
18
- replace="#{variable_name}='#{revision}'"
19
- puts " " + replace + " in " + filename unless revision=="0"
20
- text=File.read(filename)
21
- unless text.include?(replace)
22
- unless revision == "0"
23
- puts " updating " + filename + " with " + replace
24
- search=Regexp.new("#{variable_name}=['\"][\\d]+['\"]")
25
- Dev::Environment.replace_text_in_file(filename,search,"#{variable_name}='#{revision}'")
26
- end
27
- end
28
- end
29
- end
30
-
31
- def self.update_revision_variables(filename)
32
- if File.exist?(filename)
33
- puts_debug "scanning " + filename + " for revision variables"
34
- text=File.read(filename)
35
- # extract potential variable names of form
36
- text.scan(/([\dA-Z_]+)=['"][\d]+['"]/).each{ | var_match |
37
- puts_debug "found var_match: " + var_match[0].to_s
38
- varname = var_match[0].to_s
39
- # extract potential urls that use the variable name
40
- # '([.\w:\/-]+)@#{INTERFACE_REV}'
41
- uri_search=Regexp.new("['\"]([.\\w:\\/-]+)@" + '#{' + "#{varname}" + '}' + "['\"]")
42
- #puts uri_search.to_s
43
- text.scan(uri_search).each { |uri_match|
44
- puts_debug "found uri_match: " + uri_match.to_s
45
- uri=uri_match[0].to_s
46
- update_revision_variable(filename,varname,uri)
47
- }
48
- }
49
- else
50
- puts " " + filename + " does not exist"
51
- end
52
- end
53
-
54
- end # class Svn
55
- end # module Dev
@@ -1,288 +0,0 @@
1
- puts_debug "read " + __FILE__
2
-
3
- require 'tmpdir'
4
- require 'open3'
5
- require 'systemu'
6
- require 'sqlite3' if(RUBY_VERSION != "1.8.7")
7
-
8
- module Dev
9
-
10
- class SystemCall
11
- attr_accessor :output,:error,:status,:command,:start_time,:end_time,:timeout,:timed_out,:dir,:cache, :capture_output, :capture_error, :throw_on_error
12
-
13
- def initialize(cmd)
14
- @throw_on_error=true
15
- if(cmd.kind_of?(Hash))
16
- set_hash(cmd)
17
- else
18
- hash=Dev::Environment.s_to_hash(cmd)
19
- set_hash(hash) unless hash.nil?
20
- @command=cmd if hash.nil?
21
- end
22
- execute(@command);
23
- end
24
-
25
- def elapsed; @end_time-@start_time; end
26
-
27
- def cache_name
28
- name = @dir+"/" + @command.gsub(" ","_").gsub("\\","-").gsub("/","-") unless @dir.nil?
29
- name = @command.gsub(" ","_").gsub("\\","-").gsub("/","-") if @dir.nil?
30
- return name
31
- end
32
-
33
- def has_cache
34
- File.exist?(cache_name)
35
- end
36
-
37
- def get_hash
38
- hash = Hash.new()
39
- hash[:cmd]=@command
40
- hash[:dir]=@dir
41
- hash[:output]=@output
42
- hash[:error]=@error
43
- hash[:status]=@status
44
- hash[:start_time]=@start_time
45
- hash[:end_time]=@end_time
46
- hash[:elapsed]=elapsed.to_s
47
- hash[:time_out]=@time_out
48
- hash[:timeout]=@timeout
49
- hash[:cache]=@cache
50
- hash[:capture_output]=@capture_output
51
- hash[:capture_error]=@capture_error
52
- hash[:throw_on_error]=@throw_on_error
53
- return hash
54
- end
55
-
56
- def set_hash(hash)
57
- @command=hash[:cmd] unless hash[:cmd].nil?
58
- @dir=hash[:dir] unless hash[:dir].nil?
59
- @output=hash[:output] unless hash[:output].nil?
60
- @error=hash[:error] unless hash[:error].nil?
61
- @status=hash[:status] unless hash[:status].nil?
62
- @start_time=hash[:start_time] unless hash[:start_time].nil?
63
- @end_time=hash[:end_time] unless hash[:end_time].nil?
64
- @time_out=hash[:timeout] unless hash[:timeout].nil?
65
- @timed_out=hash[:timed_out] unless hash[:timed_out].nil?
66
- @cache=hash[:cache] unless hash[:cache].nil?
67
- @capture_output=hash[:capture_output] unless hash[:capture_output].nil?
68
- @capture_error=hash[:capture_error] unless hash[:capture_error].nil?
69
- @throw_on_error=hash[:throw_on_error] unless hash[:throw_on_error].nil?
70
- end
71
-
72
- def write_cache
73
- marshal_dump = Marshal.dump(get_hash)
74
- file=File.new(cache_name,'wb')
75
- file.write marshal_dump
76
- file.close
77
- end
78
-
79
- def load_cache
80
- file=File.open(cache_name,'rb')
81
- hash = Marshal.load file.read
82
- file.close
83
- set_hash hash
84
- end
85
-
86
- def execute(cmd)
87
- if !@cache.nil? && has_cache
88
- load_cache
89
- return
90
- end
91
-
92
- pwd=Dir.pwd
93
- @start_time=Time.now
94
- begin
95
- capture_output=true if capture_output.nil?
96
- capture_output=false if capture_output == "false"
97
- capture_error=true if capture_error.nil?
98
- capture_error=false unless capture_output
99
- capture_error=false if capture_error == "false"
100
- #puts_debug "system2('#{@dir}','#{@command}',#{@capture_output.to_s},#{@capture_error.to_s}) (in SystemCall.execute)"
101
- @status,@output,@error=system2(@dir,@command,@capture_output,@capture_error)
102
- @end_time=Time.now
103
- log
104
- rescue Exception=>e
105
- puts "error executing ruby code: #{@command}"
106
- warn "exception:"
107
- warn e.to_s
108
- @status="1"
109
- @end_time=Time.now
110
- ensure
111
- Dir.chdir(pwd) if Dir.pwd != pwd
112
- write_cache if !@cache.nil?
113
- end
114
- end
115
-
116
- def system2(working_dir,command,capture_output,capture_error)
117
- capture_output=true if capture_output.nil?
118
- capture_output=false if capture_output == "false"
119
- capture_error=true if capture_error.nil?
120
- capture_error=false unless capture_output
121
- capture_error=false if capture_error == "false"
122
-
123
- filename=Dir.tmpdir + "/" + (0...2).map{65.+(rand(25)).chr}.join
124
- filename=Dir.tmpdir + "/" + (0...2).map{65.+(rand(25)).chr}.join if File.exist? "#{filename}.out"
125
- working_dir = Dir.pwd if working_dir.nil? || working_dir.empty?
126
- status=0
127
- output=""
128
- error=""
129
-
130
- FileUtils.rm("#{filename}.out") if File.exist? "#{filename}.out"
131
- FileUtils.rm("#{filename}.err") if File.exist? "#{filename}.err"
132
-
133
- Dir.chdir(working_dir) do
134
- if(capture_output)
135
- if(capture_error)
136
- system("#{@command} >#{filename}.out 2>#{filename}.err")
137
- else
138
- system("#{@command} >#{filename}.out")
139
- end
140
- else
141
- if(capture_error)
142
- system("#{@command} 2>#{filename}.err")
143
- else
144
- system(@command)
145
- end
146
- end
147
- end
148
-
149
- if(File.exist?("#{filename}.out"))
150
- File.open("#{filename}.out",'r') {|f|
151
- output = f.read
152
- f.close
153
- }
154
- begin
155
- FileUtils.rm("#{filename}.out")
156
- rescue
157
- warn "unable to remove file #{filename}.out"
158
- end
159
- end
160
- if(File.exist?("#{filename}.err"))
161
- File.open("#{filename}.err",'r') {|f|
162
- error = f.read
163
- f.close
164
- }
165
- begin
166
- FileUtils.rm("#{filename}.err")
167
- rescue
168
- warn "unable to remove file #{filename}.err"
169
- end
170
- end
171
-
172
- status=$?.exitstatus
173
- return status,output,error
174
- end
175
-
176
- def puts_summary
177
- puts_summary2(@throw_on_error)
178
- end
179
-
180
- def puts_summary2(throw_on_error)
181
- if(@status != 0)
182
- if(RUBY_VERSION == "1.8.7")
183
- summary = " [" + "X" + "]" + " " + @command + " has exit status of " + @status.to_s
184
- else
185
- summary = " [" + "X" + "]" + " " + @command + " has exit status of " + @status.to_s
186
- #summary = Rainbow(" [").foreground(:cyan) + Rainbow("X").foreground(:red).bright + Rainbow("]").foreground(:cyan) + " " + Rainbow(@command).foreground(:green) + " has exit status of " + @status.to_s
187
- end
188
- summary += " dir: " + @dir unless @dir.nil?
189
- summary += " cache: true" unless @cache.nil?
190
- summary += " capture_output: false" unless @capture_output.nil? || @capture_output
191
- puts summary
192
- puts @output if !@output.nil?
193
- warn @error if !@error.nil?
194
- throw "exit status was " + @status.to_s if throw_on_error
195
- else
196
- elapsed_str="[" + "%.0f" %(elapsed) + "s]"
197
- if(RUBY_VERSION == "1.8.7")
198
- summary = " [" + "+" + "]" + " " + @command + " " + elapsed_str
199
- else
200
- summary = " [" + "+" + "]" + " " + @command + " " + elapsed_str
201
- #summary = Rainbow(" [").foreground(:cyan) + Rainbow("+").foreground(:green) + Rainbow("]").foreground(:cyan) + " " + Rainbow(@command).foreground(:green) + " " + Rainbow(elapsed_str).foreground(:cyan)
202
- end
203
- summary += " dir: " + @dir unless @dir.nil?
204
- summary += " cache: true" unless @cache.nil?
205
- summary += " capture_output: false" unless @capture_output.nil? || @capture_output
206
- puts summary
207
- end
208
- end
209
-
210
- def self.puts_hash_summary(h)
211
- if(h[:status] != 0 && h[:status] != "0")
212
- summary = " [".foreground(:cyan) + "X".foreground(:red).bright + "]".foreground(:cyan) + " " + h[:cmd].foreground(:green) + " has exit status of " + h[:status].to_s
213
- summary += " dir: " + h[:dir] unless h[:dir].nil?
214
- puts summary
215
- puts h[:output] if !h[:output].nil?
216
- warn h[:error] if !h[:error].nil?
217
- throw "exit status was " + h[:status].to_s
218
- else
219
- elapsed_str="[" + "%.0f" %(h[:elapsed]) + "s]"
220
- summary = " [".foreground(:cyan) + "+".foreground(:green) + "]".foreground(:cyan) + " " + h[:cmd].foreground(:green) + " " + elapsed_str.foreground(:cyan)
221
- summary += " dir: " + h[:dir] unless h[:dir].nil?
222
- puts summary
223
- end
224
- end
225
-
226
- def user_profile
227
- ["USERPROFILE","HOME"].each {|v|
228
- return ENV[v].gsub('\\','/') unless ENV[v].nil?
229
- }
230
- dir="~"
231
- end
232
-
233
- def split(input)
234
- m = /(?:'(?:\\.|[^'])*'|[^' ])+/.match(input)
235
- end
236
-
237
- def log
238
- filename = user_profile + "/CommandHistory.sql"
239
- sql=""
240
- if(File.exists?(filename))
241
- begin
242
- words = split(@command)
243
- cmd = words[0]
244
- arguments = @command.gsub("#{cmd} ","");
245
- executable = cmd
246
- cmd = File.basename(executable).gsub(File.extname(executable),"");
247
-
248
- db = SQLite3::Database.new filename
249
- @timeout=0 if @timeout.nil?
250
- @dir=Rake.original_dir() if(@dir.nil?)
251
- values = "VALUES(null,'" + @start_time.strftime('%Y-%m-%dT%H:%M:%S') +
252
- "','" + @end_time.strftime('%Y-%m-%dT%H:%M:%S') +
253
- "','" + Time.at(elapsed).gmtime.strftime('%H:%M:%S') +
254
- "'," + @status.to_s +
255
- ",'" + cmd + #@command.gsub("'","''") +
256
- "','" + arguments +
257
- "','" + @dir.to_s +
258
- #"','" + @output.gsub("'", "''") +
259
- #"','" + @error.gsub("'", "''") +
260
- "','" + executable +
261
- "'," + @timeout.to_s + ")"
262
- sql="insert into Commands #{values};"
263
- db.execute(sql)
264
- if(@status != 0)
265
- id=nil
266
- db.execute("select * from Commands where startTime='" +
267
- @start_time.strftime('%Y-%m-%dT%H:%M:%S') +
268
- "' AND exitCode=" + @status.to_s + ";") do |row|
269
- id=row[0]
270
- end
271
- if(!id.nil?)
272
- sql="insert or replace INTO Output VALUES(" + id.to_s +
273
- ",'" + @output.gsub("'","''") +
274
- "','" + @error.gsub("'","''") + "')";
275
- db.execute(sql)
276
- end
277
- end
278
- db.close
279
- db=nil
280
- rescue
281
- #puts_debug "failed to execute '#{sql}'"
282
- end
283
- end
284
- end
285
-
286
- end # class SystemCall
287
-
288
- end # module Dev