Last active
August 29, 2015 14:00
-
-
Save timlau/11108350 to your computer and use it in GitHub Desktop.
Dnf 0.5.0 group remove api test
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
from __future__ import print_function | |
import sys | |
# insert your own dnf git checkout build path here | |
sys.path.insert(0, '/home/tim/udv/tmp/dnf/dnf') | |
import dnf | |
class DnfBase(dnf.Base): | |
''' | |
class to encapsulate and extend the dnf.Base API | |
''' | |
def __init__(self, setup_sack=True): | |
dnf.Base.__init__(self) | |
self.setup_cache() | |
self.read_all_repos() | |
self.fill_sack() | |
self.read_comps() | |
def setup_cache(self): | |
conf = self.conf | |
conf.releasever = '20' # FIXME : this ugly, find a way to detect the release | |
# This is not public API, but we want the same cache as dnf cli | |
suffix = dnf.yum.parser.varReplace(dnf.const.CACHEDIR_SUFFIX, conf.yumvar) | |
cli_cache = dnf.conf.CliCache(conf.cachedir, suffix) | |
conf.cachedir = cli_cache.cachedir | |
self._system_cachedir = cli_cache.system_cachedir | |
print("cachedir: %s" % conf.cachedir) | |
if __name__ == "__main__": | |
id_ = 'firefox' | |
base = DnfBase() | |
grp = base.comps.group_by_pattern(id_) | |
print('group : {0} ({1})'.format(grp.name, grp.id)) | |
p_grp = base.group_persistor.group(id_) | |
print('persitor group : {0})'.format(p_grp.param_dct)) | |
if p_grp.installed: | |
print ('the {} group is installed'.format(id_)) | |
cnt = base.group_remove(grp) | |
print('group pkgs to remove : {}'.format(cnt)) | |
rc = base.resolve(allow_erasing=True) | |
print('resolve rc: {}'.format(rc)) | |
if rc: | |
rc = base.do_transaction() | |
print('do_transaction rc: {}'.format(rc)) | |
else: | |
print('no transaction to run') | |
else: | |
print ('the {} group is not installed'.format(id_)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment