This library provides Ruby access to libzypp using the
zypper command.
Distributed under the MIT license, see LICENSE file.
- 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
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')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')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_messageversion
# returns
{:major=>1, :minor=>3, :revision=>7}clean_caches
# returns
true or falseauto_import_keys
# returns
true or falseYou can access the repositories class either with
zypper = Zypper.new
zypper.repository
# or
zypper.repositoriesor
Zypper::Repository.newzypper.repositories.all
# returns
[
{ "enabled"=>true, "autorefresh"=>true, "name"=>"SLES11-SP1-x68_64", "url"=>["http://repo/URI"],
"type"=>"rpm-md", "alias"=>"repository_alias", "gpgcheck"=>true },
{ ... },
...
]zypper.repository.add(:url => 'http://repository/URI', :alias => 'repository_alias')
# returns
true or falseExample:
Zypper.new.repository.add(:url => 'http://repository/URI', :alias => 'repository_alias')
# or
Zypper::Repository.new.add(:url => 'http://repository/URI', :alias => 'repository_alias')zypper.repository.remove(:alias => 'repository_alias')
# returns
true or falsezypper.repository.refresh(parameters)
# returns
true or falsePossible optional parameters:
- :force - forces a complete refresh
- :force_build - forces rebuild of the database
You can access the services class either with
zypper = Zypper.new
zypper.service
# or
zypper.servicesor
Zypper::Service.newzypper.services.allExample:
Zypper.new.services.all
# or
Zypper::Services.new.allzypper.services.refresh
# returns
true or falseYou can access the packages class either with
zypper = Zypper.new
zypper.package
# or
zypper.packagesor
Zypper::Package.newzypper.packages.install(:packages => ['package', 'package', ...])
# returns
true or falsepackage string can consist of NAME[.ARCH][OP], where OP is one
of <, <=, =, >=, >, for example:
zypper.package.install :packages => ['less.x86_64=424b-10.22']zypper.packages.remove(:packages => ['package', 'package', ...])
# returns
true or falsepackage string can consist of NAME[.ARCH][OP], where OP is one
of <, <=, =, >=, >, for example:
zypper.package.remove :packages => ['less.x86_64=424b-10.22']Lists all installed packages.
zypper.packages.installed
# returns
[
{
:type=>"package", :status=>:installed, :summary=>"Package, Patch, Pattern, and Product Management",
:name=>"libzypp"
},
{ ... },
...
]zypper.packages.available
# returns
[
{
:type=>"package", :status=>:available, :summary=>"Helper that makes writing ...",
:name=>"zypp-plugin-python"
},
{ ... },
...
]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)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"
}zypper.package.installed?(:package => 'package')
# returns
true or falseReturns 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"
},
...
]You can access the patches class either with
zypper = Zypper.new
zypper.patch
# or
zypper.patchesor
Zypper::patch.newAll known patches
zypper.patches.allzypper.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
)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)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)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)Installs all applicable patches.
zypper.patches.install