Class: Deb::S3::Package
- Inherits:
-
Object
- Object
- Deb::S3::Package
- Extended by:
- Utils
- Includes:
- Utils
- Defined in:
- lib/deb/s3/package.rb
Instance Attribute Summary collapse
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#attributes ⇒ Object
Any other attributes specific to this package.
-
#category ⇒ Object
Returns the value of attribute category.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#description ⇒ Object
Returns the value of attribute description.
-
#epoch ⇒ Object
Returns the value of attribute epoch.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#license ⇒ Object
Returns the value of attribute license.
-
#maintainer ⇒ Object
Returns the value of attribute maintainer.
-
#md5 ⇒ Object
Returns the value of attribute md5.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sha1 ⇒ Object
Returns the value of attribute sha1.
-
#sha256 ⇒ Object
Returns the value of attribute sha256.
-
#size ⇒ Object
Returns the value of attribute size.
-
#url ⇒ Object
Returns the value of attribute url.
-
#url_filename(codename) ⇒ Object
hashes.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_file_info(file) ⇒ Object
def extract_info.
-
#extract_info(control) ⇒ Object
from fpm.
-
#fix_dependency(dep) ⇒ Object
from fpm.
- #full_version ⇒ Object
- #generate(codename) ⇒ Object
-
#initialize ⇒ Package
constructor
A new instance of Package.
- #parse_control(control) ⇒ Object
-
#parse_depends(data) ⇒ Object
from fpm.
- #url_filename_encoded(codename) ⇒ Object
Methods included from Utils
access_policy, access_policy=, bucket, bucket=, debianize_op, encryption, encryption=, gpg_options, gpg_options=, prefix, prefix=, s3, s3=, s3_escape, s3_exists?, s3_path, s3_read, s3_remove, s3_store, safesystem, signing_key, signing_key=, template
Constructor Details
#initialize ⇒ Package
Returns a new instance of Package.
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 |
# File 'lib/deb/s3/package.rb', line 82 def initialize @attributes = {} # Reference # http://www.debian.org/doc/manuals/maint-guide/first.en.html # http://wiki.debian.org/DeveloperConfiguration # https://github.com/jordansissel/fpm/issues/37 if ENV.include?("DEBEMAIL") and ENV.include?("DEBFULLNAME") # Use DEBEMAIL and DEBFULLNAME as the default maintainer if available. @maintainer = "#{ENV["DEBFULLNAME"]} <#{ENV["DEBEMAIL"]}>" else # TODO(sissel): Maybe support using 'git config' for a default as well? # git config --get user.name, etc can be useful. # # Otherwise default to user@currenthost @maintainer = "<#{ENV["USER"]}@#{Socket.gethostname}>" end @name = nil @architecture = "native" @description = "no description given" @version = nil @epoch = nil @iteration = nil @url = nil @category = "default" @license = "unknown" @vendor = "none" @sha1 = nil @sha256 = nil @md5 = nil @size = nil @filename = nil @url_filename = nil @dependencies = [] end |
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
23 24 25 |
# File 'lib/deb/s3/package.rb', line 23 def architecture @architecture end |
#attributes ⇒ Object
Any other attributes specific to this package. This is where you’d put rpm, deb, or other specific attributes.
30 31 32 |
# File 'lib/deb/s3/package.rb', line 30 def attributes @attributes end |
#category ⇒ Object
Returns the value of attribute category.
21 22 23 |
# File 'lib/deb/s3/package.rb', line 21 def category @category end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
26 27 28 |
# File 'lib/deb/s3/package.rb', line 26 def dependencies @dependencies end |
#description ⇒ Object
Returns the value of attribute description.
24 25 26 |
# File 'lib/deb/s3/package.rb', line 24 def description @description end |
#epoch ⇒ Object
Returns the value of attribute epoch.
16 17 18 |
# File 'lib/deb/s3/package.rb', line 16 def epoch @epoch end |
#filename ⇒ Object
Returns the value of attribute filename.
39 40 41 |
# File 'lib/deb/s3/package.rb', line 39 def filename @filename end |
#iteration ⇒ Object
Returns the value of attribute iteration.
17 18 19 |
# File 'lib/deb/s3/package.rb', line 17 def iteration @iteration end |
#license ⇒ Object
Returns the value of attribute license.
22 23 24 |
# File 'lib/deb/s3/package.rb', line 22 def license @license end |
#maintainer ⇒ Object
Returns the value of attribute maintainer.
18 19 20 |
# File 'lib/deb/s3/package.rb', line 18 def maintainer @maintainer end |
#md5 ⇒ Object
Returns the value of attribute md5.
36 37 38 |
# File 'lib/deb/s3/package.rb', line 36 def md5 @md5 end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/deb/s3/package.rb', line 14 def name @name end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
34 35 36 |
# File 'lib/deb/s3/package.rb', line 34 def sha1 @sha1 end |
#sha256 ⇒ Object
Returns the value of attribute sha256.
35 36 37 |
# File 'lib/deb/s3/package.rb', line 35 def sha256 @sha256 end |
#size ⇒ Object
Returns the value of attribute size.
37 38 39 |
# File 'lib/deb/s3/package.rb', line 37 def size @size end |
#url ⇒ Object
Returns the value of attribute url.
20 21 22 |
# File 'lib/deb/s3/package.rb', line 20 def url @url end |
#url_filename(codename) ⇒ Object
hashes
33 34 35 |
# File 'lib/deb/s3/package.rb', line 33 def url_filename @url_filename end |
#vendor ⇒ Object
Returns the value of attribute vendor.
19 20 21 |
# File 'lib/deb/s3/package.rb', line 19 def vendor @vendor end |
#version ⇒ Object
Returns the value of attribute version.
15 16 17 |
# File 'lib/deb/s3/package.rb', line 15 def version @version end |
Class Method Details
.extract_control(package) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/deb/s3/package.rb', line 58 def extract_control(package) if system("which dpkg > /dev/null 2>&1") `dpkg -f #{package}` else # ar fails to find the control.tar.gz tarball within the .deb # on Mac OS. Try using ar to list the control file, if found, # use ar to extract, otherwise attempt with tar which works on OS X. extract_control_tarball_cmd = "ar p #{package} control.tar.gz" begin safesystem("ar t #{package} control.tar.gz &> /dev/null") rescue SafeSystemError warn "Failed to find control data in .deb with ar, trying tar." extract_control_tarball_cmd = "tar zxf #{package} --to-stdout control.tar.gz" end Dir.mktmpdir do |path| safesystem("#{extract_control_tarball_cmd} | tar -zxf - -C #{path}") File.read(File.join(path, "control")) end end end |
.parse_file(package) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/deb/s3/package.rb', line 44 def parse_file(package) p = self.new p.extract_info(extract_control(package)) p.apply_file_info(package) p.filename = package p end |
.parse_string(s) ⇒ Object
52 53 54 55 56 |
# File 'lib/deb/s3/package.rb', line 52 def parse_string(s) p = self.new p.extract_info(s) p end |
Instance Method Details
#apply_file_info(file) ⇒ Object
def extract_info
271 272 273 274 275 276 |
# File 'lib/deb/s3/package.rb', line 271 def apply_file_info(file) self.size = File.size(file) self.sha1 = Digest::SHA1.file(file).hexdigest self.sha256 = Digest::SHA2.file(file).hexdigest self.md5 = Digest::MD5.file(file).hexdigest end |
#extract_info(control) ⇒ Object
from fpm
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 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/deb/s3/package.rb', line 222 def extract_info(control) fields = parse_control(control) # Parse 'epoch:version-iteration' in the version string full_version = fields.delete('Version') if full_version !~ /^(?:([0-9]+):)?(.+?)(?:-(.*))?$/ raise "Unsupported version string '#{full_version}'" end self.epoch, self.version, self.iteration = $~.captures self.architecture = fields.delete('Architecture') self.category = fields.delete('Section') self.license = fields.delete('License') || self.license self.maintainer = fields.delete('Maintainer') self.name = fields.delete('Package') self.url = fields.delete('Homepage') self.vendor = fields.delete('Vendor') || self.vendor self.attributes[:deb_priority] = fields.delete('Priority') self.attributes[:deb_origin] = fields.delete('Origin') self.attributes[:deb_installed_size] = fields.delete('Installed-Size') # Packages manifest fields filename = fields.delete('Filename') self.url_filename = filename && CGI.unescape(filename) self.sha1 = fields.delete('SHA1') self.sha256 = fields.delete('SHA256') self.md5 = fields.delete('MD5sum') self.size = fields.delete('Size') self.description = fields.delete('Description') #self.config_files = config_files self.dependencies += Array(parse_depends(fields.delete('Depends'))) self.attributes[:deb_recommends] = fields.delete('Recommends') self.attributes[:deb_suggests] = fields.delete('Suggests') self.attributes[:deb_enhances] = fields.delete('Enhances') self.attributes[:deb_pre_depends] = fields.delete('Pre-Depends') self.attributes[:deb_breaks] = fields.delete('Breaks') self.attributes[:deb_conflicts] = fields.delete('Conflicts') self.attributes[:deb_provides] = fields.delete('Provides') self.attributes[:deb_replaces] = fields.delete('Replaces') self.attributes[:deb_field] = Hash[fields.map { |k, v| [k.sub(/\AX[BCS]{0,3}-/, ''), v] }] end |
#fix_dependency(dep) ⇒ Object
from fpm
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 216 217 218 219 |
# File 'lib/deb/s3/package.rb', line 169 def fix_dependency(dep) # Deb dependencies are: NAME (OP VERSION), like "zsh (> 3.0)" # Convert anything that looks like 'NAME OP VERSION' to this format. if dep =~ /[\(,\|]/ # Don't "fix" ones that could appear well formed already. else # Convert ones that appear to be 'name op version' name, op, version = dep.split(/ +/) if !version.nil? # Convert strings 'foo >= bar' to 'foo (>= bar)' dep = "#{name} (#{debianize_op(op)} #{version})" end end name_re = /^[^ \(]+/ name = dep[name_re] if name =~ /[A-Z]/ dep = dep.gsub(name_re) { |n| n.downcase } end if dep.include?("_") dep = dep.gsub("_", "-") end # Convert gem ~> X.Y.Z to '>= X.Y.Z' and << X.Y+1.0 if dep =~ /\(~>/ name, version = dep.gsub(/[()~>]/, "").split(/ +/)[0..1] nextversion = version.split(".").collect { |v| v.to_i } l = nextversion.length nextversion[l-2] += 1 nextversion[l-1] = 0 nextversion = nextversion.join(".") return ["#{name} (>= #{version})", "#{name} (<< #{nextversion})"] elsif (m = dep.match(/(\S+)\s+\(!= (.+)\)/)) # Append this to conflicts self.conflicts += [dep.gsub(/!=/,"=")] return [] elsif (m = dep.match(/(\S+)\s+\(= (.+)\)/)) and self.attributes[:deb_ignore_iteration_in_dependencies?] # Convert 'foo (= x)' to 'foo (>= x)' and 'foo (<< x+1)' # but only when flag --ignore-iteration-in-dependencies is passed. name, version = m[1..2] nextversion = version.split('.').collect { |v| v.to_i } nextversion[-1] += 1 nextversion = nextversion.join(".") return ["#{name} (>= #{version})", "#{name} (<< #{nextversion})"] else # otherwise the dep is probably fine return dep.rstrip end end |
#full_version ⇒ Object
120 121 122 123 |
# File 'lib/deb/s3/package.rb', line 120 def full_version return nil if [epoch, version, iteration].all?(&:nil?) [[epoch, version].compact.join(":"), iteration].compact.join("-") end |
#generate(codename) ⇒ Object
138 139 140 |
# File 'lib/deb/s3/package.rb', line 138 def generate(codename) template("package.erb").result(binding) end |
#parse_control(control) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/deb/s3/package.rb', line 278 def parse_control(control) field = nil value = "" {}.tap do |fields| control.each_line do |line| if line =~ /^(\s+)(\S.*)$/ indent, rest = $1, $2 # Continuation if indent.size == 1 && rest == "." value << "\n" rest = "" elsif value.size > 0 value << "\n" end value << rest elsif line =~ /^([-\w]+):(.*)$/ fields[field] = value if field field, value = $1, $2.strip end end fields[field] = value if field end end |
#parse_depends(data) ⇒ Object
from fpm
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/deb/s3/package.rb', line 143 def parse_depends(data) return [] if data.nil? or data.empty? # parse dependencies. Debian dependencies come in one of two forms: # * name # * name (op version) # They are all on one line, separated by ", " dep_re = /^([^ ]+)(?: \(([>=<]+) ([^)]+)\))?$/ return data.split(/, */).collect do |dep| m = dep_re.match(dep) if m name, op, version = m.captures # this is the proper form of dependency if op && version && op != "" && version != "" "#{name} (#{op} #{version})".strip else name.strip end else # Assume normal form dependency, "name op version". dep end end end |
#url_filename_encoded(codename) ⇒ Object
134 135 136 |
# File 'lib/deb/s3/package.rb', line 134 def url_filename_encoded(codename) @url_filename || "pool/#{codename}/#{self.name[0]}/#{self.name[0..1]}/#{s3_escape(File.basename(self.filename))}" end |