Created
September 3, 2015 09:03
-
-
Save arindamchoudhury/92127e925faf48a13a96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from gi.repository import PackageKitGlib | |
# this fails in install_packages(), as the Epson archive is not actually signed | |
#repo = 'deb http://download.ebz.epson.net/dsc/op/stable/debian lsb3.2 main' | |
#repo_gpg_id = '8AA65D56' | |
#package = 'epson-inkjet-printer-px-402a' | |
# this works | |
repo = 'deb http://ppa.launchpad.net/picsaw-team/ppa/ubuntu/ quantal main' | |
repo_gpg_id = '220B9F10' | |
package = 'picsaw' | |
# progress callback | |
# http://www.packagekit.org/gtk-doc/PkProgress.html | |
def progress(progress, type, user_data): | |
print ' ', type.value_name, 'package:', progress.props.package_id, ':', progress.props.percentage, '%' | |
# get PackageKit client | |
pk = PackageKitGlib.Client() | |
# install repository key | |
res = pk.install_signature(PackageKitGlib.SigTypeEnum.GPG, repo_gpg_id, '', | |
None, progress, None) | |
print '----------- install_signature result code:', res.get_exit_code() | |
assert res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS | |
# add repository; see | |
# http://www.packagekit.org/gtk-doc/PackageKit-pk-client-sync.html#pk-client-repo-enable | |
res = pk.repo_enable(repo, True, None, progress, None) | |
print '----------- repo_enable result code:', res.get_exit_code() | |
assert res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS | |
# download/update the indexes | |
res = pk.refresh_cache(False, None, progress, None) | |
print '----------- refresh_cache result code:', res.get_exit_code() | |
assert res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS | |
# map package name to PackageKit ID; do not print progress here, it's fast | |
res = pk.resolve(PackageKitGlib.FilterEnum.NONE, [package], | |
None, lambda p, t, d: True, None) | |
print '----------- resolve result code:', res.get_exit_code() | |
assert res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS | |
package_ids = res.get_package_array() | |
assert len(package_ids) > 0 | |
# install the first match | |
package_id = package_ids[0].get_id() | |
print '-------- installing:', package_id | |
# install package | |
res = pk.install_packages(True, [package_id], None, progress, None) | |
print '----------- install_packages result code:', res.get_exit_code() | |
assert res.get_exit_code() == PackageKitGlib.ExitEnum.SUCCESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment