Skip to content

Commit 9e009e5

Browse files
committed
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 esp8266#4464).
1 parent 7999f5c commit 9e009e5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/get.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ def identify_platform():
108108
sys_name = 'Windows'
109109
return arduino_platform_names[sys_name][bits]
110110

111-
if __name__ == '__main__':
111+
def main():
112112
print('Platform: {0}'.format(identify_platform()))
113113
tools_to_download = load_tools_list('../package/package_esp8266com_index.template.json', identify_platform())
114114
mkdir_p(dist_dir)
115115
for tool in tools_to_download:
116116
get_tool(tool)
117+
118+
if __name__ == '__main__':
119+
main()

0 commit comments

Comments
 (0)