Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Compare revisions
master to feat/update-lock-metadata-yml
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
calibration/pycalibration
Select target project
No results found
feat/update-lock-metadata-yml
Select Git revision
Swap
Target
calibration/pycalibration
Select target project
calibration/pycalibration
1 result
master
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (1)
Add function to update metadata.yml with file locking
· 9e1f2068
Thomas Kluyver
authored
2 years ago
9e1f2068
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/tools.py
+30
-0
30 additions, 0 deletions
src/cal_tools/tools.py
with
30 additions
and
0 deletions
src/cal_tools/tools.py
View file @
9e1f2068
...
@@ -4,6 +4,7 @@ import os
...
@@ -4,6 +4,7 @@ import os
import
re
import
re
import
zlib
import
zlib
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
fcntl
import
lockf
,
LOCK_EX
,
LOCK_UN
from
glob
import
glob
from
glob
import
glob
from
multiprocessing.pool
import
ThreadPool
from
multiprocessing.pool
import
ThreadPool
from
os
import
environ
,
listdir
,
path
from
os
import
environ
,
listdir
,
path
...
@@ -811,6 +812,35 @@ def module_index_to_qm(index: int, total_modules: int = 16):
...
@@ -811,6 +812,35 @@ def module_index_to_qm(index: int, total_modules: int = 16):
return
f
"
Q
{
quad
+
1
}
M
{
mod
+
1
}
"
return
f
"
Q
{
quad
+
1
}
M
{
mod
+
1
}
"
def
recursive_update
(
target
:
dict
,
source
:
dict
):
for
k
,
v2
in
source
.
items
():
v1
=
target
.
get
(
k
,
None
)
if
isinstance
(
v1
,
dict
)
and
isinstance
(
v2
,
dict
):
recursive_update
(
v1
,
v2
)
else
:
target
[
k
]
=
v2
def
update_metadata
(
folder
,
changes
:
dict
):
yaml_fn
=
Path
(
folder
)
/
"
calibration_metadata.yml
"
try
:
f
=
yaml_fn
.
open
(
'
x
'
)
except
FileExistsError
:
f
=
yaml_fn
.
open
(
'
r+
'
)
with
f
:
lockf
(
f
,
LOCK_EX
)
d
=
yaml
.
safe_load
(
f
)
if
d
is
None
:
d
=
{}
recursive_update
(
d
,
changes
)
f
.
seek
(
0
)
yaml
.
safe_dump
(
d
,
f
)
f
.
truncate
()
class
CalibrationMetadata
(
dict
):
class
CalibrationMetadata
(
dict
):
"""
Convenience class: dictionary stored in metadata YAML file
"""
Convenience class: dictionary stored in metadata YAML file
...
...
This diff is collapsed.
Click to expand it.