From 3a8cc00ae6daf92e960805b857c847e8144c8c3b Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 2 Apr 2024 12:56:53 -0300 Subject: [PATCH] Avoid messing with config file when using Python/CLI - Saves time and problems - Could be a workaround for Windows issues (INTI-CMNB/KiBot#599) --- src/eeschema_do | 36 ++++++++++++++++++++---------------- src/pcbnew_do | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/eeschema_do b/src/eeschema_do index b52e731..921ab4e 100755 --- a/src/eeschema_do +++ b/src/eeschema_do @@ -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') @@ -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) # @@ -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) diff --git a/src/pcbnew_do b/src/pcbnew_do index 069329d..a7a70f3 100755 --- a/src/pcbnew_do +++ b/src/pcbnew_do @@ -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') @@ -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 @@ -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