Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
psot.repository
Commits
278b28bc
Commit
278b28bc
authored
Jan 31, 2018
by
Lukas Jelonek
Browse files
Implement merge of multiple psot repositories
parent
c62b52a7
Changes
9
Hide whitespace changes
Inline
Side-by-side
psot/config.py
View file @
278b28bc
...
...
@@ -11,7 +11,6 @@ class Repository:
def
load_config
(
self
):
'''return a dictionary with the whole configuration for this repository'''
config
=
self
.
load_config_file
()
print
(
config
)
config
[
'profiles'
]
=
self
.
load_profiles
()
config
[
'modules'
]
=
self
.
load_modules
()
self
.
normalize_profiles
(
config
[
'profiles'
])
...
...
@@ -101,11 +100,12 @@ class Config:
self
.
repo_paths
=
repository_paths
def
merge_config
(
self
,
source
,
target
):
import
jsonmerge
# Quick hack: replacement instead of merge
# TODO do an actual merge instead of just a replacement
for
k
in
source
:
target
[
k
]
=
source
[
k
]
return
schema
=
{
'properties'
:
{
'profiles'
:{
'mergeStrategy'
:
'append'
}}
}
return
jsonmerge
.
merge
(
target
,
source
,
schema
)
def
load_config
(
self
):
config
=
{}
...
...
@@ -113,7 +113,7 @@ class Config:
for
repo_path
in
self
.
repo_paths
:
repo
=
Repository
(
repo_path
)
repo_config
=
repo
.
load_config
()
self
.
merge_config
(
repo_config
,
config
)
config
=
self
.
merge_config
(
repo_config
,
config
)
# quick hack
# use the last script directory
# TODO replace with list
...
...
requirements.txt
View file @
278b28bc
requests
jsonmerge
pyyaml
pbr
dbxref
tests/data/example_repo/config.yaml
View file @
278b28bc
tools
:
override
:
1
tests/data/example_repo2/config.yaml
0 → 100644
View file @
278b28bc
tools
:
test
:
bla
override
:
2
tests/data/example_repo2/modules/example.yaml
0 → 100644
View file @
278b28bc
name
:
'
example2'
info
:
'
example
module
for
testing'
analysis
:
script
:
'
run_example.sh'
parameters
:
converter
:
script
:
'
convert_example.sh'
parameters
:
tests/data/example_repo2/profiles/test.yaml
0 → 100644
View file @
278b28bc
name
:
'
test2'
info
:
'
Profile
for
testing
purposes'
modules
:
example2
:
tests/data/example_repo2/scripts/convert_example.sh
0 → 100644
View file @
278b28bc
tests/data/example_repo2/scripts/run_example.sh
0 → 100644
View file @
278b28bc
tests/test_repository.py
View file @
278b28bc
...
...
@@ -31,3 +31,29 @@ class TestExampleRepositoryIsLoadedCorrectly(unittest.TestCase):
def
test_that_config_exists
(
self
):
self
.
assertTrue
(
'tools'
in
self
.
config
,
'config.yml not loaded'
)
class
TestMergingRepositoriesWorksCorrectly
(
unittest
.
TestCase
):
def
setUp
(
self
):
repo_path1
=
pkg_resources
.
resource_filename
(
'tests'
,
'data/example_repo/'
)
repo_path2
=
pkg_resources
.
resource_filename
(
'tests'
,
'data/example_repo2/'
)
self
.
repository
=
config
.
Config
([
repo_path1
,
repo_path2
])
self
.
config
=
self
.
repository
.
load_config
()
# output config for debugging purposes
#from pprint import pformat
#print(pformat(self.config))
#print()
def
test_profiles_merged
(
self
):
profiles
=
self
.
config
[
'profiles'
]
self
.
assertTrue
(
len
(
profiles
)
is
2
,
'Only {} profile(s) found, expected 2'
.
format
(
str
(
len
(
profiles
))))
def
test_modules_merged
(
self
):
modules
=
self
.
config
[
'modules'
]
self
.
assertTrue
(
len
(
modules
)
is
2
,
'Only {} module(s) found, expected 2'
.
format
(
str
(
len
(
modules
))))
def
test_config_value_was_overriden
(
self
):
value
=
self
.
config
[
'tools'
][
'override'
]
self
.
assertEqual
(
value
,
2
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment