EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESA
PRISM
VS
Commits
4279081c
Commit
4279081c
authored
4 years ago
by
Fabian Schindler
Browse files
Options
Downloads
Patches
Plain Diff
Improving registrar: type and level in one step
parent
64703d4b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/registrar.py
+32
-15
32 additions, 15 deletions
core/registrar.py
with
32 additions
and
15 deletions
core/registrar.py
+
32
−
15
View file @
4279081c
...
...
@@ -52,6 +52,7 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pvs_instance.settings")
django
.
setup
()
from
eoxserver.backends
import
access
from
eoxserver.backends
import
models
as
backends
from
eoxserver.resources.coverages
import
models
from
eoxserver.resources.coverages.registration.product
import
(
ProductRegistrator
...
...
@@ -104,26 +105,39 @@ def add_mask(product):
)
def
get_product_level
(
product
):
def
get_product_type_and_level
(
metadata_item
):
with
access
.
vsi_open
(
metadata_item
)
as
f
:
tree
=
lxml
.
etree
.
parse
(
f
)
root
=
tree
.
getroot
()
try
:
metadata_item
=
product
.
metadata_items
.
all
()[
0
]
with
access
.
vsi_open
(
metadata_item
)
as
f
:
tree
=
lxml
.
etree
.
parse
(
f
)
root
=
tree
.
getroot
()
xp
=
'
/gsc:report/gsc:opt_metadata/gml:metaDataProperty/gsc:EarthObservationMetaData/eop:parentIdentifier/text()
'
xp
=
'
//gml:using/eop:EarthObservationEquipment/eop:platform/eop:Platform/eop:shortName/text()
'
product_type_name
=
tree
.
xpath
(
xp
,
namespaces
=
root
.
nsmap
)[
0
]
if
product_type_name
.
endswith
(
'
Level_1
'
):
return
'
Level_1
'
if
product_type_name
.
endswith
(
'
Level_3
'
):
return
'
Level_3
'
except
Exception
as
e
:
logger
.
warning
(
'
Failed to determine product type of %s, error was %s
'
%
(
metadata_item
.
location
,
e
)
)
try
:
xp
=
'
//gml:metaDataProperty/gsc:EarthObservationMetaData/eop:parentIdentifier/text()
'
parent_identifier
=
tree
.
xpath
(
xp
,
namespaces
=
root
.
nsmap
)[
0
]
print
(
"
parent identifier --->
"
,
parent_identifier
)
if
parent_identifier
.
endswith
(
'
Level_1
'
):
level
=
'
Level_1
'
if
parent_identifier
.
endswith
(
'
Level_3
'
):
level
=
'
Level_3
'
else
:
raise
Exception
(
'
Invalid p
roduct
type name %s
'
%
p
roduct_type_name
)
raise
Exception
(
'
Invalid p
arent identifier
type name %s
'
%
p
arent_identifier
)
except
Exception
as
e
:
logger
.
warning
(
'
Failed to determine product level f
or product
%s, error was %s
'
%
(
product
.
identifier
,
e
)
'
Failed to determine product level
o
f %s, error was %s
'
%
(
metadata_item
.
location
,
e
)
)
return
product_type_name
,
level
class
RegistrationError
(
Exception
):
pass
...
...
@@ -172,7 +186,10 @@ def registrar(
%
objects_prefix
)
product_type
=
data_package
.
split
(
"
/
"
)[
2
]
storage
=
backends
.
Storage
.
objects
.
get
(
name
=
upload_container
)
metadata_item
=
models
.
MetaDataItem
(
storage
=
storage
,
location
=
metadata_package
)
product_type
,
level
=
get_product_type_and_level
(
metadata_item
)
product
,
replaced
=
ProductRegistrator
().
register
(
metadata_locations
=
[[
upload_container
,
...
...
@@ -184,12 +201,12 @@ def registrar(
package_path
=
None
,
overrides
=
{},
)
collection
=
models
.
Collection
.
objects
.
get
(
identifier
=
collection
)
models
.
collection_insert_eo_object
(
collection
,
product
)
level
=
get_product_level
(
product
)
if
level
==
'
Level_1
'
:
collection_level_1
=
models
.
Collection
.
objects
.
get
(
identifier
=
"
%s_Level_1
"
%
collection
...
...
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