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
nomad-lab
nomad-FAIR
Commits
a5bbbcc3
Commit
a5bbbcc3
authored
Jan 08, 2020
by
Markus Scheidgen
Browse files
Added CLI command to remove entries.
parent
94aef9c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
nomad/cli/admin/__init__.py
View file @
a5bbbcc3
...
...
@@ -13,4 +13,4 @@
# limitations under the License.
from
.
import
admin
,
uploads
,
run
,
clean
,
users
from
.
import
admin
,
uploads
,
entries
,
run
,
clean
,
users
nomad/cli/admin/entries.py
0 → 100644
View file @
a5bbbcc3
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
click
from
nomad
import
processing
as
proc
,
infrastructure
,
search
from
.admin
import
admin
@
admin
.
group
(
help
=
'Entry related commands'
)
def
entries
():
infrastructure
.
setup_mongo
()
infrastructure
.
setup_elastic
()
@
entries
.
command
(
help
=
'Delete selected entries from mongo and elastic'
)
@
click
.
argument
(
'ENTRIES'
,
nargs
=-
1
)
@
click
.
option
(
'--skip-es'
,
help
=
'Keep the elastic index version of the data.'
,
is_flag
=
True
)
@
click
.
option
(
'--skip-mongo'
,
help
=
'Keep uploads and calcs in mongo.'
,
is_flag
=
True
)
def
rm
(
entries
,
skip_es
,
skip_mongo
):
print
(
'%d entries selected, deleting ...'
%
len
(
entries
))
if
not
skip_es
:
for
entry
in
entries
:
search
.
delete_entry
(
calc_id
=
entry
)
if
not
skip_mongo
:
proc
.
Calc
.
objects
(
calc_id__in
=
entries
).
delete
()
nomad/search.py
View file @
a5bbbcc3
...
...
@@ -167,6 +167,12 @@ def delete_upload(upload_id):
Search
(
index
=
index
).
query
(
'match'
,
upload_id
=
upload_id
).
delete
()
def
delete_entry
(
calc_id
):
""" Delete the entry with the given ``calc_id`` from the index. """
index
=
Entry
.
_default_index
()
Search
(
index
=
index
).
query
(
'match'
,
calc_id
=
calc_id
).
delete
()
def
publish
(
calcs
:
Iterable
[
datamodel
.
CalcWithMetadata
])
->
None
:
""" Update all given calcs with their metadata and set ``publish = True``. """
def
elastic_updates
():
...
...
tests/test_cli.py
View file @
a5bbbcc3
...
...
@@ -79,6 +79,19 @@ class TestAdmin:
assert
search
.
SearchRequest
().
search_parameter
(
'comment'
,
'specific'
).
execute
()[
'total'
]
==
1
def
test_delete_entry
(
self
,
published
):
upload_id
=
published
.
upload_id
calc
=
Calc
.
objects
(
upload_id
=
upload_id
).
first
()
result
=
click
.
testing
.
CliRunner
().
invoke
(
cli
,
[
'admin'
,
'entries'
,
'rm'
,
calc
.
calc_id
],
catch_exceptions
=
False
,
obj
=
utils
.
POPO
())
print
(
result
.
output
)
assert
result
.
exit_code
==
0
assert
'deleting'
in
result
.
stdout
assert
Upload
.
objects
(
upload_id
=
upload_id
).
first
()
is
not
None
assert
Calc
.
objects
(
calc_id
=
calc
.
calc_id
).
first
()
is
None
@
pytest
.
mark
.
usefixtures
(
'reset_config'
,
'no_warn'
)
class
TestAdminUploads
:
...
...
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