Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Manifest Ingestion DAG
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
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
Service Desk
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
Data Flow
Data Ingestion
Manifest Ingestion DAG
Commits
e9d48875
Commit
e9d48875
authored
4 years ago
by
Yan Sushchynski (EPAM)
Browse files
Options
Downloads
Patches
Plain Diff
GONRG-1183: Add script to replace invalid values in schemas
parent
f2a67962
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
R3 Data Ingestion
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/convert_R2_schemas_to_R3.py
+81
-0
81 additions, 0 deletions
scripts/convert_R2_schemas_to_R3.py
with
81 additions
and
0 deletions
scripts/convert_R2_schemas_to_R3.py
0 → 100644
+
81
−
0
View file @
e9d48875
import
glob
import
json
import
os
import
re
from
collections
import
UserString
TENANT
=
"
opendes
"
AUTHORITY
=
"
osdu
"
SCHEMAS_DIR
=
os
.
environ
[
"
SCHEMAS_DIR
"
]
class
JsonString
(
UserString
):
REF_REGEXP
=
r
"
(?P<abstract_perfix>\.\.\/abstract/)(?P<kind_name>\w+)\.(?P<version>\d+\.\d+\.\d+)\.json
"
NAMESPACE_REGEXP
=
r
"
\<namespace\>
"
def
repl_closure
(
self
,
match
:
re
.
match
):
if
not
match
.
groups
:
print
(
self
.
data
)
raise
Exception
kind_name
=
match
.
group
(
'
kind_name
'
)
version
=
match
.
group
(
'
version
'
)
repl
=
f
"
{
TENANT
}
:
{
AUTHORITY
}
:
{
kind_name
}
:
{
version
}
"
return
repl
def
replace_refs
(
self
):
self
.
data
=
re
.
sub
(
self
.
REF_REGEXP
,
self
.
repl_closure
,
self
.
data
)
return
self
def
replace_namespaces
(
self
):
self
.
data
=
re
.
sub
(
self
.
NAMESPACE_REGEXP
,
TENANT
,
self
.
data
)
return
self
@staticmethod
def
lower_first_letter
(
val
:
str
):
if
val
[
0
].
islower
():
pass
elif
val
in
(
"
ACL
"
,
"
Legals
"
,
"
ID
"
):
val
=
val
.
lower
()
else
:
val
=
val
.
replace
(
val
[
0
],
val
[
0
].
lower
(),
1
)
return
val
def
to_pascal_case
(
self
):
tmp_properties
=
{}
tmp_required
=
[]
json_file_dict
=
json
.
loads
(
self
.
data
)
try
:
if
"
schemaInfo
"
in
json_file_dict
:
# if schema has additional fields to be recorded
content
=
json_file_dict
[
"
schema
"
]
else
:
content
=
json_file_dict
if
"
properties
"
in
content
:
for
key
,
value
in
content
[
"
properties
"
].
items
():
tmp_properties
[
self
.
lower_first_letter
(
key
)]
=
value
content
[
"
properties
"
]
=
tmp_properties
if
"
required
"
in
content
:
for
i
in
content
[
"
required
"
]:
tmp_required
.
append
(
self
.
lower_first_letter
(
i
))
content
[
"
required
"
]
=
tmp_required
self
.
data
=
json
.
dumps
(
json_file_dict
,
indent
=
4
)
return
self
except
Exception
as
e
:
print
(
self
.
data
)
raise
e
for
file_path
in
glob
.
glob
(
SCHEMAS_DIR
+
"
/*.json
"
):
try
:
with
open
(
file_path
,
"
r
"
)
as
file
:
content
=
file
.
read
()
content
=
JsonString
(
content
).
replace_refs
().
replace_namespaces
().
to_pascal_case
().
data
with
open
(
file_path
,
"
w
"
)
as
file
:
file
.
write
(
content
)
except
Exception
as
e
:
print
(
f
"
Error on file
{
file_path
}
"
)
raise
e
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