Skip to content

Commit

Permalink
Improve verbosity of tools/minimizeCURL.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Sep 18, 2024
1 parent fa0b1f6 commit 0ddadb1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tools/minimizeCURL.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ def isCommandStillFine(command):
result = executeCommand(command)
return wantedOutput in result

def getCommandLengthFormatted(command):
return f'{len(command):,}'

def printThatCommandIsStillFine(command):
print(f'Command with length {getCommandLengthFormatted(command)} is still fine.')

# For Chromium support:
command = command.replace(' \\\n ', '')

print(len(command))
print(f'Initial command length: {getCommandLengthFormatted(command)}.')
# To verify that the user provided the correct `wantedOutput` to keep during the minimization.
if not isCommandStillFine(command):
print('The wanted output isn\'t contained in the result of the original curl command!')
Expand All @@ -70,7 +76,7 @@ def isCommandStillFine(command):
del arguments[argumentsIndex : argumentsIndex + 2]
command = shlex.join(arguments)
if isCommandStillFine(command):
print(len(command), 'still fine')
printThatCommandIsStillFine(command)
changedSomething = True
break
else:
Expand Down Expand Up @@ -101,7 +107,7 @@ def isCommandStillFine(command):
arguments[urlIndex] = url
command = shlex.join(arguments)
if isCommandStillFine(command):
print(len(command), 'still fine')
printThatCommandIsStillFine(command)
changedSomething = True
break
else:
Expand Down Expand Up @@ -138,7 +144,7 @@ def isCommandStillFine(command):
arguments[cookiesIndex] = COOKIES_PREFIX + '; '.join(cookiesParsedCopy)
command = shlex.join(arguments)
if isCommandStillFine(command):
print(len(command), 'still fine')
printThatCommandIsStillFine(command)
changedSomething = True
cookies = '; '.join(cookiesParsedCopy)
break
Expand Down Expand Up @@ -178,7 +184,7 @@ def isCommandStillFine(command):
arguments[rawDataIndex] = '&'.join(rawDataPartsCopy)
command = shlex.join(arguments)
if isCommandStillFine(command):
print(len(command), 'still fine')
printThatCommandIsStillFine(command)
changedSomething = True
rawData = '&'.join(rawDataPartsCopy)
break
Expand Down Expand Up @@ -226,7 +232,7 @@ def getPaths(d):
command = shlex.join(arguments)
# (1) If it was unnecessary, then reconsider paths excluding possible children paths of this unnecessary entry, ensuring optimized complexity it seems.
if isCommandStillFine(command):
print(len(command), 'still fine')
printThatCommandIsStillFine(command)
changedSomething = True
rawData = json.dumps(rawDataParsedCopy)
break
Expand Down

0 comments on commit 0ddadb1

Please sign in to comment.