Skip to content

Commit 518af3a

Browse files
committed
[WIP] working on the iterator
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
1 parent a7ace26 commit 518af3a

File tree

3 files changed

+91
-39
lines changed

3 files changed

+91
-39
lines changed

plugins/config/_test_repository.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ projects:
2727
- name: osrf
2828
type: stable
2929
- name: ignition-transport7
30+
distributions:
31+
ubuntu:
32+
- no-existing-distro
3033
repositories:
3134
- name: osrf
3235
type: stable
3336
- name: osrf
3437
type: prerelease
38+
- name: ignition-transport7
39+
distributions:
40+
ubuntu:
41+
- jammy
42+
repositories:
43+
- name: osrf
44+
type: stable
3545
- name: ignition-.*
3646
repositories:
3747
- name: osrf

plugins/repository.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,26 @@ def load_config_file(config_file_path='config/repository.yaml'):
6565
exit(-1)
6666

6767

68-
def get_project_config(project, config):
68+
def get_first_valid_project_config(project, config, linux_distro):
6969
"""Returns the project configuration from yaml that correspond
7070
to the first match while searching starting from top to bottom
7171
"""
7272
for p in config['projects']:
7373
pattern = re.compile(p['name'])
74+
75+
print(config['projects'])
7476
if pattern.search(project):
77+
try:
78+
if linux_distro in config['projects'][project]['distributions'][distro.id()]:
79+
print("FOO")
80+
# print(project_config['distributions'][distro.id()])
81+
except KeyError as kerror:
82+
print(kerror)
83+
if str(kerror) == 'distributions':
84+
pass # supported use case, no distributions defined
85+
else:
86+
warn(str(kerror))
87+
7588
return p
7689
return None
7790

@@ -213,9 +226,10 @@ def validate_input(args):
213226

214227

215228
def process_project_install(project, config, linux_distro, dry_run=False):
216-
project_config = get_project_config(project, config)
229+
project_config = get_first_valid_project_config(project, config, linux_distro)
217230
if not project_config:
218231
error('Unknown project: ' + project)
232+
219233
if not dry_run: # useful for tests
220234
install_repos(get_repositories_config(project_config),
221235
config,

plugins/repository_TEST.py

+65-37
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,92 @@ def setUp(self):
2626
self.config = repository.load_config_file('config/_test_repository.yaml')
2727

2828

29-
class TestBasicOperations(TestBase):
29+
# class TestBasicOperations(TestBase):
3030

31-
def test_config_file_path(self):
32-
self.assertTrue(self.config)
31+
# def test_config_file_path(self):
32+
# self.assertTrue(self.config)
3333

3434

35-
class TestRepoKey(TestBase):
35+
# class TestRepoKey(TestBase):
3636

37-
def test_basic_ok(self):
38-
self.assertEqual(
39-
repository.get_repo_key('osrf', self.config),
40-
'ABC1234567890')
37+
# def test_basic_ok(self):
38+
# self.assertEqual(
39+
# repository.get_repo_key('osrf', self.config),
40+
# 'ABC1234567890')
4141

4242

43-
class TestRepo_URL(TestBase):
43+
# class TestRepo_URL(TestBase):
4444

45-
def test_basic_ok(self):
46-
self.assertEqual(
47-
repository.get_repo_url('osrf', 'prerelease', self.config),
48-
'http://prerelease-' + repository.get_linux_distro())
45+
# def test_basic_ok(self):
46+
# self.assertEqual(
47+
# repository.get_repo_url('osrf', 'prerelease', self.config),
48+
# 'http://prerelease-' + repository.get_linux_distro())
4949

50-
def test_no_repo(self):
51-
with self.assertRaises(SystemExit):
52-
repository.get_repo_url('invalid_repo', 'invalid_type', self.config)
50+
# def test_no_repo(self):
51+
# with self.assertRaises(SystemExit):
52+
# repository.get_repo_url('invalid_repo', 'invalid_type', self.config)
5353

54-
def test_no_type(self):
55-
with self.assertRaises(SystemExit):
56-
repository.get_repo_url('osrf', 'invalid_tye', self.config)
54+
# def test_no_type(self):
55+
# with self.assertRaises(SystemExit):
56+
# repository.get_repo_url('osrf', 'invalid_tye', self.config)
5757

5858

5959
class TestProjectNameResolution(TestBase):
6060

61-
def test_direct_match(self):
62-
project_config = repository.get_project_config('ignition-math6',
63-
self.config)
61+
# def test_direct_match(self):
62+
# project_config = \
63+
# repository.get_first_valid_project_config('ignition-math6',
64+
# self.config,
65+
# 'jammy')
66+
# for p in repository.get_repositories_config(project_config):
67+
# self.assertEqual(p['name'], 'osrf')
68+
# self.assertEqual(p['type'], 'stable')
69+
70+
# def test_non_exist(self):
71+
# self.assertIsNone(
72+
# repository.get_first_valid_project_config('fooooo',
73+
# self.config,
74+
# 'jammy'))
75+
76+
# def test_regexp(self):
77+
# project_config = \
78+
# repository.get_first_valid_project_config('ignition-plugin',
79+
# self.config,
80+
# 'jammy')
81+
# for p in repository.get_repositories_config(project_config):
82+
# self.assertEqual(p['name'], 'osrf')
83+
# self.assertEqual(p['type'], 'regexp')
84+
85+
def test_precedence(self):
86+
project_config = \
87+
repository.get_first_valid_project_config('ignition-transport7',
88+
self.config,
89+
'jammy')
6490
for p in repository.get_repositories_config(project_config):
6591
self.assertEqual(p['name'], 'osrf')
6692
self.assertEqual(p['type'], 'stable')
6793

68-
def test_non_exist(self):
69-
self.assertIsNone(repository.get_project_config('fooooo', self.config))
7094

71-
def test_regexp(self):
72-
project_config = repository.get_project_config('ignition-plugin',
73-
self.config)
74-
for p in repository.get_repositories_config(project_config):
75-
self.assertEqual(p['name'], 'osrf')
76-
self.assertEqual(p['type'], 'regexp')
95+
# class TestProjectInstall(TestBase):
7796

97+
# def test_no_distributions(self):
98+
# repository.process_project_install('ignition-math6',
99+
# self.config,
100+
# 'jammy',
101+
# dry_run=True)
78102

79-
class TestProjectInstall(TestBase):
103+
# def test_distributions(self):
104+
# repository.process_project_install('ignition-transport7',
105+
# self.config,
106+
# 'jammy',
107+
# dry_run=True)
80108

81-
def test_non_exist(self):
82-
with self.assertRaises(SystemExit):
83-
repository.process_project_install('fooooo',
84-
self.config,
85-
'jammy',
86-
dry_run=True)
109+
# def test_non_exist(self):
110+
# with self.assertRaises(SystemExit):
111+
# repository.process_project_install('fooooo',
112+
# self.config,
113+
# 'jammy',
114+
# dry_run=True)
87115

88116

89117
if __name__ == '__main__':

0 commit comments

Comments
 (0)