120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/package_cloud/cli/entry.rb', line 120
def push(repo, package_file, *package_files)
total_time = Benchmark.measure do
ARGV.clear
package_files << package_file
exts = package_files.map { |f| f.split(".").last }.uniq
if package_files.length > 1 && exts.length > 1
abort("You can't push multiple packages of different types at the same time.\nFor example, use *.deb to push all your debs at once.".color(:red))
end
invalid_packages = package_files.select do |f|
!SUPPORTED_EXTS.include?(f.split(".").last.downcase)
end
if JAVA_EXTS.include?(exts.first.downcase) && options.has_key?("coordinates")
puts "Using coordinates #{options["coordinates"].color(:yellow)}"
end
if !options.has_key?("skip-file-ext-validation") && invalid_packages.any?
message = "I don't know how to push these packages:\n\n".color(:red)
invalid_packages.each do |p|
message << " #{p}\n"
end
message << "\npackage_cloud only supports node.js, deb, gem, java, python, "\
"rpm, alpine, helm, anyfile (.zip, .asc) packages".color(:red)
abort(message)
end
if !options.has_key?("yes") && exts.first == "gem" && package_files.length > 1
answer = get_valid("Are you sure you want to push #{package_files.length} packages? (y/n)") do |s|
s == "y" || s == "n"
end
if answer != "y"
abort("Aborting...".color(:red))
end
end
validator = Validator.new(client)
if PY_EXTS.include?(exts.first.downcase)
dist_id = validator.distribution_id(repo, package_files, 'py')
elsif ANYFILE_EXTS.include?(exts.first.downcase)
dist_id = validator.distribution_id(repo, package_files, 'anyfile')
elsif NODE_EXTS.include?(exts.first.downcase)
dist_id = validator.distribution_id(repo, package_files, 'node')
elsif JAVA_EXTS.include?(exts.first.downcase)
abort_if_snapshot!(package_files)
dist_id = validator.distribution_id(repo, package_files, 'jar')
elsif AMBIGUOUS_EXTS.include?(exts.first.downcase)
dist_id = validator.distribution_id_from_repo_url(repo, package_files)
else
dist_id = validator.distribution_id(repo, package_files, exts.first)
end
split_repo = repo.split("/")[0..1].join("/")
print "Looking for repository at #{split_repo}... "
client_repo = nil
measurement = Benchmark.measure do
client_repo = client.repository(split_repo)
end
print "success!\n"
$logger.debug("repository lookup request timing: #{measurement}")
package_files.each do |f|
url = nil
files = nil
urls = nil
ext = f.split(".").last
if ext == "dsc"
print "Checking source package #{f}... "
files = parse_and_verify_dsc(client_repo, f, dist_id)
end
if options["upload-before-push"]
print "Uploading #{f}... "
upload = client_repo.create_upload
begin
response = RestClient::Request.execute(
:method => upload.fetch("form").fetch("method", "POST"),
:url => upload.fetch("form").fetch("url"),
:timeout => nil,
:payload => upload.fetch("form").fetch("data", {}).merge(
upload.fetch("form").fetch("file_input") => File.open(f, "r"),
)
)
url = response..fetch(:location)
uri = URI.parse(url)
if uri.host.end_with?(".amazonaws.com")
uri.path = CGI.unescape(uri.path)
url = uri.to_s
end
if files
urls = files.map do |file|
response = RestClient::Request.execute(
:method => upload.fetch("form").fetch("method", "POST"),
:url => upload.fetch("form").fetch("url"),
:timeout => nil,
:payload => upload.fetch("form").fetch("data", {}).merge(
upload.fetch("form").fetch("file_input") => File.open(file, "r"),
)
)
source_url = response..fetch(:location)
source_uri = URI.parse(source_url)
if source_uri.host.end_with?(".amazonaws.com")
source_uri.path = CGI.unescape(source_uri.path)
source_url = source_uri.to_s
end
source_url
end
end
rescue
print "error!\n".color(:red)
puts $!, *$!.backtrace, $!.response, $!.response.body
exit(1)
end
end
print "Pushing #{f}... "
measurement = Benchmark.measure do
if options.has_key?("skip-errors")
create_package_skip_errors(client_repo, f, url, dist_id, files, urls, ext, options["coordinates"])
elsif options.has_key?("skip-duplicates")
create_package_skip_duplicates(client_repo, f, url, dist_id, files, urls, ext, options["coordinates"])
else
create_package(client_repo, f, url, dist_id, files, urls, ext, options["coordinates"])
end
end
$logger.debug("create package request timing: #{measurement}")
end
end
$logger.debug("push command total timing: #{total_time}")
end
|