Skip to content

Commit

Permalink
Avoid messing with config file when using Python/CLI
Browse files Browse the repository at this point in the history
- Saves time and problems
- Could be a workaround for Windows issues (INTI-CMNB/KiBot#599)
  • Loading branch information
set-soft committed Apr 2, 2024
1 parent e22acbb commit 3a8cc00
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
36 changes: 20 additions & 16 deletions src/eeschema_do
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,25 @@ def can_be_done_using_cli(command, cfg):
return False


def setup_config_files(cfg):
# Ensure we have a config dir
check_kicad_config_dir(cfg)
# Back-up the current eeschema configuration
cfg.conf_eeschema_bkp = backup_config('Eeschema', cfg.conf_eeschema, EESCHEMA_CFG_PRESENT, cfg)
# Create a suitable configuration
create_eeschema_config(cfg)
# Back-up the current kicad_common configuration
cfg.conf_kicad_bkp = backup_config('KiCad common', cfg.conf_kicad, KICAD_CFG_PRESENT, cfg)
# Create a suitable configuration
create_kicad_config(cfg)
if cfg.kicad_version >= KICAD_VERSION_5_99:
# KiCad 6 breaks menu short-cuts, but we can configure user hotkeys
# Back-up the current user.hotkeys configuration
cfg.conf_hotkeys_bkp = backup_config('User hotkeys', cfg.conf_hotkeys, USER_HOTKEYS_PRESENT, cfg)
# Create a suitable configuration
create_user_hotkeys(cfg)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='KiCad schematic automation')
subparsers = parser.add_subparsers(help='Command:', dest='command')
Expand Down Expand Up @@ -961,22 +980,6 @@ if __name__ == '__main__':
#
# Force english + UTF-8
os.environ['LANG'] = get_en_locale(logger)
# Ensure we have a config dir
check_kicad_config_dir(cfg)
# Back-up the current eeschema configuration
cfg.conf_eeschema_bkp = backup_config('Eeschema', cfg.conf_eeschema, EESCHEMA_CFG_PRESENT, cfg)
# Create a suitable configuration
create_eeschema_config(cfg)
# Back-up the current kicad_common configuration
cfg.conf_kicad_bkp = backup_config('KiCad common', cfg.conf_kicad, KICAD_CFG_PRESENT, cfg)
# Create a suitable configuration
create_kicad_config(cfg)
if cfg.kicad_version >= KICAD_VERSION_5_99:
# KiCad 6 breaks menu short-cuts, but we can configure user hotkeys
# Back-up the current user.hotkeys configuration
cfg.conf_hotkeys_bkp = backup_config('User hotkeys', cfg.conf_hotkeys, USER_HOTKEYS_PRESENT, cfg)
# Create a suitable configuration
create_user_hotkeys(cfg)
# Make sure the user has sym-lib-table
check_lib_table(cfg.user_sym_lib_table, cfg.sys_sym_lib_table)
#
Expand Down Expand Up @@ -1026,6 +1029,7 @@ if __name__ == '__main__':
do_retry = False
cfg.use_interposer = cfg.enable_interposer = False
else:
setup_config_files(cfg)
# Interposer settings
check_interposer(args, logger, cfg)
flog_out, flog_err, cfg.flog_int = get_log_files(output_dir, 'eeschema', also_interposer=cfg.enable_interposer)
Expand Down
44 changes: 24 additions & 20 deletions src/pcbnew_do
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,29 @@ def wait_pcbnew_start_by_msg(cfg):
return wait_pcbnew()


def setup_config_files(cfg):
# Back-up the current pcbnew configuration
check_kicad_config_dir(cfg)
cfg.conf_pcbnew_bkp = backup_config('PCBnew', cfg.conf_pcbnew, PCBNEW_CFG_PRESENT, cfg)
if cfg.conf_colors:
cfg.conf_colors_bkp = backup_config('Colors', cfg.conf_colors, PCBNEW_CFG_PRESENT, cfg)
if cfg.conf_3dview:
cfg.conf_3dview_bkp = backup_config('3D Viewer', cfg.conf_3dview, PCBNEW_CFG_PRESENT, cfg)
# Create a suitable configuration
create_pcbnew_config(cfg)
# Hotkeys
if not cfg.ki5:
# KiCad 6 breaks menu short-cuts, but we can configure user hotkeys
# Back-up the current user.hotkeys configuration
cfg.conf_hotkeys_bkp = backup_config('User hotkeys', cfg.conf_hotkeys, USER_HOTKEYS_PRESENT, cfg)
# Create a suitable configuration
create_user_hotkeys(cfg)
# Back-up the current kicad_common configuration
cfg.conf_kicad_bkp = backup_config('KiCad common', cfg.conf_kicad, KICAD_CFG_PRESENT, cfg)
# Create a suitable configuration
create_kicad_config(cfg)


if __name__ == '__main__': # noqa: C901
parser = argparse.ArgumentParser(description='KiCad PCB automation')
subparsers = parser.add_subparsers(help='Command:', dest='command')
Expand Down Expand Up @@ -1719,26 +1742,6 @@ if __name__ == '__main__': # noqa: C901
load_filters(cfg, args.errors_filter[0])

memorize_project(cfg)
# Back-up the current pcbnew configuration
check_kicad_config_dir(cfg)
cfg.conf_pcbnew_bkp = backup_config('PCBnew', cfg.conf_pcbnew, PCBNEW_CFG_PRESENT, cfg)
if cfg.conf_colors:
cfg.conf_colors_bkp = backup_config('Colors', cfg.conf_colors, PCBNEW_CFG_PRESENT, cfg)
if cfg.conf_3dview:
cfg.conf_3dview_bkp = backup_config('3D Viewer', cfg.conf_3dview, PCBNEW_CFG_PRESENT, cfg)
# Create a suitable configuration
create_pcbnew_config(cfg)
# Hotkeys
if not cfg.ki5:
# KiCad 6 breaks menu short-cuts, but we can configure user hotkeys
# Back-up the current user.hotkeys configuration
cfg.conf_hotkeys_bkp = backup_config('User hotkeys', cfg.conf_hotkeys, USER_HOTKEYS_PRESENT, cfg)
# Create a suitable configuration
create_user_hotkeys(cfg)
# Back-up the current kicad_common configuration
cfg.conf_kicad_bkp = backup_config('KiCad common', cfg.conf_kicad, KICAD_CFG_PRESENT, cfg)
# Create a suitable configuration
create_kicad_config(cfg)
# Make sure the user has fp-lib-table
check_lib_table(cfg.user_fp_lib_table, cfg.sys_fp_lib_table)
# Create output dir, compute full name for output file and remove it
Expand Down Expand Up @@ -1767,6 +1770,7 @@ if __name__ == '__main__': # noqa: C901
do_retry = False
cfg.use_interposer = cfg.enable_interposer = False
else:
setup_config_files(cfg)
# Interposer settings
check_interposer(args, logger, cfg)
# When using the interposer inform the output file name using the environment
Expand Down

0 comments on commit 3a8cc00

Please sign in to comment.