Class: Ropes::Repository
- Inherits:
-
Object
- Object
- Ropes::Repository
- Defined in:
- lib/ropes/repository.rb
Instance Method Summary collapse
- #add_file_by_info(package) ⇒ Object
- #add_file_by_path(path) ⇒ Object
-
#initialize(options) ⇒ Repository
constructor
A new instance of Repository.
-
#packages_file ⇒ Object
Get the Packages file as a string.
-
#packages_file_gz ⇒ 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) ⇒ Repository
Returns a new instance of Repository.
16 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 |
# File 'lib/ropes/repository.rb', line 16 def initialize() = %w{ origin type distribution version architecture components description package_base}.reject do |required_option| .has_key?(required_option.to_sym) end raise "Missing options: #{.join(", ")}" unless .empty? raise InvalidRepositoryType, "Repository type #{[:type]} is neither :apt or :yum" unless [:type] == :yum or [:type] == :apt @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
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ropes/repository.rb', line 78 def add_file_by_info(package) if (packages).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: #{().join(", ")}" end end |
#add_file_by_path(path) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/ropes/repository.rb', line 69 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 ⇒ Object
Get the Packages file as a string
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ropes/repository.rb', line 92 def packages_file return @packages_file unless @packages_file.nil? entries = @packages.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 @packages_file = entries.join("\n\n") + "\n" end |
#packages_file_gz ⇒ Object
Get the Packages file as a gzip’ed string
117 118 119 120 121 122 123 |
# File 'lib/ropes/repository.rb', line 117 def packages_file_gz io = StringIO.new("w") gz = Zlib::GzipWriter.new(io) gz.write(packages_file()) gz.close io.string end |
#release_file ⇒ Object
Get the Release file as a string
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ropes/repository.rb', line 127 def release_file # 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 temp_packages_file_gz= Tempfile.new("Packages.gz") temp_packages_file_gz.write packages_file_gz 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[:architecture]}" lines << "Components: #{@options[:components]}" lines << "Description: #{@options[:description]}" lines << "MD5Sum:" lines << " #{Digest::MD5.hexdigest(packages_file)} #{temp_packages_file.size} #{@options[:components]}/binary-#{@options[:architecture]}/Packages" lines << " #{Digest::MD5.hexdigest(packages_file_gz)} #{temp_packages_file_gz.size} #{@options[:components]}/binary-#{@options[:architecture]}/Packages.gz" lines.join("\n") + "\n" end |
#release_file_gpg(path_to_gpgkey) ⇒ Object
Get detached GPG signature of Release file
153 154 155 156 157 158 159 |
# File 'lib/ropes/repository.rb', line 153 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 |