Skip to content

Commit

Permalink
rename configuration from remove comments to minify
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Jun 10, 2022
1 parent 8fa7a5d commit 6479331
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions microfreezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self):
self.excludeList = self.config.get("excludeList", [])
self.directoriesKeptInFrozen = self.config.get("directoriesKeptInFrozen", [])
self.enableZlibCompression = self.config.get("enableZlibCompression", True)
self.removeComments = self.config.get("removeComments", False)
self.minify = self.config.get("minify", False)
self.targetESP32 = self.config.get("targetESP32", False)
self.targetPycom = self.config.get("targetPycom", True)
self.flashRootFolder = "/flash/" if self.targetPycom else "/"
Expand Down Expand Up @@ -148,7 +148,7 @@ def run_package(self, sourceDir, destDir):
logging.info("Operation completed successfully.")

# https://www.codingconception.com/python-examples/write-a-program-to-delete-comment-lines-from-a-file-in-python/
def removeCommentsAndReplaceFile(self, sourceFile, destFile):
def minifyAndReplaceFile(self, sourceFile, destFile):
import python_minifier

with open(sourceFile) as f:
Expand All @@ -171,15 +171,15 @@ def removeCommentsAndReplaceFile(self, sourceFile, destFile):
def convertFileToBase64(self, sourceFile, destFile):
logging.debug(" [C]: " + str(sourceFile))
tmp_file = None
if self.removeComments and sourceFile.endswith(".py") and '/templ/' not in sourceFile:
if self.minify and sourceFile.endswith(".py") and '/templ/' not in sourceFile:
import uuid
tmp_file = '/tmp/' + str(uuid.uuid1()) + ".py"
self.removeCommentsAndReplaceFile(sourceFile, tmp_file)
self.minifyAndReplaceFile(sourceFile, tmp_file)
sourceFile = tmp_file

bytes = readFromFile(sourceFile, True)

if self.removeComments and tmp_file is not None:
if self.minify and tmp_file is not None:
try:
import os
#os.remove(tmp_file)
Expand Down

0 comments on commit 6479331

Please sign in to comment.