Module: Omnizip::Formats::Rpm

Defined in:
lib/omnizip/formats/rpm.rb,
lib/omnizip/formats/rpm/tag.rb,
lib/omnizip/formats/rpm/lead.rb,
lib/omnizip/formats/rpm/entry.rb,
lib/omnizip/formats/rpm/header.rb,
lib/omnizip/formats/rpm/writer.rb,
lib/omnizip/formats/rpm/constants.rb

Overview

RPM package format support

Provides read and write access to RPM packages, extracting metadata and file contents from the payload.

Examples:

Open RPM and list files

Omnizip::Formats::Rpm.open('package.rpm') do |rpm|
  rpm.files.each { |f| puts f }
end

Extract RPM contents

Omnizip::Formats::Rpm.extract('package.rpm', 'output/')

Create an RPM package

writer = Omnizip::Formats::Rpm::Writer.new(
  name: "mypkg",
  version: "1.0.0",
  release: "1"
)
writer.add_file("/usr/bin/app", "#!/bin/sh\necho hello")
writer.write("mypkg.rpm")

Defined Under Namespace

Modules: Constants Classes: Entry, Header, Lead, Reader, Tag, Writer

Class Method Summary collapse

Class Method Details

.extract(rpm_path, output_dir) ⇒ Object

Extract RPM to directory

Parameters:

  • rpm_path (String)

    Path to RPM file

  • output_dir (String)

    Output directory



72
73
74
75
76
# File 'lib/omnizip/formats/rpm.rb', line 72

def extract(rpm_path, output_dir)
  self.open(rpm_path) do |rpm|
    rpm.extract(output_dir)
  end
end

.info(path) ⇒ Hash

Get RPM information

Parameters:

  • path (String)

    Path to RPM file

Returns:

  • (Hash)

    Package information



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/omnizip/formats/rpm.rb', line 82

def info(path)
  self.open(path) do |rpm|
    {
      name: rpm.name,
      version: rpm.version,
      release: rpm.release,
      epoch: rpm.epoch,
      arch: rpm.architecture,
      summary: rpm.summary,
      description: rpm.description,
      license: rpm.license,
      vendor: rpm.vendor,
      build_time: rpm.build_time,
      file_count: rpm.files.size,
    }
  end
end

.list(path) ⇒ Array<String>

List files in RPM

Parameters:

  • path (String)

    Path to RPM file

Returns:

  • (Array<String>)

    File paths



64
65
66
# File 'lib/omnizip/formats/rpm.rb', line 64

def list(path)
  self.open(path, &:files)
end

.open(path) {|reader| ... } ⇒ Reader

Open RPM package

Parameters:

  • path (String)

    Path to RPM file

Yields:

  • (reader)

    Block for reading package

Yield Parameters:

  • reader (Reader)

    RPM reader

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/omnizip/formats/rpm.rb', line 45

def open(path)
  reader = Reader.new(path)
  reader.open

  if block_given?
    begin
      yield reader
    ensure
      reader.close
    end
  else
    reader
  end
end