Move json formatting to separate function

This commit is contained in:
shortcutme 2017-10-03 15:30:10 +02:00
parent 5ccdfbd40a
commit 468fe8f266
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -258,8 +258,7 @@ class SiteStorage(object):
with self.open(inner_path) as file: with self.open(inner_path) as file:
return json.load(file) return json.load(file)
# Write formatted json file def formatJson(self, data):
def writeJson(self, inner_path, data):
content = json.dumps(data, indent=1, sort_keys=True) content = json.dumps(data, indent=1, sort_keys=True)
# Make it a little more compact by removing unnecessary white space # Make it a little more compact by removing unnecessary white space
@ -282,9 +281,12 @@ class SiteStorage(object):
# Remove end of line whitespace # Remove end of line whitespace
content = re.sub("(?m)[ ]+$", "", content) content = re.sub("(?m)[ ]+$", "", content)
return content
# Write formatted json file
def writeJson(self, inner_path, data):
# Write to disk # Write to disk
self.write(inner_path, content) self.write(inner_path, self.formatJson(data))
# Get file size # Get file size
def getSize(self, inner_path): def getSize(self, inner_path):