-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnf-repo.py
83 lines (63 loc) · 2.34 KB
/
dnf-repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import
from base import DnfBase
# we need 0.4.16 or later for the progress to work
from dnf.callback import DownloadProgress
class MDProgress(DownloadProgress):
def __init__(self):
super(MDProgress, self).__init__()
self._last = None
def start(self, total_files, total_size):
#print("Start : ", total_files, total_size)
self._last = None
def end(self,payload, status, msg):
#print ("End : ", str(payload), status, msg)
pass
def progress(self, payload, done):
if not self._last:
print (" Getting repo metadata : %s " % str(payload))
self._last = payload
class DnfExample(DnfBase):
'''
This example shows how to get packages matching a given
package name.
'''
def __init__(self):
DnfBase.__init__(self,setup_sack=False) # dont load the sack yet
self.progress = MDProgress()
# Find some repositories matching a filter
print("Find *-source repos")
for repo in self.find_repos("*-source"):
print(" : %s" % repo.id)
# Enable & disable some repositories
self.enable_repos(['updates-testing'])
self.disable_repos(['Dropbox'])
self.repos.all().set_progress_bar(self.progress)
print("Enabled repositories : ")
for repo in self.repos.iter_enabled():
print(" : %s" % repo.id)
print("Setting up the package sack")
self.fill_sack()
print("show repo attributes")
self.get_repo_attr('updates')
def find_repos(self, filter):
return self.repos.get_matching(filter)
def enable_repos(self, to_enable):
for repo in self.repos.all():
if repo.id in to_enable:
repo.enable()
def disable_repos(self, to_disable):
for repo in self.repos.all():
if repo.id in to_disable:
repo.disable()
def get_repo_attr(self, id):
repo = self.repos.get(id, None) # get the repo object
if repo:
print("%-20s : %s" % ("id", str(repo.id)))
for attr in repo.iterkeys():
res = getattr(repo, attr)
print("%-20s : %s" % (attr, str(res)))
if __name__ == "__main__":
de = DnfExample()
del de