forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.rb
107 lines (94 loc) · 2.18 KB
/
files.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
def find_file(file)
puts "Copying #{file}" if $DEBUG
if Rake::Task.task_defined?(file) and Rake::Task[file].out
# Grab the "out" of the task represented by this symbol
t = Rake::Task[file]
file = t.out
end
if (file.is_a? Symbol)
file = file.to_s
end
if File.exists?(file)
return file
elsif File.exists?("build/#{file}")
return "build/#{file}"
else
fl = FileList.new(file).existing!()
if fl.length > 0
return fl
end
fl = FileList.new("build/#{file}").existing!()
if fl.length > 0
return fl
end
puts "Unable to locate #{file}"
exit -1
end
end
def copy_single_resource_(from, to)
dir = to.sub(/(.*)\/.*?$/, '\1')
mkdir_p "#{dir}"
from = find_file(from)
if from.kind_of? FileList
from.each do |f|
cp_r f, "#{to}", :remove_destination => true
end
else
cp_r from, "#{to}", :remove_destination => true
end
end
def copy_resource_(from, to)
if !from.nil?
if (from.kind_of? Hash)
from.each do |key,value|
copy_single_resource_ key, to + "/" + value
end
elsif (from.kind_of? Array)
from.each do |res|
copy_resource_ res, to
end
else
copy_single_resource_ from, to
end
end
end
def copy_prebuilt(prebuilt, out)
dir = out.split('/')[0..-2].join('/')
if prebuilt.nil?
mkdir_p dir
File.open(out, 'w') {|f| f.write('')}
elsif File.directory? prebuilt
from = prebuilt + "/" + out
from = from.sub(/\/build\//, "/")
if (File.exists?(from))
puts "Falling back to copy of: #{from}"
mkdir_p dir
if File.directory? from
cp_r from + "/.", out
else
cp_r from, out
end
else
puts "Unable to locate prebuilt copy of #{out}"
end
elsif File.exists?(prebuilt)
puts "Falling back to copy of: #{prebuilt}"
mkdir_p dir
cp prebuilt, out
else
puts "Unable to locate prebuilt copy of #{out}"
end
end
def copy_to_prebuilt(out, prebuilt)
dest = "#{prebuilt}/#{out}".sub(/\/build\//, "/")
src = out
if File.directory? src
cp_r src + "/.", dest
else
if File.exist? prebuilt
cp src, prebuilt
else
cp src, dest
end
end
end