marguerite / rubygem-rpmspec

Parse an RPM specfile into Ruby structs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RPMSpec


Code Climate

RPMSpec parses an RPM specfile into Ruby OpenStructs. It not only parses the tags, but also macros, sections like %install, files, changelog and etc. It can also parse conditional requirements and scriptlets.

It is distributed as a standard rubygem and licensed under MIT.

Terms

  • tag: 'Name', 'Version'...

  • macro: %define a %(/usr/bin/echo "a"), %{!?b %global b %(/usr/bin/echo "b")}

  • section: %prep, %build...

  • conditional requirements:

      %if 0%{?suse_version}
      BuildRequires:  a
      %else
      BuildRequires:  b
      %endif
    

Usage

    require 'rpmspec'
    specfile = RPMSpec::Parser.new('test.spec').parse

    # get package name
    puts specfile.name # => ['Test']
Dependencies

dependency: it can be 'BuildRequires', 'Requires', 'Provides'...

conditionals: an array ["%if 0%{?suse_version} >= 1320", "%if 0%{?suse_version}"]. Basically, if:

    %if 0%{?suse_version}
    BuildRequires:  a
    %if 0%{?suse_version} >= 1320
    BuildRequires:  b
    BuildRequires:  c
    %endif
    %else
    BuildRequires:  d
    %endif

Then, specfile.buildrequires will return an array contains a, b, c and d. But their conditionals are different, eg:

    c # => <#OpenStruct 'name'='c' 'conditionals'=['%if 0%{?suse_version}', '%if 0%{?suse_version} >= 1320'] 'modifier'=nil>
    d # => <#OpenStruct 'name'='d' 'conditionals'=['%if !0%{?suse_version}'] 'modifier'=nil>

modifier: eg Requires(post), the modifier is post.

Self-defined Macros

indicator: There're two ways to self-define a macro inside specfile: %define and %global.

test: return true if sometimes packagers check the existence of a macro like this %{!?macro %define macro}.

Sub Packages
    specfile.subpackages # => [<#OpenStruct similar with specfile itself>, <#OpenStruct ... >] 

Sub packages are actually normal packages without some build worker instruction tags like BuildRoot.

Sections
    specfile.install # => everything under %install section in plain text

About

Parse an RPM specfile into Ruby structs

License:MIT License


Languages

Language:Ruby 100.0%