(
script: string,
dataFolderPath: string,
scriptName: string,
)
| 164 | } |
| 165 | |
| 166 | async executePythonScript( |
| 167 | script: string, |
| 168 | dataFolderPath: string, |
| 169 | scriptName: string, |
| 170 | ): Promise<ChildProcess> { |
| 171 | console.log('Saving Script'); |
| 172 | console.log('Data Folder Path:', dataFolderPath); // Added logging |
| 173 | |
| 174 | let adjustedScriptName = scriptName; |
| 175 | if (process.platform === 'win32') { |
| 176 | adjustedScriptName = adjustedScriptName.replace(/[^a-zA-Z0-9_]/g, '_'); // Replace invalid characters with underscores |
| 177 | } |
| 178 | |
| 179 | const chatFilePath = path.join(dataFolderPath, `${adjustedScriptName}.py`); |
| 180 | console.log('Chat File Path:', chatFilePath); // Added logging |
| 181 | |
| 182 | //overwrite the file if it exists |
| 183 | try { |
| 184 | await fs.promises.writeFile(chatFilePath, script); |
| 185 | console.log('Script saved to:', chatFilePath); |
| 186 | } catch (error) { |
| 187 | console.error('Error saving script:', error); |
| 188 | throw new Error('Failed to save the script file.'); |
| 189 | } |
| 190 | |
| 191 | const options = { |
| 192 | cwd: dataFolderPath, |
| 193 | shell: true, |
| 194 | }; |
| 195 | |
| 196 | if (!this.SurferPythonPath) { |
| 197 | throw new Error( |
| 198 | 'Python path is not set. Make sure to call findPython() before executing a script.', |
| 199 | ); |
| 200 | } |
| 201 | |
| 202 | console.log('Using Python path:', this.SurferPythonPath); |
| 203 | |
| 204 | // Wrap paths in quotes to handle spaces |
| 205 | const pythonPath = `"${this.SurferPythonPath}"`; |
| 206 | const scriptPath = `"${chatFilePath}"`; |
| 207 | |
| 208 | if (process.platform === 'win32') { |
| 209 | return spawn(`python.exe ${chatFilePath}`, options); |
| 210 | } else { |
| 211 | return spawn(pythonPath, [scriptPath], options); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | async hackBrowserScript(platform: string): Promise<ChildProcess> { |
| 216 | const pythonPath = `"${this.SurferPythonPath}"`; |
nothing calls this directly
no outgoing calls
no test coverage detected