Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
c2543e78
Commit
c2543e78
authored
May 03, 2019
by
Samuel GAIST
Browse files
[common] Improve handling of version/fork setup
parent
794f6626
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/common.py
View file @
c2543e78
...
...
@@ -151,35 +151,32 @@ class Selector(object):
self
.
prefix
=
prefix
# the root of the directory
self
.
path
=
os
.
path
.
join
(
self
.
prefix
,
".beat"
,
"selected.json"
)
status
=
False
self
.
__version
=
{}
self
.
__fork
=
{}
self
.
__versionables
=
[
"dataformat"
,
"database"
,
"algorithm"
,
"library"
,
"toolchain"
,
"experiment"
,
"protocoltemplate"
,
]
self
.
__forkables
=
[
"dataformat"
,
"database"
,
"algorithm"
,
"library"
,
"toolchain"
,
"experiment"
,
"protocoltemplate"
,
]
if
os
.
path
.
exists
(
self
.
path
):
status
=
self
.
load
()
if
not
status
:
self
.
__version
=
{
"dataformat"
:
dict
(),
"database"
:
dict
(),
"algorithm"
:
dict
(),
"library"
:
dict
(),
"toolchain"
:
dict
(),
"experiment"
:
dict
(),
"protocoltemplate"
:
dict
(),
}
self
.
__fork
=
{
"dataformat"
:
dict
(),
"database"
:
dict
(),
"algorithm"
:
dict
(),
"library"
:
dict
(),
"toolchain"
:
dict
(),
"experiment"
:
dict
(),
"protocoltemplate"
:
dict
(),
}
self
.
load
()
else
:
for
type_
in
TYPE_GLOB
.
keys
():
if
type_
not
in
self
.
__version
:
self
.
__version
[
type_
]
=
dict
()
if
type_
not
in
self
.
__fork
:
self
.
__fork
[
type_
]
=
dict
()
self
.
__ensure_entries
()
def
__enter__
(
self
):
"""Implements our context manager"""
...
...
@@ -189,6 +186,17 @@ class Selector(object):
"""Implements our context manager"""
self
.
save
()
def
__ensure_entries
(
self
):
"""Ensure all types have an entry"""
for
type_
in
self
.
__versionables
:
if
type_
not
in
self
.
__version
:
self
.
__version
[
type_
]
=
dict
()
for
type_
in
self
.
__forkables
:
if
type_
not
in
self
.
__fork
:
self
.
__fork
[
type_
]
=
dict
()
def
fork
(
self
,
type
,
src
,
dst
):
"""Registers that object ``dst`` is a fork of object ``src``"""
...
...
@@ -248,6 +256,8 @@ class Selector(object):
self
.
__fork
=
data
[
"fork"
]
self
.
__version
=
data
[
"version"
]
self
.
__ensure_entries
()
return
True
def
save
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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