/
rdoinfo.py
162 lines (135 loc) · 5.11 KB
/
rdoinfo.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from __future__ import print_function
import distroinfo
import distroinfo.query
from distroinfo.info import DistroInfo
from rdopkg import exception, helpers
from rdopkg.utils import log
from rdopkg.conf import cfg
def print_releases(info):
print("{t.bold}releases & repos:{t.normal}".format(t=log.term))
for rls in info['releases']:
if 'status' in rls:
s = (" {t.bold}{rls} in {status} "
"phase {t.normal}").format(t=log.term,
rls=rls['name'],
status=rls['status'])
else:
s = (" {t.bold}{rls}{t.normal}").format(t=log.term,
rls=rls['name'])
if 'fedora' in rls:
s += ' (Fedora %s)' % rls['fedora']
print(s)
for repo in rls['repos']:
if 'special' in repo:
print(" {t.bold}{name}{t.normal}: "
"{t.yellow}{special}{t.normal}".format(
t=log.term,
name=repo['name'],
special=repo['special']))
else:
print(" {t.bold}{name}{t.normal} built in"
" {t.bold}{bs}{t.normal} from"
" {t.bold}{branch}{t.normal} branch".format(
t=log.term,
name=repo['name'],
bs=repo.get('buildsys', '??'),
branch=repo['branch']))
def print_release_info(release):
repo_names = []
output = {}
output['name'] = release["name"]
output['status'] = release["status"]
output['branch'] = release["branch"]
if "identifier" in release:
output['identifier'] = release["identifier"]
output['source_branch'] = "stable/" + release["identifier"]
else:
output['source_branch'] = "stable/" + release["name"]
for repo in release["repos"]:
repo_names.append(repo['name'])
output['repos'] = ', '.join(repo_names)
dict_print = helpers.DictPrinter(header='name',
first=['status', 'branch',
'identifier', 'source_branch'],
last=['repos'])
dict_print(output)
def print_pkg_summary(info):
pkgs = info['packages']
n = len(pkgs)
print("{t.bold}{n} packages defined:{t.normal}".format(
t=log.term, n=n))
confs = {}
for pkg in pkgs:
conf = pkg.get('conf')
confs[conf] = confs.get(conf, 0) + 1
for conf, n in confs.items():
if not conf:
continue
print(" {t.bold}{n}{t.normal} using {t.bold}{conf}{t.normal} "
"config".format(t=log.term, conf=conf, n=n))
n = confs.get(None)
if n:
print(" {t.bold}{n}{t.normal} configured ad-hoc".format(
t=log.term, n=n))
def print_summary(info):
print_releases(info)
print('')
print_pkg_summary(info)
def print_pkgs(info, filters=None):
pkgs = info['packages']
if filters:
pkgs = distroinfo.query.filter_pkgs(pkgs, rexen=filters)
if not pkgs:
print("No packages match your filter.")
return
print("{t.bold}{n} packages found:{t.normal}".format(t=log.term,
n=len(pkgs)))
for pkg in pkgs:
print("")
print_pkg(pkg)
def print_pkg(pkg):
dp = helpers.DictPrinter(
header='name',
first=['project', 'conf', 'upstream', 'patches', 'distgit', 'master',
'distgit'],
last=['maintainers'])
dp(pkg)
def info_file(distro=None):
"""Return default distroinfo info file"""
if not distro:
distro = cfg['DISTRO']
info_file_conf = distro.upper() + 'INFO_FILE'
try:
return cfg[info_file_conf]
except KeyError:
raise exception.InvalidUsage(
why="Couldn't find config option %s for distro: %s"
% (info_file_conf, distro))
def get_distroinfo(distro=None):
"""Get DistroInfo initialized from configuration"""
if not distro:
distro = cfg['DISTRO']
_info_file = info_file(distro)
# prefer git fetcher if available
git_info_url_conf = distro.upper() + 'INFO_REPO'
try:
remote_git_info = cfg[git_info_url_conf]
return DistroInfo(_info_file, remote_git_info=remote_git_info)
except KeyError:
pass
# try raw remote fetcher
remote_info_url_conf = distro.upper() + 'INFO_RAW_URL'
try:
remote_info = cfg[remote_info_url_conf]
return DistroInfo(_info_file, remote_info=remote_info)
except KeyError:
raise exception.InvalidUsage(
why="Couldn't find config option %s or %s for distro: %s"
% (git_info_url_conf, remote_info_url_conf, distro))
def get_rdoinfo():
"""Compat function
"""
return get_distroinfo(distro='rdo')
def get_default_inforepo(apply_tag=None, include_fns=None):
raise DeprecationWarning("rdopkg >= 0.47.0 uses distroinfo, please use "
"`get_distroinfo` instead.")