Class: Deb::S3::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/deb/s3/cli.rb

Instance Method Summary collapse

Instance Method Details

#upload(*files) ⇒ Object



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
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
# File 'lib/deb/s3/cli.rb', line 81

def upload(*files)
  component = options[:component]
  if options[:section]
    component = options[: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.detect { |f| !File.exists?(f) }
    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(options[: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 = options[: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(options[:codename], component, arch)

    # add in the package
    manifests[arch].add(pkg, options[: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

#verifyObject



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
# File 'lib/deb/s3/cli.rb', line 143

def verify
  component = options[:component]
  if options[:section]
    component = options[: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(options[:codename])

  %w[amd64 armel i386 all].each do |arch|
    log("Checking for missing packages in: #{options[:codename]}/#{options[:component]} #{arch}")
    manifest = Deb::S3::Manifest.retrieve(options[: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 options[: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