Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
brivas
mdf_reader
Commits
6f485e2f
Commit
6f485e2f
authored
5 years ago
by
iregon
Browse files
Options
Download
Email Patches
Plain Diff
Added path validation
parent
b7c637b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
read.py
read.py
+18
-8
No files found.
read.py
View file @
6f485e2f
...
...
@@ -9,8 +9,10 @@ a named model (included in the module) or as the path to a valid data model.
Data is validated against its data model after reading, producing a boolean mask.
Calls the schemas, reader and valiate modules in the tool to access the data models,
read the data and validate it.
Uses submodules:
- schemas
- reader
- valiate
@author: iregon
"""
...
...
@@ -83,13 +85,19 @@ def ERV(TextParser,read_sections_list, schema, code_tables_path):
return
data
,
valid
def
validate_arg
(
arg_name
,
arg_value
,
arg_type
):
if
arg_value
and
not
isinstance
(
arg_value
,
arg_type
):
logging
.
error
(
'Argument {0} must be {1}, input type is {2}'
.
format
(
arg_name
,
arg_type
,
type
(
arg_value
)))
return
False
else
:
return
True
def
validate_path
(
arg_name
,
arg_value
):
if
arg_value
and
not
os
.
path
.
isdir
(
arg_value
):
logging
.
error
(
'{0} could not find path {1}'
.
format
(
arg_name
,
arg_value
))
return
False
else
:
return
True
def
read
(
source
,
data_model
=
None
,
data_model_path
=
None
,
sections
=
None
,
chunksize
=
None
,
skiprows
=
None
,
out_path
=
None
):
...
...
@@ -114,9 +122,15 @@ def read(source, data_model = None, data_model_path = None, sections = None,chun
return
if
not
validate_arg
(
'skiprows'
,
skiprows
,
int
):
return
if
not
validate_path
(
'data_model_path'
,
data_model_path
):
return
if
not
validate_path
(
'out_path'
,
out_path
):
return
# 1. Read data model
# Schema reader will return None if schema does not validate
# Schema reader will return empty if cannot read schema or is not valid
# and will log the corresponding error
# multiple_reports_per_line error also while reading schema
logging
.
info
(
"READING DATA MODEL SCHEMA FILE..."
)
schema
=
schemas
.
read_schema
(
schema_name
=
data_model
,
ext_schema_path
=
data_model_path
)
if
not
schema
:
...
...
@@ -127,10 +141,6 @@ def read(source, data_model = None, data_model_path = None, sections = None,chun
model_path
=
data_model_path
code_tables_path
=
os
.
path
.
join
(
model_path
,
'code_tables'
)
# For future use: some work already done in schema reading
if
schema
[
'header'
].
get
(
'multiple_reports_per_line'
):
logging
.
error
(
'File format not yet supported'
)
sys
.
exit
(
1
)
# 2. Read and validate data
imodel
=
data_model
if
data_model
else
data_model_path
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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