112
113
114
115
116
117
118
119
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
|
# File 'lib/package_cloud/cli/entry.rb', line 112
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|
files = nil
ext = f.split(".").last
if ext == "dsc"
print "Checking source package #{f}... "
files = parse_and_verify_dsc(client_repo, f, dist_id)
end
print "Pushing #{f}... "
measurement = Benchmark.measure do
if options.has_key?("skip-errors")
create_package_skip_errors(client_repo, f, dist_id, files, ext, options["coordinates"])
elsif options.has_key?("skip-duplicates")
create_package_skip_duplicates(client_repo, f, dist_id, files, ext, options["coordinates"])
else
create_package(client_repo, f, dist_id, files, ext, options["coordinates"])
end
end
$logger.debug("create package request timing: #{measurement}")
end
end
$logger.debug("push command total timing: #{total_time}")
end
|