Move gadget config file writing too

This commit is contained in:
Ben Jackson 2020-05-27 21:47:17 +01:00
commit f945dbcfdd
2 changed files with 36 additions and 20 deletions

View file

@ -163,19 +163,8 @@ for custom_file_name in functools.reduce( operator.add,
failed = [] failed = []
if args.update_gadget_config: all_adapters = installer.ReadAdapters(
with open( install.GetGadgetConfigFile( vimspector_base ), 'r' ) as f: read_existing = args.update_gadget_config )
all_adapters = json.load( f ).get( 'adapters', {} )
else:
all_adapters = {}
# Include "built-in" adapter for multi-session mode
all_adapters.update( {
'multi-session': {
'port': '${port}',
'host': '${host}'
},
} )
for name, gadget in gadgets.GADGETS.items(): for name, gadget in gadgets.GADGETS.items():
if not gadget.get( 'enabled', True ): if not gadget.get( 'enabled', True ):
@ -197,17 +186,12 @@ for name, gadget in gadgets.GADGETS.items():
for name, gadget in CUSTOM_GADGETS.items(): for name, gadget in CUSTOM_GADGETS.items():
installer.InstallGagdet( name, gadget, failed, all_adapters ) installer.InstallGagdet( name, gadget, failed, all_adapters )
adapter_config = json.dumps ( { 'adapters': all_adapters },
indent=2,
sort_keys=True )
if args.no_gadget_config: if args.no_gadget_config:
print( "" ) print( "" )
print( "Would write the following gadgets: " ) print( "Would write the following gadgets: " )
print( adapter_config ) installer.WriteAdapters( all_adapters, to_file = sys.stdout )
else: else:
with open( install.GetGadgetConfigFile( vimspector_base ), 'w' ) as f: installer.WriteAdapters( all_adapters )
f.write( adapter_config )
if failed: if failed:
raise RuntimeError( 'Failed to install gadgets: {}'.format( raise RuntimeError( 'Failed to install gadgets: {}'.format(

View file

@ -211,6 +211,38 @@ def InstallGagdet( name, gadget, failed, all_adapters ):
print( "FAILED installing {}: {}".format( name, e ) ) print( "FAILED installing {}: {}".format( name, e ) )
def ReadAdapters( read_existing = True ):
if read_existing:
with open( install.GetGadgetConfigFile( options.vimspector_base ),
'r' ) as f:
all_adapters = json.load( f ).get( 'adapters', {} )
else:
all_adapters = {}
# Include "built-in" adapter for multi-session mode
all_adapters.update( {
'multi-session': {
'port': '${port}',
'host': '${host}'
},
} )
return all_adapters
def WriteAdapters( all_adapters, to_file=None ):
adapter_config = json.dumps ( { 'adapters': all_adapters },
indent=2,
sort_keys=True )
if to_file:
to_file.write( adapter_config )
else:
with open( install.GetGadgetConfigFile( options.vimspector_base ),
'w' ) as f:
f.write( adapter_config )
@contextlib.contextmanager @contextlib.contextmanager
def CurrentWorkingDir( d ): def CurrentWorkingDir( d ):
cur_d = os.getcwd() cur_d = os.getcwd()