Skip to content

Commit

Permalink
Remove partially_minimized_curl on minimization finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Dec 2, 2024
1 parent 7049c89 commit 20782d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tools/minimizeCURL.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import sys
from urllib.parse import urlparse, parse_qs, quote_plus
import re
import os

# Could precise the input file and possibly remove the output one as the minimized requests start to be short.
if len(sys.argv) < 3:
Expand All @@ -36,7 +37,7 @@

PRINT_TRY_TO_REMOVE = False

VERIFY_INITIAL_COMMAND = False
VERIFY_INITIAL_COMMAND = True

def printTryToRemove(toRemove):
if PRINT_TRY_TO_REMOVE:
Expand All @@ -55,16 +56,21 @@ def executeCommand(command):
return b''
return result

def getCommandScript(fileName):
return f'{fileName}.sh'

def writeCommand(fileName, command):
with open(f'{fileName}.sh', 'w') as f:
with open(getCommandScript(fileName), 'w') as f:
f.write(command)

PARTIALLY_MINIMIZED_CURL_SCRIPT_NAME = 'partially_minimized_curl'

def isCommandStillFine(command):
result = executeCommand(command)
isCommandStillFineResult = wantedOutput in result
# [Benjamin-Loison/cpython/issues/48](https://github.com/Benjamin-Loison/cpython/issues/48)
if isCommandStillFineResult:
writeCommand('partially_minimized_curl', command)
writeCommand(PARTIALLY_MINIMIZED_CURL_SCRIPT_NAME, command)
return isCommandStillFineResult

def getCommandLengthFormatted(command):
Expand Down Expand Up @@ -296,3 +302,5 @@ def getPaths(d):
# First test `print`ing, before potentially removing `minimized_curl` writing.
print(command)
writeCommand('minimized_curl', command)

os.remove(getCommandScript(PARTIALLY_MINIMIZED_CURL_SCRIPT_NAME))

0 comments on commit 20782d9

Please sign in to comment.