Removed some whitespace, minor optimizations
parent
1b7df6e3b2
commit
5f961b7460
|
@ -15,7 +15,7 @@ import os
|
|||
import argparse
|
||||
from tempfile import NamedTemporaryFile
|
||||
import yaml
|
||||
from platform import system as getOS, release
|
||||
from platform import system as OSName, OSRelease
|
||||
|
||||
try:
|
||||
import winreg
|
||||
|
@ -50,12 +50,12 @@ def writeOutput(data, className) -> dict:
|
|||
"""
|
||||
global args
|
||||
namesDict = {} # return dict
|
||||
|
||||
|
||||
# Variables
|
||||
lineList = [ l.encode('utf8') for l in data.splitlines() ]
|
||||
fileNum = 1
|
||||
bytesWritten = 0
|
||||
|
||||
|
||||
# Constants
|
||||
maxFileSize = 2 ** 20 # 1MiB maximum cfg file size
|
||||
filesNeeded = 1 + int( len(data)/maxFileSize )
|
||||
|
@ -63,32 +63,32 @@ def writeOutput(data, className) -> dict:
|
|||
print( f'DEBUG: need {filesNeeded} files for {className}', file=sys.stderr)
|
||||
|
||||
FilNedLen = len(str(filesNeeded))
|
||||
reservedSpace = len(f'{className}_script_{filesNeeded}.cfg') + 4
|
||||
|
||||
# Initialize variables
|
||||
outfile = NamedTemporaryFile(prefix=className, delete=False)
|
||||
# I know % formatting is old-school and pylint hates it,
|
||||
# but "%*d" is the easiest way to left-pad with zeros
|
||||
# without hardcoding a number. The extra 4 bytes is just some leeway
|
||||
reservedSpace = len('%s_script_%0*d.cfg' % (className, FilNedLen, fileNum)) + 4
|
||||
|
||||
# Initialize the variables
|
||||
outfile = NamedTemporaryFile(prefix=className, delete=False)
|
||||
namesDict.update({ outfile.name: '%s_script_%0*d.cfg' % (className, FilNedLen, fileNum) })
|
||||
|
||||
while (fileNum <= filesNeeded and len(lineList) > 0):
|
||||
line = lineList.pop(0) + '\n'.encode('utf8')
|
||||
lineLen = len(line) # nice
|
||||
|
||||
|
||||
if bytesWritten + reservedSpace + lineLen > maxFileSize:
|
||||
outfile.write( ('exec %s_script_%0*d' % (className, FilNedLen, fileNum)).encode('utf8') )
|
||||
outfile.write( ('exec %s_script_%0*d' % (className, FilNedLen, fileNum+1)).encode('utf8') )
|
||||
bytesWritten += reservedSpace
|
||||
if args.debug:
|
||||
print( f'DEBUG: Wrote {bytesWritten} bytes to {className} ({fileNum}/{filesNeeded})', file=sys.stderr)
|
||||
|
||||
|
||||
outfile.close()
|
||||
outfile = NamedTemporaryFile(prefix=className, delete=False)
|
||||
|
||||
|
||||
fileNum += 1
|
||||
namesDict.update({ outfile.name: '%s_script_%0*d.cfg' % (className, FilNedLen, fileNum) })
|
||||
bytesWritten = 0
|
||||
|
||||
|
||||
outfile.write(line)
|
||||
bytesWritten += lineLen
|
||||
|
||||
|
@ -106,7 +106,7 @@ def parseConfig(config):
|
|||
if os.path.isdir(targetDir) == False:
|
||||
os.mkdir(targetDir)
|
||||
if args.debug:
|
||||
print(f"DEBUG: Created", file=sys.stderr)
|
||||
print( f"DEBUG: Created directory {targetDir}", file=sys.stderr)
|
||||
|
||||
tempsAndReals = {}
|
||||
|
||||
|
@ -144,9 +144,7 @@ def parseCLI():
|
|||
return parser
|
||||
|
||||
def main():
|
||||
"""
|
||||
Command line interface.
|
||||
"""
|
||||
""" Command line interface. """
|
||||
global args
|
||||
global targetDir
|
||||
parser = parseCLI()
|
||||
|
@ -155,9 +153,9 @@ def main():
|
|||
if args.directory is not None:
|
||||
targetDir = args.directory
|
||||
else:
|
||||
systemName = getOS()
|
||||
systemName = OSName()
|
||||
if systemName == "Darwin":
|
||||
if float( '.'.join(release().split('.')[0:2]) ) >= 10.15:
|
||||
if float( '.'.join(OSRelease().split('.')[0:2]) ) >= 10.15:
|
||||
if not args.force:
|
||||
print(
|
||||
"As of macOS Catalina (v10.15), 32-bit applications "
|
||||
|
|
Loading…
Reference in New Issue