Class: Deb::S3::CLI

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

Instance Method Summary collapse

Instance Method Details

#upload(file) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
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
# File 'lib/deb/s3/cli.rb', line 70

def upload(file)
  # make sure the file exists
  error("File doesn't exist") unless File.exists?(file)

  # configure AWS::S3
  configure_s3_client

  Deb::S3::Utils.signing_key = options[:sign]

  # make sure we have a valid visibility setting
  Deb::S3::Utils.access_policy = case options[:visibility]
  when "public"
    :public_read
  when "private"
    :private
  when "authenticated"
    :authenticated_read
  else
    error("Invalid visibility setting given. Can be public, private, or authenticated.")
  end

  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 from the file. " +
    "Please specify one with --arch [i386,amd64].") unless arch

  log("Retrieving existing manifests")
  release  = Deb::S3::Release.retrieve(options[:codename])
  manifest = Deb::S3::Manifest.retrieve(options[:codename], options[:section], arch)

  # add in the package
  manifest.add(pkg, options[:preserve_versions])

  log("Uploading package and 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

#verifyObject


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

def verify
  configure_s3_client

  log("Retrieving existing manifests")
  release = Deb::S3::Release.retrieve(options[:codename])

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