Zypper (libzypp) functionality in Ruby
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
test
.gitignore
CHANGELOG
LICENSE
README.markdown
Rakefile
TODO
VERSION
zypper.gemspec

README.markdown

Zypper Library

This library provides Ruby access to libzypp using the zypper command.

License

Distributed under the MIT license, see LICENSE file.

Features

  • Easy-to-use API
  • Running zypper in chroot or running your system zypper over a different root directory
  • Handling packages, repositories and patches
  • Easy to extend

Usage

Require the library

require "zypper"

Initialize new access to the library methods

zypper = Zypper.new()

Add a new repository

zypper.repository.add(:url => 'http://example.org/new/repo', :alias => 'Repo_at_Example_Org')

Public Methods

Global

Constructor

zypper = Zypper.new(parameters)
# or
config = Zypper::Config.new(parameters)
zypper = Zypper.new(config)

All parameters are optional, using their default value if not set.

Possible parameters in hash:

  • :root => '/changed-root' - defaults to '/'
  • :chroot_method => 'local' (calls local zypper with changed root) or 'chroot' (calls zypper in chroot)
  • :refresh_repo => true or false - default for all newly added repositories
  • :auto_agree_with_licenses => true or false - default for installing packages, applying patches...

Example:

zypper = Zypper.new(:chroot => '/some-chroot-dir', :chroot_method => 'chroot')

Zypper Output

These methods work after calling all API functions:

  • last_message - unparsed STDOUT of the last zypper call
  • last_error_message - unparsed STDERR of the last zypper call
  • last_exit_status - exit code (integer) of the last zypper call

Example:

zypper.last_message

Zypper Version

version

# returns
{:major=>1, :minor=>3, :revision=>7}

Caches Cleanup

clean_caches

# returns
true or false

Importing All used GPG Keys

auto_import_keys

# returns
true or false

Repositories

You can access the repositories class either with

zypper = Zypper.new
zypper.repository
# or
zypper.repositories

or

Zypper::Repository.new

Listing repositories

zypper.repositories.all

# returns
[
  { "enabled"=>true, "autorefresh"=>true, "name"=>"SLES11-SP1-x68_64", "url"=>["http://repo/URI"],
    "type"=>"rpm-md", "alias"=>"repository_alias", "gpgcheck"=>true },
  { ... },
  ...
]

Adding a Repository

zypper.repository.add(:url => 'http://repository/URI', :alias => 'repository_alias')

# returns
true or false

Example:

Zypper.new.repository.add(:url => 'http://repository/URI', :alias => 'repository_alias')
# or
Zypper::Repository.new.add(:url => 'http://repository/URI', :alias => 'repository_alias')

Removing a Repository

zypper.repository.remove(:alias => 'repository_alias')

# returns
true or false

Refreshing Repositories

zypper.repository.refresh(parameters)

# returns
true or false

Possible optional parameters:

  • :force - forces a complete refresh
  • :force_build - forces rebuild of the database

Services

You can access the services class either with

zypper = Zypper.new
zypper.service
# or
zypper.services

or

Zypper::Service.new

Listing Services

zypper.services.all

Example:

Zypper.new.services.all
# or
Zypper::Services.new.all

Refreshing Services

zypper.services.refresh

# returns
true or false

Packages

Installing Packages

You can access the packages class either with

zypper = Zypper.new
zypper.package
# or
zypper.packages

or

Zypper::Package.new
zypper.packages.install(:packages => ['package', 'package', ...])

# returns
true or false

package string can consist of NAME[.ARCH][OP], where OP is one of <, <=, =, >=, >, for example:

zypper.package.install :packages => ['less.x86_64=424b-10.22']

Removing Packages

zypper.packages.remove(:packages => ['package', 'package', ...])

# returns
true or false

package string can consist of NAME[.ARCH][OP], where OP is one of <, <=, =, >=, >, for example:

zypper.package.remove :packages => ['less.x86_64=424b-10.22']

Installed Packages

Lists all installed packages.

zypper.packages.installed

# returns
[
  {
    :type=>"package", :status=>:installed, :summary=>"Package, Patch, Pattern, and Product Management",
    :name=>"libzypp"
  },
  { ... },
  ...
]

Available Packages

zypper.packages.available

# returns
[
  {
    :type=>"package", :status=>:available, :summary=>"Helper that makes writing ...",
    :name=>"zypp-plugin-python"
  },
  { ... },
  ...
]

Packages Search

zypper.packages.find

# returns
[
  ... list of packages ...
]

Example

# All packages with name 'kernel-default'
zypper.packages.find(:name => 'kernel-default')

# All available packages matching zypp*
zypper.packages.find(:name => 'zypp*', :status => :available)

# All installed packages
zypper.packages.find(:status => :installed)

Package Info

zypper.package.info(:package => 'package')

# Returns, e.g.
{
  :status=>"not installed", :version=>"424b-10.22",
  :summary=>"Text File Browser and Pager Similar to more", :arch=>"x86_64",
  :repository=>"SLES11-SP1-x68_64", :size=>"266.0 KiB",
  :vendor=>"SUSE LINUX Products GmbH, Nuernberg, Germany",
  :name=>"less", :installed=>"No", :level=>"Level 3"
}

Package Installed?

zypper.package.installed?(:package => 'package')

# returns
true or false

Package Updates

Returns list of packages that could be updated (with higher version available).

zypper.packages.updates

# returns e.g.
[
  ...
  {:source=>{:url=>"http://download.opensuse.org/update/12.1/", :alias=>"openSUSE_12.1_Updates"},
   :summary=>"Utilities to query and test DNS  ", :license=>nil, :description=>"This package
   includes the utilities host, dig, and nslookup used to\ntest and query the Domain Name System
   (DNS).  The Berkeley Internet\nName Domain (BIND) DNS server is found in the package named bind.",
   :edition=>"9.8.3P1-4.14.1", :name=>"bind-utils", :kind=>"package", :arch=>"x86_64"
  },
  ...
]

Patches

You can access the patches class either with

zypper = Zypper.new
zypper.patch
# or
zypper.patches

or

Zypper::patch.new

Listing Patches

All known patches

zypper.patches.all

Searching for Patches

zypper.patches.find(filter_parameters)

# returns
[
  { :status=>'Needed', :category=>'Recommended', :name=>'patch-name',
    :version=>'patch-version', :catalog=>"repository-name"
  },
  { ... },
  ...
]

All parameters are optional and can be combined, using their default value if not set.

Possible parameters in hash:

  • :status => 'Status' (see Zypper::Patch::Status class constants)
  • :category => 'Category' (See Zypper::Patch::Category class constants)
  • :name => 'Exact-Name'
  • :version => 'Exact-Version'
  • :catalog => 'Alias-of-the-repo'

Example:

zypper.patches.all(
  :status => Zypper::Patch::Status::INSTALLED,
  :category => Zypper::Patch::Category::RECOMMENDED
)

Applicable Patches

Lists all applicable patches. All filter parameters are optional and can be used the same as for the find() method.

zypper.patches.applicable(filter_parameters)

Any Applicable Patches?

Returns whether there are any applicable patches present. All filter parameters are optional and can be used the same as for the find() method.

zypper.patches.applicable?(filter_parameters)

Installed Patches

Lists all installed patches. All filter parameters are optional and can be used the same as for the find() method.

zypper.patches.installed(filter_parameters)

Install Patches

Installs all applicable patches.

zypper.patches.install