This library provides Ruby access to libzypp using the
zypper
command.
Distributed under the MIT license, see LICENSE file.
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:
Example:
zypper = Zypper.new(:chroot => '/some-chroot-dir', :chroot_method => 'chroot')
These methods work after calling all API functions:
Example:
zypper.last_message
version
# returns
{:major=>1, :minor=>3, :revision=>7}
clean_caches
# returns
true or false
auto_import_keys
# returns
true or false
You can access the repositories class either with
zypper = Zypper.new
zypper.repository
# or
zypper.repositories
or
Zypper::Repository.new
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 },
{ ... },
...
]
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')
zypper.repository.remove(:alias => 'repository_alias')
# returns
true or false
zypper.repository.refresh(parameters)
# returns
true or false
Possible optional parameters:
You can access the services class either with
zypper = Zypper.new
zypper.service
# or
zypper.services
or
Zypper::Service.new
zypper.services.all
Example:
Zypper.new.services.all
# or
Zypper::Services.new.all
zypper.services.refresh
# returns
true or false
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
zypper.package.install :packages => ['less.x86_64=424b-10.22']
zypper.packages.remove(:packages => ['package', 'package', ...])
# returns
true or false
package
string can consist of NAME[.ARCH][OP
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 false
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"
},
...
]
You can access the patches class either with
zypper = Zypper.new
zypper.patch
# or
zypper.patches
or
Zypper::patch.new
All known patches
zypper.patches.all
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:
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