Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
f2b2af6d
Verified
Commit
f2b2af6d
authored
7 years ago
by
Benjamin Regler
Browse files
Options
Downloads
Patches
Plain Diff
Added missing docstrings, file version, and fixed bug in `nomad_query.username()`
parent
b5c109dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/nomad_query.py
+24
-6
24 additions, 6 deletions
common/python/nomadcore/nomad_query.py
with
24 additions
and
6 deletions
common/python/nomadcore/nomad_query.py
+
24
−
6
View file @
f2b2af6d
...
...
@@ -45,16 +45,23 @@ class NomadQueryResult(object):
@author Benjamin Regler
"""
def
__init__
(
self
,
query
,
response
):
def
__init__
(
self
,
query
,
response
,
version
=
1.0
):
"""
Constructor.
Arguments:
query {dict} -- Query information, i.e., query filter, context,
group_by, endpoint, and URL
response {dict} -- Response of the Nomad Query API
Keyword Arguments:
version {number} -- Version of the Nomad Query data file
(default: {1.0})
"""
self
.
_uri
=
[]
self
.
_query
=
query
or
{}
self
.
_timestamp
=
int
(
time
.
time
())
self
.
_response
=
response
.
get
(
'
result
'
,
{})
self
.
_version
=
version
# Construct download path
path
=
response
.
get
(
'
path
'
,
''
)
...
...
@@ -67,7 +74,6 @@ class NomadQueryResult(object):
regex
=
re
.
compile
(
r
'
(?<=/[a-zA-Z0-9\-_]{3}/)[^\.]+
'
)
paths
=
response
[
'
data
'
].
get
(
'
result
'
,
[])
uri
=
[]
for
path
in
paths
:
match
=
regex
.
search
(
path
)
if
match
:
...
...
@@ -80,6 +86,14 @@ class NomadQueryResult(object):
self
.
_uri
.
append
(
'
nmd://
'
+
'
/
'
.
join
(
groups
))
def
version
(
self
):
"""
Get the version of the Nomad Query data file.
Returns:
float -- Version of the Nomad Query data file
"""
return
self
.
_version
def
timestamp
(
self
):
"""
Get the timestamp of the query.
...
...
@@ -127,6 +141,9 @@ class NomadQuery(object):
@author Benjamin Regler
"""
# Version of the Nomad Query API
__version__
=
1.0
# Nomad API endpoint
endpoint
=
'
https://analytics-toolkit.nomad-coe.eu/api/
'
...
...
@@ -168,7 +185,7 @@ class NomadQuery(object):
"""
if
username
:
self
.
_username
=
str
(
username
)
self
.
_base_path
=
os
.
path
.
join
(
self
.
user_path
,
self
.
username
,
self
.
_base_path
=
os
.
path
.
join
(
self
.
user_path
,
self
.
_
username
,
'
nomad-query
'
)
return
self
.
_username
...
...
@@ -359,7 +376,7 @@ class NomadQuery(object):
'
group_by
'
:
group_by
.
strip
().
lower
(),
'
url
'
:
url
}
return
NomadQueryResult
(
query
,
response
)
return
NomadQueryResult
(
query
,
response
,
self
.
__version__
)
def
fetch
(
self
,
name_or_index
=
''
,
resolve
=
False
,
**
params
):
"""
Fetch stored query.
...
...
@@ -466,6 +483,7 @@ class NomadQuery(object):
data
=
{
'
filename
'
:
filename
,
'
version
'
:
self
.
__version__
,
'
query
'
:
query
.
query
(),
'
timestamp
'
:
timestamp
,
'
uri
'
:
query
.
uri
()
...
...
@@ -559,7 +577,7 @@ class NomadQuery(object):
"""
try
:
os
.
makedirs
(
path
)
except
OSError
as
exc
:
# Python >2.5
except
OSError
as
exc
:
# Python >
2.5
if
exc
.
errno
!=
errno
.
EEXIST
or
not
os
.
path
.
isdir
(
path
):
return
False
return
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment