Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Merlijn Wajer
Python Derivermodule
Commits
3ecb6aa5
Commit
3ecb6aa5
authored
Jan 26, 2021
by
Merlijn Wajer
Browse files
metadata: add write_files_metadata
parent
82399981
Changes
1
Hide whitespace changes
Inline
Side-by-side
derivermodule/metadata.py
View file @
3ecb6aa5
...
...
@@ -6,12 +6,14 @@ from xml.dom import minidom
import
hashlib
,
zlib
from
json
import
dump
from
subprocess
import
check_output
from
collections
import
OrderedDict
import
xmltodict
from
.const
import
PB_ITEM
from
.const
import
PB_ITEM
,
PB_TASK
def
parse_item_metadata
(
path
):
...
...
@@ -116,6 +118,9 @@ def load_files_metadata(identifier):
modified) object. Use `lookup_file_metadata` to get a reference to the
metadata of a specific file.
There is no way to save changes made to this structure, so users have to
treat the result as read-only.
Args:
* identifier (``str``): Identifier of the item
...
...
@@ -130,6 +135,39 @@ def load_files_metadata(identifier):
return
xmltodict
.
parse
(
data
)
def
write_files_metadata
(
files_metadata
):
"""
Write additional metadata for a set of files.
This function cannot add metadata to arbitrary files, only to the target
file and any extra targets specified in
``derivermodule.task.write_extra_targets``. It also cannot delete metadata
values, nor does it have to: any files that are created by this module will
have no metadata associated with it, so there will be nothing to delete.
Metadata values can be of type ``str`` or ``list (of str)``.
Args:
* files_metadata: a dictionary where the key is a canonical item filename
(see ``derivermodule.files.canonical_item_filename``)
and the value is a key-value metadata pairs.
Returns:
* Nothing
Example:
>>> from derivermodule.files import canonical_item_filename
>>> md = {'foo_module_version': '0.0.1'}
>>> write_files_metadata({canonical_item_filename(target_file): md})
"""
files_metadata_file
=
join
(
PB_TASK
,
'extra_metadata.json'
)
fp
=
open
(
files_metadata_file
,
'w+'
)
dump
(
files_metadata
,
fp
)
fp
.
close
()
## TODO: Perform a *LOT* of testing on this
#def write_files_metadata(identifier, metadata):
# """
...
...
Write
Preview
Supports
Markdown
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