Class: Deb::S3::CLI
- Inherits:
-
Thor
- Object
- Thor
- Deb::S3::CLI
- Defined in:
- lib/deb/s3/cli.rb
Instance Method Summary collapse
Instance Method Details
#delete(package) ⇒ Object
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 |
# File 'lib/deb/s3/cli.rb', line 166 def delete(package) component = [:component] if [:section] component = [:section] warn("===> WARNING: The --section/-s argument is deprecated, please use --component/-m.") end if package.nil? error("You must specify a package name.") end versions = [:versions] if versions.nil? warn("===> WARNING: Deleting all versions of #{package}") else log("Versions to delete: #{versions.join(', ')}") end arch = [:arch] if arch.nil? error("You must specify the architecture of the package to remove.") end configure_s3_client # retrieve the existing manifests log("Retrieving existing manifests") release = Deb::S3::Release.retrieve([:codename]) manifest = Deb::S3::Manifest.retrieve([:codename], component, [:arch]) deleted = manifest.delete_package(package, versions) if deleted.length == 0 if versions.nil? error("No packages were deleted. #{package} not found.") else error("No packages were deleted. #{package} versions #{versions.join(', ')} could not be found.") end else deleted.each { |p| sublog("Deleting #{p.name} version #{p.version}") } end log("Uploading new manifests to S3") manifest.write_to_s3 {|f| sublog("Transferring #{f}") } release.update_manifest(manifest) release.write_to_s3 {|f| sublog("Transferring #{f}") } log("Update complete.") end |
#upload(*files) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 |
# File 'lib/deb/s3/cli.rb', line 95 def upload(*files) component = [:component] if [:section] component = [:section] warn("===> WARNING: The --section/-s argument is deprecated, please use --component/-m.") end if files.nil? || files.empty? error("You must specify at least one file to upload") end # make sure all the files exists if missing_file = files.find { |pattern| Dir.glob(pattern).empty? } error("File '#{missing_file}' doesn't exist") end # configure AWS::S3 configure_s3_client # retrieve the existing manifests log("Retrieving existing manifests") release = Deb::S3::Release.retrieve([:codename]) manifests = {} # examine all the files files.collect { |f| Dir.glob(f) }.flatten.each do |file| log("Examining package file #{File.basename(file)}") pkg = Deb::S3::Package.parse_file(file) # copy over some options if they weren't given arch = [:arch] || pkg.architecture # validate we have them error("No architcture given and unable to determine one for #{file}. " + "Please specify one with --arch [i386,amd64].") unless arch # retrieve the manifest for the arch if we don't have it already manifests[arch] ||= Deb::S3::Manifest.retrieve([:codename], component, arch) # add in the package manifests[arch].add(pkg, [:preserve_versions]) end # upload the manifest log("Uploading packages and new manifests to S3") manifests.each_value do |manifest| manifest.write_to_s3 { |f| sublog("Transferring #{f}") } release.update_manifest(manifest) end release.write_to_s3 { |f| sublog("Transferring #{f}") } log("Update complete.") end |
#verify ⇒ Object
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 261 262 263 |
# File 'lib/deb/s3/cli.rb', line 226 def verify component = [:component] if [:section] component = [:section] warn("===> WARNING: The --section/-s argument is deprecated, please use --component/-m.") end configure_s3_client log("Retrieving existing manifests") release = Deb::S3::Release.retrieve([:codename]) %w[amd64 armel i386 all].each do |arch| log("Checking for missing packages in: #{[:codename]}/#{[:component]} #{arch}") manifest = Deb::S3::Manifest.retrieve([:codename], component, arch) missing_packages = [] manifest.packages.each do |p| unless Deb::S3::Utils.s3_exists? p.url_filename_encoded sublog("The following packages are missing:\n\n") if missing_packages.empty? puts(p.generate) puts("") missing_packages << p end end if [:fix_manifests] && !missing_packages.empty? log("Removing #{missing_packages.length} package(s) from the manifest...") missing_packages.each { |p| manifest.packages.delete(p) } manifest.write_to_s3 { |f| sublog("Transferring #{f}") } release.update_manifest(manifest) release.write_to_s3 { |f| sublog("Transferring #{f}") } log("Update complete.") end end end |