Project

zypper

0.0
No commit activity in last 3 years
No release in over 3 years
Library for accessing zypper functions such as searching and installing packages, adding and removing repositories and services, filtering and applying patches. Supports calling zypper in changed root (both with local zypper and zypper in chroot).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 0
>= 0
 Project Readme

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