From 9e009e58b70d1aec572840b80234590eb1ab8adb Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 6 Mar 2018 18:48:54 -0800 Subject: [PATCH] Wrap get.py's "if __name__ == '__main__':" into a function so it can be externally called Adding the Arduino repo as a git submodule can be very useful for version control. However, `git submodule update` is not enough, as the tools need to be downloaded through `get.py`. Wrapping the main code in that script into its own function allows an external Python script to import the module and execute its functionality without relying on the unsafe `execfile` (or `Popen`). The main advantage would be easy flow control in case of error (eg: issue #4464). --- tools/get.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/get.py b/tools/get.py index c9750ae03d..b76d8fca9f 100755 --- a/tools/get.py +++ b/tools/get.py @@ -108,9 +108,12 @@ def identify_platform(): sys_name = 'Windows' return arduino_platform_names[sys_name][bits] -if __name__ == '__main__': +def main(): print('Platform: {0}'.format(identify_platform())) tools_to_download = load_tools_list('../package/package_esp8266com_index.template.json', identify_platform()) mkdir_p(dist_dir) for tool in tools_to_download: get_tool(tool) + +if __name__ == '__main__': + main()