Support gzip compressed database files
This commit is contained in:
parent
f451ce6c91
commit
b503d59c49
2 changed files with 8 additions and 4 deletions
|
@ -9,6 +9,7 @@ import gevent
|
||||||
from DbCursor import DbCursor
|
from DbCursor import DbCursor
|
||||||
from Config import config
|
from Config import config
|
||||||
from util import SafeRe
|
from util import SafeRe
|
||||||
|
from util import helper
|
||||||
|
|
||||||
opened_dbs = []
|
opened_dbs = []
|
||||||
|
|
||||||
|
@ -244,10 +245,13 @@ class Db(object):
|
||||||
# Load the json file
|
# Load the json file
|
||||||
try:
|
try:
|
||||||
if file is None: # Open file is not file object passed
|
if file is None: # Open file is not file object passed
|
||||||
file = open(file_path)
|
file = open(file_path, "rb")
|
||||||
|
|
||||||
if file is False: # File deleted
|
if file is False: # File deleted
|
||||||
data = {}
|
data = {}
|
||||||
|
else:
|
||||||
|
if file_path.endswith("json.gz"):
|
||||||
|
data = json.load(helper.limitedGzipFile(fileobj=file))
|
||||||
else:
|
else:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
|
|
|
@ -85,7 +85,7 @@ class SiteStorage(object):
|
||||||
# Data files in content.json
|
# Data files in content.json
|
||||||
content_inner_path_dir = helper.getDirname(content_inner_path) # Content.json dir relative to site
|
content_inner_path_dir = helper.getDirname(content_inner_path) # Content.json dir relative to site
|
||||||
for file_relative_path in content.get("files", {}).keys() + content.get("files_optional", {}).keys():
|
for file_relative_path in content.get("files", {}).keys() + content.get("files_optional", {}).keys():
|
||||||
if not file_relative_path.endswith(".json"):
|
if not file_relative_path.endswith(".json") and not file_relative_path.endswith("json.gz"):
|
||||||
continue # We only interesed in json files
|
continue # We only interesed in json files
|
||||||
file_inner_path = content_inner_path_dir + file_relative_path # File Relative to site dir
|
file_inner_path = content_inner_path_dir + file_relative_path # File Relative to site dir
|
||||||
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
||||||
|
@ -239,7 +239,7 @@ class SiteStorage(object):
|
||||||
if self.has_db:
|
if self.has_db:
|
||||||
self.closeDb()
|
self.closeDb()
|
||||||
self.openDb()
|
self.openDb()
|
||||||
elif not config.disable_db and inner_path.endswith(".json") and self.has_db: # Load json file to db
|
elif not config.disable_db and (inner_path.endswith(".json") or inner_path.endswith(".json.gz")) and self.has_db: # Load json file to db
|
||||||
if config.verbose:
|
if config.verbose:
|
||||||
self.log.debug("Loading json file to db: %s (file: %s)" % (inner_path, file))
|
self.log.debug("Loading json file to db: %s (file: %s)" % (inner_path, file))
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue