From 38cdc362a0dddcf4140b5b939c4e7650e7d4fa44 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 21 Sep 2021 14:21:40 -0700 Subject: [PATCH] Don't fail if we can't create startup file Fixes https://gitlab.com/kicad/code/kicad/issues/9205 --- scripting/kicad_pyshell/__init__.py | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripting/kicad_pyshell/__init__.py b/scripting/kicad_pyshell/__init__.py index 5b07f080a3..15fb60d3ae 100644 --- a/scripting/kicad_pyshell/__init__.py +++ b/scripting/kicad_pyshell/__init__.py @@ -49,21 +49,24 @@ class KiCadPyShell(KiCadEditorNotebookFrame): # Check if startup script exists if not os.path.isfile(self.startup_file): - # Not, so create a default. - default_startup = open(self.startup_file, 'w') - # provide the content for the default startup file. - default_startup.write( - "### DEFAULT STARTUP FILE FOR KiCad Python Shell\n" + - "# Enter any Python code you would like to execute when" + - " the PCBNEW python shell first runs.\n" + - "\n" + - "# For example, uncomment the following lines to import the current board\n" + - "\n" + - "# import pcbnew\n" + - "# import eeschema\n" + - "# board = pcbnew.GetBoard()\n" + - "# sch = eeschema.GetSchematic()\n") - default_startup.close() + # Not, so try to create a default. + try: + default_startup = open(self.startup_file, 'w') + # provide the content for the default startup file. + default_startup.write( + "### DEFAULT STARTUP FILE FOR KiCad Python Shell\n" + + "# Enter any Python code you would like to execute when" + + " the PCBNEW python shell first runs.\n" + + "\n" + + "# For example, uncomment the following lines to import the current board\n" + + "\n" + + "# import pcbnew\n" + + "# import eeschema\n" + + "# board = pcbnew.GetBoard()\n" + + "# sch = eeschema.GetSchematic()\n") + default_startup.close() + except: + pass def _setup(self): """