Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Siputils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
Siputils
Commits
d0fb647c
Commit
d0fb647c
authored
Feb 9, 2017
by
Jörn Künsemöller
Browse files
Options
Downloads
Patches
Plain Diff
Task #9091 - Now functional ID service integration with Identifier constructor
parent
f5372072
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/query.py
+39
-33
39 additions, 33 deletions
lib/query.py
lib/siplib.py
+1
-2
1 addition, 2 deletions
lib/siplib.py
with
40 additions
and
35 deletions
lib/query.py
+
39
−
33
View file @
d0fb647c
...
...
@@ -12,6 +12,9 @@ import copy
path
=
expanduser
(
"
~/.siplibrc
"
)
user
=
None
passw
=
None
host
=
"
lta-ingest-test.lofar.eu:19443
"
#host = "lofar-ingest.target.rug.nl:9443"
with
open
(
path
,
'
r
'
)
as
file
:
print
"
Parsing user credentials from
"
,
path
for
line
in
file
:
...
...
@@ -19,50 +22,49 @@ with open(path,'r') as file:
user
=
line
.
split
(
'
=
'
)[
1
].
strip
()
if
line
.
startswith
(
"
password
"
):
passw
=
line
.
split
(
'
=
'
)[
1
].
strip
()
if
line
.
startswith
(
"
host
"
):
host
=
line
.
split
(
'
=
'
)[
1
].
strip
()
login_data
=
{
'
j_username
'
:
user
,
'
j_password
'
:
passw
}
url
=
'
https://
'
+
user
+
'
:
'
+
passw
+
'
@
lofar-ingest.target.rug.nl:9443/
'
url
=
'
https://
'
+
user
+
'
:
'
+
passw
+
'
@
'
+
host
client
=
xmlrpclib
.
ServerProxy
(
url
)
# todo: comment out this testing dict
id_cache
=
{}
# id_cache = {}
def
_call_idservice
(
source
,
userlabel
=
None
):
# todo: use this query to momqueryservice
# if userlabel is not None:
# response = client.getUniqueIDForLabel(source, label)
# response = client.getUniqueID(source)
# todo: comment out this mock of the service for testing:
if
userlabel
in
id_cache
:
print
"
using existing
"
,
userlabel
response
=
id_cache
.
get
(
userlabel
)
else
:
print
"
creating new
"
,
userlabel
response
=
{
"
version
"
:
"
version
"
,
"
result
"
:
"
ok
"
,
"
error_nr
"
:
0
,
"
error
"
:
""
,
"
id
"
:
uuid
.
uuid1
().
int
>>
64
,
"
user_label
"
:
userlabel
,
"
data_type
"
:
"
type
"
,
"
data_source
"
:
source
,
"
is_new
"
:
True
}
if
userlabel
is
not
None
:
print
"
keeping copy
"
,
userlabel
keeper
=
copy
.
deepcopy
(
response
)
keeper
[
"
is_new
"
]
=
False
id_cache
[
userlabel
]
=
keeper
response
=
client
.
GetUniqueIDForLabel
(
source
,
userlabel
)
else
:
response
=
client
.
GetUniqueID
(
source
)
return
response
# for testing:
# if userlabel in id_cache:
# print "using existing", userlabel
# response = id_cache.get(userlabel)
# else:
# print "creating new", userlabel
# response = {"version": "version",
# "result": "ok",
# "id": uuid.uuid1().int>>64,
# "user_label": userlabel,
# "data_type": "type",
# "identifier_source": source,
# "is_new": True,
# "error": ''}
# if userlabel is not None:
# print "keeping copy", userlabel
# keeper = copy.deepcopy(response)
# keeper["is_new"] = False
# id_cache[userlabel] = keeper
#
# return response
def
create_unique_id
(
source
,
userlabel
=
None
):
"""
...
...
@@ -71,9 +73,11 @@ def create_unique_id(source, userlabel=None):
Throws an exception if the given label already exists for the given source.
"""
response
=
_call_idservice
(
source
,
userlabel
)
if
not
response
.
get
(
"
result
"
)
==
"
ok
"
:
raise
Exception
(
'
An identifier for this userlabel could not be created ->
'
+
str
(
response
.
get
(
"
error
"
)))
if
not
response
.
get
(
"
is_new
"
):
raise
Exception
(
'
An identifier for this userlabel already exists ->
'
+
str
(
userlabel
))
return
response
return
response
.
get
(
'
id
'
)
def
get_unique_id
(
source
,
userlabel
):
...
...
@@ -83,9 +87,11 @@ def get_unique_id(source, userlabel):
Throws an exception if the given label does not exist for the given source.
"""
response
=
_call_idservice
(
source
,
userlabel
)
if
not
response
.
get
(
"
result
"
)
==
"
ok
"
:
raise
Exception
(
'
An identifier for this userlabel could not be retrieved ->
'
+
str
(
response
.
get
(
"
error
"
)))
if
response
.
get
(
"
is_new
"
):
raise
Exception
(
'
An identifier for this userlabel does not exist ->
'
+
str
(
userlabel
))
return
response
return
response
.
get
(
'
id
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/siplib.py
+
1
−
2
View file @
d0fb647c
...
...
@@ -89,10 +89,9 @@ class Identifier(object):
at the time the Identifier is created to allow this lookup to work).
Throws an exception if the given label does not exist for the given source.
"""
unique_id
=
query
.
get_unique_id
(
source
,
userlabel
)
identifier
=
Identifier
.
__new__
(
Identifier
)
identifier
.
_setpyxb_identifier
(
identifier
.
_set
_
pyxb_identifier
(
ltasip
.
IdentifierType
(
source
=
str
(
source
),
identifier
=
str
(
unique_id
),
...
...
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