|
|
@ -25,6 +25,9 @@ from itertools import islice
|
|
|
|
from multiprocessing import Process
|
|
|
|
from multiprocessing import Process
|
|
|
|
import transport
|
|
|
|
import transport
|
|
|
|
import jsonmerge
|
|
|
|
import jsonmerge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import copy
|
|
|
|
|
|
|
|
|
|
|
|
class void :
|
|
|
|
class void :
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
class Formatters :
|
|
|
|
class Formatters :
|
|
|
@ -86,12 +89,17 @@ class Formatters :
|
|
|
|
_row = list(row) if type(row[0]) == str else list(row[0])
|
|
|
|
_row = list(row) if type(row[0]) == str else list(row[0])
|
|
|
|
|
|
|
|
|
|
|
|
_info = config[_row[0]] if _row[0] in config else {}
|
|
|
|
_info = config[_row[0]] if _row[0] in config else {}
|
|
|
|
|
|
|
|
_rinfo = {}
|
|
|
|
key = None
|
|
|
|
key = None
|
|
|
|
if '@ref' in _info:
|
|
|
|
if '@ref' in _info:
|
|
|
|
key = list(set(_row) & set(_info['@ref'].keys()))
|
|
|
|
keys = list(set(_row) & set(_info['@ref'].keys()))
|
|
|
|
if key :
|
|
|
|
if keys :
|
|
|
|
key = key[0]
|
|
|
|
_rinfo = {}
|
|
|
|
return _info['@ref'][key]
|
|
|
|
for key in keys :
|
|
|
|
|
|
|
|
_rinfo = jsonmerge.merge(_rinfo,_info['@ref'][key])
|
|
|
|
|
|
|
|
return _rinfo
|
|
|
|
|
|
|
|
# key = key[0]
|
|
|
|
|
|
|
|
# return _info['@ref'][key]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return {}
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
@ -315,11 +323,11 @@ class Parser (Process):
|
|
|
|
|
|
|
|
|
|
|
|
if type(value) == dict :
|
|
|
|
if type(value) == dict :
|
|
|
|
|
|
|
|
|
|
|
|
object_value = dict(object_value, **value)
|
|
|
|
# object_value = dict(object_value, **value)
|
|
|
|
|
|
|
|
object_value = jsonmerge.merge(object_value, value)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object_value[key] = value
|
|
|
|
object_value[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -360,9 +368,6 @@ class Parser (Process):
|
|
|
|
_cinfo = util.get.config(self._custom_config[_code],row)
|
|
|
|
_cinfo = util.get.config(self._custom_config[_code],row)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
_cinfo = {}
|
|
|
|
_cinfo = {}
|
|
|
|
if 'SV3' in row :
|
|
|
|
|
|
|
|
print (row)
|
|
|
|
|
|
|
|
print (_info)
|
|
|
|
|
|
|
|
if _info or _cinfo:
|
|
|
|
if _info or _cinfo:
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -370,10 +375,13 @@ class Parser (Process):
|
|
|
|
|
|
|
|
|
|
|
|
_info = jsonmerge.merge(_info,_cinfo)
|
|
|
|
_info = jsonmerge.merge(_info,_cinfo)
|
|
|
|
tmp = self.get.value(row,_info)
|
|
|
|
tmp = self.get.value(row,_info)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# let's prune the objects not found
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not tmp :
|
|
|
|
if not tmp :
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
if 'label' in _info :
|
|
|
|
if 'label' in _info :
|
|
|
|
label = _info['label']
|
|
|
|
label = _info['label']
|
|
|
|
|
|
|
|
|
|
|
@ -398,10 +406,10 @@ class Parser (Process):
|
|
|
|
|
|
|
|
|
|
|
|
name = _info['field']
|
|
|
|
name = _info['field']
|
|
|
|
# value[name] = tmp
|
|
|
|
# value[name] = tmp
|
|
|
|
value = jsonmerge.merge(value,{name:tmp})
|
|
|
|
# value = jsonmerge.merge(value,{name:tmp})
|
|
|
|
|
|
|
|
value = dict(value,**{name:tmp})
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
value = dict(value,**tmp)
|
|
|
|
value = dict(value,**tmp)
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -434,8 +442,9 @@ class Parser (Process):
|
|
|
|
value["submitted"] = SUBMITTED_DATE
|
|
|
|
value["submitted"] = SUBMITTED_DATE
|
|
|
|
value['sender_id'] = SENDER_ID
|
|
|
|
value['sender_id'] = SENDER_ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = dict(value,**self.apply(content,_code))
|
|
|
|
# Let's parse this for default values
|
|
|
|
# Let's parse this for default values
|
|
|
|
return jsonmerge.merge(value,self.apply(content,_code))
|
|
|
|
return value #jsonmerge.merge(value,self.apply(content,_code))
|
|
|
|
|
|
|
|
|
|
|
|
def read(self,filename) :
|
|
|
|
def read(self,filename) :
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -449,7 +458,7 @@ class Parser (Process):
|
|
|
|
logs = []
|
|
|
|
logs = []
|
|
|
|
claims = []
|
|
|
|
claims = []
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
file = open(filename.strip(),errors='ignore')
|
|
|
|
file = open(filename.strip())
|
|
|
|
file = file.read().split('CLP')
|
|
|
|
file = file.read().split('CLP')
|
|
|
|
_code = '835'
|
|
|
|
_code = '835'
|
|
|
|
section = 'CLP'
|
|
|
|
section = 'CLP'
|
|
|
@ -473,6 +482,7 @@ class Parser (Process):
|
|
|
|
DEFAULT_VALUE = self.get.default_value(INITIAL_ROWS,_code)
|
|
|
|
DEFAULT_VALUE = self.get.default_value(INITIAL_ROWS,_code)
|
|
|
|
DEFAULT_VALUE['name'] = filename.strip()
|
|
|
|
DEFAULT_VALUE['name'] = filename.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = section.join(file).split('\n')
|
|
|
|
file = section.join(file).split('\n')
|
|
|
|
if len(file) == 1:
|
|
|
|
if len(file) == 1:
|
|
|
|
|
|
|
|
|
|
|
@ -525,9 +535,11 @@ class Parser (Process):
|
|
|
|
schema = {"properties":{}}
|
|
|
|
schema = {"properties":{}}
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
merger = jsonmerge.Merger(schema)
|
|
|
|
merger = jsonmerge.Merger(schema)
|
|
|
|
_baseclaim = None
|
|
|
|
_baseclaim = None
|
|
|
|
_baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
|
|
|
|
_baseclaim = merger.merge(_baseclaim,copy.deepcopy(DEFAULT_VALUE))
|
|
|
|
_claim = merger.merge(_baseclaim,_claim)
|
|
|
|
_claim = merger.merge(_baseclaim,_claim)
|
|
|
|
|
|
|
|
|
|
|
|
# _claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
|
|
|
|
# _claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
|
|
|
@ -566,8 +578,9 @@ class Parser (Process):
|
|
|
|
schema = {"properties":{}}
|
|
|
|
schema = {"properties":{}}
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
for attr in _claim.keys() :
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
|
|
|
|
|
|
|
|
|
|
|
|
_baseclaim = None
|
|
|
|
_baseclaim = None
|
|
|
|
_baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
|
|
|
|
_baseclaim = merger.merge(_baseclaim,copy.deepcopy(DEFAULT_VALUE))
|
|
|
|
claim = merger.merge(_baseclaim,claim)
|
|
|
|
claim = merger.merge(_baseclaim,claim)
|
|
|
|
claims.append(claim)
|
|
|
|
claims.append(claim)
|
|
|
|
|
|
|
|
|
|
|
|