Class: Deb::Fog::CLI

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

Instance Method Summary collapse

Instance Method Details

#delete(package) ⇒ Object



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

def delete(package)
  component = options[:component]
  if options[:section]
    component = options[: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 = options[:versions]
  if versions.nil?
    warn("===> WARNING: Deleting all versions of #{package}")
  else
    log("Versions to delete: #{versions.join(', ')}")
  end

  arch = options[:arch]
  if arch.nil?
    error("You must specify the architecture of the package to remove.")
  end

  configure_fog_client

  # retrieve the existing manifests
  log("Retrieving existing manifests")
  release  = Deb::Fog::Release.retrieve(options[:codename])
  manifest = Deb::Fog::Manifest.retrieve(options[:codename], component, options[: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 Fog")
  manifest.write_to_fog {|f| sublog("Transferring #{f}") }
  release.update_manifest(manifest)
  release.write_to_fog {|f| sublog("Transferring #{f}") }

  log("Update complete.")
end

#upload(*files) ⇒ Object



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
134
135
136
137
138
139
140
141
142
# File 'lib/deb/fog/cli.rb', line 90

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::Fog
  configure_fog_client

  # retrieve the existing manifests
  log("Retrieving existing manifests")
  release  = Deb::Fog::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::Fog::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::Fog::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 Fog")
  manifests.each_value do |manifest|
    manifest.write_to_fog { |f| sublog("Transferring #{f}") }
    release.update_manifest(manifest)
  end
  release.write_to_fog { |f| sublog("Transferring #{f}") }

  log("Update complete.")
end

#verifyObject



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

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_fog_client

  log("Retrieving existing manifests")
  release = Deb::Fog::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::Fog::Manifest.retrieve(options[:codename], component, arch)
    missing_packages = []

    manifest.packages.each do |p|
      unless Deb::Fog::Utils.fog_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_fog { |f| sublog("Transferring #{f}") }
      release.update_manifest(manifest)
      release.write_to_fog { |f| sublog("Transferring #{f}") }

      log("Update complete.")
    end
  end
end