Skip to content

Commit 4c5d3d4

Browse files
committed
Add an option to specify the filename in info repo
Currently, we have hardcoded the name of the main file for inforepo to `rdo.yml`. However, to extend the usage to other projects as NFV SIG that may have a different filename for the initial file, as `nfv.yml`[1], this patch is adding a parameter --info-file that defaults to rdo.yml but can be set to other name files. Also, this patch is replacing the usage of the old parse function included in rdoinfo module in the rdoinfo repo by distroinfo. Change-Id: Ic9432552956eb307100064afdbc257137e6bbed4
1 parent 4576ec2 commit 4c5d3d4

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

Diff for: graffiti/cli.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def main():
172172
parser.add_argument('--centos-release', default='7',
173173
choices=['7', '8', '8s'],
174174
help='CentOS Release to check.')
175+
parser.add_argument('--info-file', default='rdo.yml',
176+
help='Main info file. Default: rdo.yml')
175177
subparsers = parser.add_subparsers(dest='cmd')
176178

177179
subparsers.add_parser('version', help='show version') # NOQA
@@ -206,7 +208,7 @@ def main():
206208
sys.argv.append('--help')
207209
args = parser.parse_args(sys.argv[1:])
208210
config = parse_config_file(args.config_file, args.info_repo,
209-
args.centos_release)
211+
args.centos_release, args.info_file)
210212

211213
if args.cmd == 'version':
212214
version_cmd()

Diff for: graffiti/config.py

+15-23
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
"""graffiti.config handles config and command files parsing
22
"""
3-
import imp
43
import os.path
54
import yaml
65

6+
from distroinfo import info as dinfo
77

8-
def parse_config_file(filename, rdoinfo_path=None, centos_release='7'):
8+
9+
def parse_config_file(filename, rdoinfo_path=None, centos_release='7',
10+
info_file='rdo.yml'):
911
"""Parse graffiti config file
1012
"""
1113
with open(filename, 'rb') as cfg_file:
1214
data = yaml.load(cfg_file)
13-
info = parse_config(data, rdoinfo_path, centos_release)
15+
info = parse_config(data, rdoinfo_path, centos_release, info_file)
1416
return info
1517
return None
1618

1719

18-
def parse_config(data, rdoinfo_path=None, centos_release='7'):
20+
def parse_config(data, rdoinfo_path=None, centos_release='7',
21+
info_file='rdo.yml'):
1922
"""Config file parser
2023
"""
2124
info = {}
2225
if not rdoinfo_path:
2326
info['rdoinfo'] = parse_rdoinfo(data)
2427
rdoinfo_path = info['rdoinfo']['location']
25-
info['releases'] = parse_releases(rdoinfo_path, centos_release)
26-
info['releases_info'] = parse_releases_info(rdoinfo_path)
28+
info['releases'] = parse_releases(rdoinfo_path, centos_release, info_file)
29+
info['releases_info'] = parse_releases_info(rdoinfo_path, info_file)
2730
info['koji'] = parse_koji(data)
2831
info['tags_maps'] = data['tags_maps']
2932
return info
@@ -36,21 +39,11 @@ def parse_rdoinfo(data):
3639
return {'location': location}
3740

3841

39-
# Shamelessly taken from rdopkg code
40-
def _ensure_rdoinfo(path):
41-
file, path, desc = imp.find_module('rdoinfo', [path])
42-
rdoinfo = imp.load_module('rdoinfo', file, path, desc)
43-
return rdoinfo
44-
45-
46-
def parse_releases(rdoinfo_path, centos_release='7'):
42+
def parse_releases(rdoinfo_path, centos_release='7', info_file='rdo.yml'):
4743
"""Parse config release section to extract buildsys-tags
4844
"""
49-
rdoinfo_db = os.path.join(rdoinfo_path, 'rdo.yml')
50-
rdoinfo = _ensure_rdoinfo(rdoinfo_path)
51-
# FIXME: needs to unset include_fns as default in rdoinfo
52-
# is a relative path
53-
data = rdoinfo.parse_info_file(rdoinfo_db, include_fns=[])
45+
data = dinfo.DistroInfo(info_files=info_file,
46+
local_info=rdoinfo_path).get_info()
5447
releases = data['releases']
5548
rel = {}
5649
dist_tag = "el{0}".format(centos_release)
@@ -66,12 +59,11 @@ def parse_releases(rdoinfo_path, centos_release='7'):
6659
return rel
6760

6861

69-
def parse_releases_info(rdoinfo_path):
62+
def parse_releases_info(rdoinfo_path, info_file='rdo.yml'):
7063
"""Parse config release section
7164
"""
72-
rdoinfo_db = os.path.join(rdoinfo_path, 'rdo.yml')
73-
rdoinfo = _ensure_rdoinfo(rdoinfo_path)
74-
data = rdoinfo.parse_info_file(rdoinfo_db, include_fns=[])
65+
data = dinfo.DistroInfo(info_files=info_file,
66+
local_info=rdoinfo_path).get_info()
7567
releases = data['releases']
7668
releases_info = {}
7769
for release in releases:

Diff for: graffiti/tests/fake_rdoinfo.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Fake rdoinfo module for tests
22
#
33

4-
import sys
54
import yaml
65

76
RDOINFO_SAMPLE = """releases:
@@ -79,9 +78,9 @@
7978
"""
8079

8180

82-
def parse_info_file(rdoinfo_db, include_fns):
83-
return yaml.load(RDOINFO_SAMPLE)
81+
class FakeRdoinfo(object):
82+
def __init__(self, **kwargs):
83+
pass
8484

85-
86-
def _ensure_rdoinfo(path):
87-
return sys.modules[__name__]
85+
def get_info(self, **kwargs):
86+
return yaml.load(RDOINFO_SAMPLE)

Diff for: graffiti/tests/test_config.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from __future__ import print_function
2+
from fake_rdoinfo import FakeRdoinfo
23
import os.path
34
try:
45
import unittest.mock as mock
56
except Exception:
67
import mock
78
from graffiti.config import parse_config_file
89

9-
from fake_rdoinfo import _ensure_rdoinfo
10-
1110

1211
SAMPLE_CONFIG = """releases:
1312
rdoinfo:
@@ -37,8 +36,8 @@ def test_parse_config_file():
3736
# FIXME: the multiple context managers syntax does
3837
# not work encapsulated by parenthesis hence disable PEP8 checks
3938
with mock.patch('six.moves.builtins.open', m), \
40-
mock.patch('graffiti.config._ensure_rdoinfo',
41-
side_effect=_ensure_rdoinfo): # noqa
39+
mock.patch('distroinfo.info.DistroInfo',
40+
FakeRdoinfo):
4241
info = parse_config_file('test')
4342
assert info['koji']['username'] == 'hguemar'
4443
assert info['koji']['url'] == 'https://cbs.centos.org/kojihub'

Diff for: requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
PyYAML
2+
distroinfo
23
six

0 commit comments

Comments
 (0)