@@ -105,3 +105,37 @@ def bootstrap_scratch_bot(bot_name, directory):
105105 replace_all (config_file , r'port = .*$' , 'port = ' + str (random .randint (20000 , 65000 )))
106106
107107 return config_file
108+
109+
110+ def bootstrap_python_hivemind (hive_name , directory ):
111+ sanitized_name = convert_to_filename (hive_name )
112+ bot_directory = Path (directory or '.' )
113+ top_dir = bot_directory / sanitized_name
114+ if os .path .exists (top_dir ):
115+ raise FileExistsError (f'There is already a bot named { sanitized_name } , please choose a different name!' )
116+
117+ with tempfile .TemporaryDirectory () as tmpdirname :
118+ tmpdir = Path (tmpdirname )
119+ print ('created temporary directory' , tmpdir )
120+
121+ download_and_extract_zip (
122+ download_url = 'https://github.com/ViliamVadocz/RLBotPythonHivemindExample/archive/master.zip' ,
123+ local_folder_path = tmpdir )
124+
125+ safe_move (tmpdir / 'RLBotPythonHivemindExample-master' , top_dir )
126+
127+
128+ config_file = top_dir / 'config.cfg'
129+ drone_file = top_dir / 'src' / 'drone.py'
130+ hive_file = top_dir / 'src' / 'hive.py'
131+
132+ replace_all (config_file , r'name = .*$' , f'name = { hive_name } ' )
133+ replace_all (drone_file , r'hive_name = .*$' , f'hive_name = "{ hive_name } Hivemind"' )
134+ replace_all (drone_file , r'hive_key = .*$' , f'hive_key = "{ random .randint (100000 , 999999 ) + hash (hive_name )} "' )
135+ replace_all (hive_file , r'class .*\(PythonHivemind\)' , f'class { hive_name } Hivemind(PythonHivemind)' )
136+
137+ # This is intended to open the example python file in the default system editor for .py files.
138+ # Hopefully this will be VS Code or notepad++ or something. If it gets executed as a python script, no harm done.
139+ os .startfile (hive_file )
140+
141+ return config_file
0 commit comments