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