Class: Ropes::Repository::Apt
- Inherits:
-
Object
- Object
- Ropes::Repository::Apt
- Defined in:
- lib/ropes/repository/apt.rb
Instance Method Summary collapse
- #add_file_by_info(package) ⇒ Object
- #add_file_by_path(path) ⇒ Object
-
#initialize(options) ⇒ Apt
constructor
A new instance of Apt.
-
#packages_file(arch) ⇒ Object
Get the Packages file as a string.
-
#packages_file_gz(arch) ⇒ Object
Get the Packages file as a gzip’ed string.
-
#release_file ⇒ Object
Get the Release file as a string.
-
#release_file_gpg(path_to_gpgkey) ⇒ Object
Get detached GPG signature of Release file.
Constructor Details
#initialize(options) ⇒ Apt
Returns a new instance of Apt.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ropes/repository/apt.rb', line 17 def initialize() = %w{ origin type distribution version architectures components description package_base}.reject do |required_option| .has_key?(required_option.to_sym) end raise "Missing options: #{.join(", ")}" unless .empty? raise Error, "Architectures must be an array" unless [:architectures].is_a? Array @release_file = nil @packages_file = nil @packages_field_gz = nil @options = @packages = [] @field_order = %w{ package priority section installed_size maintainer architecture source version depends filename size MD5sum SHA1 SHA256 description description-md5 bugs origin supported } @mandatory_fields = %w{ package version architecture maintainer description } end |
Instance Method Details
#add_file_by_info(package) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ropes/repository/apt.rb', line 79 def add_file_by_info(package) if (package).empty? if package.is_a? Hash @packages << package else raise "Package metadata must be in hash format" end else raise "Missing mandatory fields on package: #{(package).join(", ")}" end end |
#add_file_by_path(path) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/ropes/repository/apt.rb', line 70 def add_file_by_path(path) = Debeasy.read(path).to_hash if ().empty? @packages << else raise "Missing mandatory fields on package: #{().join(", ")}" end end |
#packages_file(arch) ⇒ Object
Get the Packages file as a string
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/ropes/repository/apt.rb', line 93 def packages_file(arch) packages_for_arch = @packages.select {|p| p["architecture"] == arch} entries = packages_for_arch.map do |package| lines = [] @field_order.each do |field| if package[field] != nil case field when "filename" lines << packages_line(field.capitalize, "#{@options[:package_base]}/#{package[field]}") when "installed_size" lines << packages_line("Installed-Size", package[field]) when "SHA1", "SHA256", "MD5sum" lines << packages_line(field, package[field]) else lines << packages_line(field.capitalize, package[field]) end end end lines.join("\n") end if entries.empty? "" else entries.join("\n\n") + "\n" end end |
#packages_file_gz(arch) ⇒ Object
Get the Packages file as a gzip’ed string
122 123 124 125 126 127 128 |
# File 'lib/ropes/repository/apt.rb', line 122 def packages_file_gz(arch) io = StringIO.new("w") gz = Zlib::GzipWriter.new(io) gz.write(packages_file(arch)) gz.close io.string end |
#release_file ⇒ Object
Get the Release file as a string
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ropes/repository/apt.rb', line 132 def release_file lines = [] lines << "Origin: #{@options[:origin]}" lines << "Label: #{@options[:origin]}" lines << "Suite: #{@options[:distribution]}" lines << "Version: #{@options[:version]}" lines << "Codename: #{@options[:distribution]}" lines << "Date: #{Time.new.utc.strftime '%a, %d %b %Y %H:%M:%S UTC'}" lines << "Architectures: #{@options[:architectures].join(" ")}" lines << "Components: #{@options[:components]}" lines << "Description: #{@options[:description]}" lines << "MD5Sum:" @options[:architectures].each do |arch| # Have to create the files in real life to get the real size temp_packages_file = Tempfile.new("Packages") temp_packages_file.write packages_file(arch) temp_packages_file_gz = Tempfile.new("Packages.gz") temp_packages_file_gz.write packages_file_gz(arch) lines << " #{Digest::MD5.hexdigest(packages_file(arch))} #{temp_packages_file.size} #{@options[:components]}/binary-#{arch}/Packages" lines << " #{Digest::MD5.hexdigest(packages_file_gz(arch))} #{temp_packages_file_gz.size} #{@options[:components]}/binary-#{arch}/Packages.gz" end lines.join("\n") + "\n" end |
#release_file_gpg(path_to_gpgkey) ⇒ Object
Get detached GPG signature of Release file
158 159 160 161 162 163 164 |
# File 'lib/ropes/repository/apt.rb', line 158 def release_file_gpg(path_to_gpgkey) GPGME::Key.import(File.open(path_to_gpgkey)) GPGME::Crypto.new.sign(release_file, { :mode => GPGME::SIG_MODE_DETACH, :armor => true }) end |