Commit 188c55f9 authored by Julien Muchembled's avatar Julien Muchembled

neolog: add support for xz-compressed logs, using external xzcat commands

parent 9ee4e04d
...@@ -22,7 +22,7 @@ from bisect import insort ...@@ -22,7 +22,7 @@ from bisect import insort
from logging import getLevelName from logging import getLevelName
from zlib import decompress from zlib import decompress
comp_dict = dict(bz2=bz2.BZ2File, gz=gzip.GzipFile) comp_dict = dict(bz2=bz2.BZ2File, gz=gzip.GzipFile, xz='xzcat')
class Log(object): class Log(object):
...@@ -46,9 +46,12 @@ class Log(object): ...@@ -46,9 +46,12 @@ class Log(object):
os.stat(db_path) # do not create empty DB if file is missing os.stat(db_path) # do not create empty DB if file is missing
self._db = sqlite3.connect(db_path) self._db = sqlite3.connect(db_path)
else: else:
import shutil, tempfile import shutil, subprocess, tempfile
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
shutil.copyfileobj(ZipFile(db_path), f) if type(ZipFile) is str:
subprocess.check_call((ZipFile, db_path), stdout=f)
else:
shutil.copyfileobj(ZipFile(db_path), f)
self._db = sqlite3.connect(f.name) self._db = sqlite3.connect(f.name)
name = name.rsplit(os.extsep, 1)[0] name = name.rsplit(os.extsep, 1)[0]
self._default_name = name self._default_name = name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment