remote.py as module

This commit is contained in:
DiG 2022-01-17 23:44:30 +01:00
parent 290dd598fd
commit 9f5d2acfd3
1 changed files with 17 additions and 12 deletions

View File

@ -177,14 +177,14 @@ def lookup_file( muid, format ):
_visited = [] _visited = []
def lookup_model( muid ): def lookup_model( muid, recurse = False ):
eprint( "> Lookup model: %s" % (muid) ) eprint( "> Lookup model: %s" % (muid) )
recursive = False # recursive = False
if ( 'recursive' in OPTS and OPTS['recursive'] ): # or ( 'format' in OPTS and 'json' in OPTS['format'] ): # if ( 'recursive' in OPTS and OPTS['recursive'] ): # or ( 'format' in OPTS and 'json' in OPTS['format'] ):
recursive = OPTS['recursive'] # recursive = OPTS['recursive']
if type(recursive) == str: if type(recurse) == str:
recursive = recursive.split(',') recurse = recurse.split(',')
eprint( "> Recursive: %s %s" % (recursive, type(recursive)) ) eprint( "> Recursive: %s %s" % (recurse, type(recurse)) )
_tree = {} _tree = {}
# _ctree = _tree # _ctree = _tree
@ -233,7 +233,7 @@ def lookup_model( muid ):
# if field.ttype == 'many2many': # if field.ttype == 'many2many':
# if field.ttype == 'reference': # if field.ttype == 'reference':
if recursive == True or field.relation in recursive: if recurse == True or field.relation in recurse:
_tree[muid][field.name] = [ lookup_model( id ) for id in _tree[muid][field.name] ] _tree[muid][field.name] = [ lookup_model( id ) for id in _tree[muid][field.name] ]
@ -242,7 +242,7 @@ def lookup_model( muid ):
return _tree return _tree
def lookup( model, domains ): def lookup( model, domains, recurse = False ):
eprint( "> Lookup many: %s %s" % (model,domains) ) eprint( "> Lookup many: %s %s" % (model,domains) )
if model in MODEL_IGNORE: if model in MODEL_IGNORE:
eprint( 'IGNORED' ) eprint( 'IGNORED' )
@ -254,7 +254,7 @@ def lookup( model, domains ):
for inst in Model.browse( ids ): for inst in Model.browse( ids ):
tree = lookup_model( Muid(model, inst.id) ) tree = lookup_model( Muid(model, inst.id), recurse=recurse )
filename = json_path( model, inst.id ) filename = json_path( model, inst.id )
if filename in [item['file'] for item in stack]: if filename in [item['file'] for item in stack]:
continue continue
@ -490,11 +490,16 @@ if __name__ == "__main__":
#for inst in Field.browse( ids ): #for inst in Field.browse( ids ):
# render_tsv( 'ir.model.fields', inst ) # render_tsv( 'ir.model.fields', inst )
if 'lookup' in METHOD:
recurse = False
if ( 'recurse' in OPTS and OPTS['recurse'] ):
recurse = OPTS['recurse']
if METHOD == 'lookup': if METHOD == 'lookup':
jlog( lookup( MODEL, args2domains(PARAMS[2:]) ) ) jlog( lookup( MODEL, args2domains(PARAMS[2:]), recurse=recurse ) )
if METHOD == 'lookup-model': if METHOD == 'lookup-model':
jlog( lookup_model( Muid(MODEL,PARAMS[2]) ) ) jlog( lookup_model( Muid(MODEL,PARAMS[2]), recurse=recurse ) )
# if METHOD == 'lookup-recs': # if METHOD == 'lookup-recs':
# jlog( lookup_recs( MODEL, args2domains(PARAMS[2:]) ) ) # jlog( lookup_recs( MODEL, args2domains(PARAMS[2:]) ) )