2008-09-16 04:01:21 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Licensed under the GNU General Public License Version 2
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
# Copyright (C) 2008
|
|
|
|
# Tim Lauridsen <timlau@fedoraproject.org>
|
|
|
|
|
|
|
|
import sys
|
2008-10-06 08:18:14 -07:00
|
|
|
|
2008-09-16 04:01:21 -07:00
|
|
|
from packagekit.client import PackageKitClient
|
|
|
|
from packagekit.enums import *
|
|
|
|
|
2008-09-24 04:46:30 -07:00
|
|
|
def show_packages(pkit, pkgs, details=False, limit=None):
|
2008-09-18 03:25:08 -07:00
|
|
|
i = 0
|
|
|
|
for pkg in pkgs:
|
|
|
|
i += 1
|
|
|
|
if limit and i == limit:
|
|
|
|
break
|
|
|
|
show_package(pkg)
|
|
|
|
if details:
|
2008-09-24 04:46:30 -07:00
|
|
|
detail = pkit.GetDetails(pkg.id)
|
2008-09-18 03:25:08 -07:00
|
|
|
print 79 *"-"
|
2008-09-24 04:46:30 -07:00
|
|
|
print detail[0].detail
|
2008-09-18 03:25:08 -07:00
|
|
|
print 79 *"="
|
|
|
|
|
|
|
|
def show_package(pkg):
|
|
|
|
if pkg:
|
|
|
|
if isinstance(pkg, list):
|
|
|
|
pkg = pkg[0]
|
2008-10-06 08:18:14 -07:00
|
|
|
print pkg
|
|
|
|
print pkg.summary
|
2008-09-18 03:25:08 -07:00
|
|
|
else:
|
|
|
|
print "no package found"
|
|
|
|
|
2008-09-16 04:01:21 -07:00
|
|
|
if __name__ == '__main__':
|
2008-09-16 04:54:30 -07:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
cmd = sys.argv[1:]
|
|
|
|
else:
|
|
|
|
cmd = 'all'
|
2008-09-16 04:01:21 -07:00
|
|
|
|
2008-09-16 04:54:30 -07:00
|
|
|
pk = PackageKitClient()
|
2008-09-16 04:01:21 -07:00
|
|
|
|
2008-09-16 04:54:30 -07:00
|
|
|
if 'all' in cmd or "refresh-cache" in cmd:
|
|
|
|
print '---- RefreshCache() -----'''
|
2008-09-18 03:25:08 -07:00
|
|
|
pk.RefreshCache()
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if 'all' in cmd or "resolve" in cmd:
|
|
|
|
print '---- Resolve() -----'
|
|
|
|
pkg = pk.Resolve(FILTER_NONE, 'yum')
|
2008-09-18 03:25:08 -07:00
|
|
|
show_package(pkg)
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if 'all' in cmd or "get-packages" in cmd:
|
|
|
|
print '---- GetPackages() ----'
|
|
|
|
packages = pk.GetPackages(FILTER_INSTALLED)
|
2008-09-24 04:46:30 -07:00
|
|
|
show_packages(pk, packages, details=True, limit=20)
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if 'all' in cmd or "search-file" in cmd:
|
|
|
|
print '---- SearchFile() ----'
|
2008-09-18 03:25:08 -07:00
|
|
|
pkgs = pk.SearchFile(FILTER_INSTALLED,"/usr/bin/yum")
|
2008-09-24 04:46:30 -07:00
|
|
|
show_packages(pk, pkgs)
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if 'all' in cmd or "get-updates" in cmd:
|
|
|
|
print '---- GetUpdates() ----'
|
|
|
|
pkgs = pk.GetUpdates(FILTER_INSTALLED)
|
|
|
|
if pkgs: # We have updates
|
|
|
|
for p in pkgs:
|
2008-09-21 02:53:10 -07:00
|
|
|
print p.id
|
|
|
|
print pk.GetUpdateDetail(p.id)
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if 'all' in cmd or "search-name" in cmd:
|
|
|
|
print '---- SearchName() -----'
|
2008-09-18 03:25:08 -07:00
|
|
|
show_package(pk.SearchName(FILTER_NOT_INSTALLED, 'coreutils'))
|
|
|
|
show_package(pk.SearchName(FILTER_INSTALLED, 'coreutils'))
|
|
|
|
|
|
|
|
if "search-group" in cmd:
|
|
|
|
print '---- SearchGroup() -----'
|
2008-09-24 04:46:30 -07:00
|
|
|
show_packages(pk, pk.SearchGroup(FILTER_NONE, GROUP_GAMES))
|
|
|
|
show_packages(pk, pk.SearchGroup(FILTER_NONE, GROUP_COLLECTIONS))
|
2008-09-18 03:25:08 -07:00
|
|
|
|
|
|
|
if "get-distro-upgrades" in cmd:
|
|
|
|
print '---- GetDistroUpgrades() -----'
|
|
|
|
rc = pk.GetDistroUpgrades()
|
|
|
|
if rc:
|
|
|
|
print rc
|
|
|
|
else:
|
|
|
|
print "No distribution upgrades"
|
2008-09-16 04:01:21 -07:00
|
|
|
|
|
|
|
|
2008-09-24 04:46:30 -07:00
|
|
|
def cb(status, pct, spct, elem, rem, cancel):
|
|
|
|
print 'install pkg: %s, %i%%, cancel allowed: %s' % \
|
|
|
|
(status, pct, str(cancel))
|
2008-09-16 04:01:21 -07:00
|
|
|
return True
|
|
|
|
#return pc < 12
|
|
|
|
|
2008-09-16 04:54:30 -07:00
|
|
|
if "updates-system" in cmd:
|
|
|
|
print '---- UpdateSystem() ----'
|
|
|
|
print pk.UpdateSystem()
|
|
|
|
|
|
|
|
if "install-packages" in cmd:
|
|
|
|
print '---- InstallPackages() -----'
|
|
|
|
pkg = pk.Resolve(FILTER_NOT_INSTALLED, 'yumex')
|
|
|
|
if pkg:
|
2008-09-21 02:53:10 -07:00
|
|
|
print "Installing : %s " % pkg[0].id
|
|
|
|
pk.InstallPackages(pkg[0].id, cb)
|
2008-09-16 04:54:30 -07:00
|
|
|
|
|
|
|
if "remove-packages" in cmd:
|
|
|
|
print '---- RemovePackages() -----'
|
2008-09-16 05:56:02 -07:00
|
|
|
pkg = pk.Resolve(FILTER_INSTALLED, 'yumex')
|
2008-09-16 04:54:30 -07:00
|
|
|
if pkg:
|
2008-09-21 02:53:10 -07:00
|
|
|
print "Removing : %s " % pkg[0].id
|
|
|
|
pk.RemovePackages(pkg[0].id, cb)
|
2008-09-16 04:01:21 -07:00
|
|
|
|
2008-09-17 07:06:29 -07:00
|
|
|
if "download-packages" in cmd:
|
|
|
|
print '---- DownloadPackages() -----'
|
|
|
|
pkg = pk.Resolve(FILTER_NOT_INSTALLED, 'yumex')
|
|
|
|
if pkg:
|
2008-09-21 02:53:10 -07:00
|
|
|
print "Installing : %s " % pkg[0].id
|
|
|
|
print pk.DownloadPackages(pkg[0].id)
|
2008-09-16 04:01:21 -07:00
|
|
|
|
2008-10-06 08:18:14 -07:00
|
|
|
if "get-categories" in cmd:
|
|
|
|
print '---- GetCategories() -----'
|
|
|
|
cats = pk.GetCategories()
|
|
|
|
for cat in cats:
|
|
|
|
print cat.name
|
|
|
|
|
2008-09-16 04:01:21 -07:00
|
|
|
pk.SuggestDaemonQuit()
|
|
|
|
|