diff options
author | 2023-10-05 19:40:09 +0200 | |
---|---|---|
committer | 2023-10-05 19:40:12 +0200 | |
commit | 04b6fdbf29c6643a3c72d35091dc28a56b5defc6 (patch) | |
tree | 134f1b2db2164e2ddd439b673103cffef261c5b6 | |
parent | Release 0.8.1 (diff) | |
parent | Port to lzma (diff) | |
download | elogv-04b6fdbf29c6643a3c72d35091dc28a56b5defc6.tar.gz elogv-04b6fdbf29c6643a3c72d35091dc28a56b5defc6.tar.bz2 elogv-04b6fdbf29c6643a3c72d35091dc28a56b5defc6.zip |
Merge branch 'pull-15-parona-source-lzma'
Signed-off-by: Sebastian Pipping <sping@gentoo.org>
-rwxr-xr-x | elogv | 32 | ||||
-rw-r--r-- | pyproject.toml | 3 |
2 files changed, 14 insertions, 21 deletions
@@ -33,6 +33,7 @@ import gettext import locale import gzip import bz2 +import lzma import signal _LOCALE_CATEGORY_PAIRS = ( @@ -46,12 +47,6 @@ _LOCALE_CATEGORY_PAIRS = ( (locale.LC_ALL, 'LC_ALL'), ) -no_liblzma = False -try: - import liblzma -except ImportError: - no_liblzma = True - def report_bad_locale(variable, value): py_version = '%s.%s.%s' % sys.version_info[:3] @@ -418,18 +413,19 @@ class ElogViewer: self.logf_wrap = self.wrap_logf_lines() self.show_log() - def openfile(self, myfile): - if myfile.endswith('.xz'): - if not no_liblzma: - self.logf = liblzma.LZMAFile(myfile) - else: - sys.exit('You need pyliblzma library to be able to read xz compressed elog files.\nhttp://pypi.python.org/pypi/pyliblzma') - elif myfile.endswith('.gz'): - self.logf = gzip.open(myfile) - elif myfile.endswith('.bz2'): - self.logf = bz2.BZ2File(myfile) + @staticmethod + def open(file, mode='rt'): + if file.endswith('.xz'): + return lzma.open(file, mode=mode) + elif file.endswith('.gz'): + return gzip.open(file, mode=mode) + elif file.endswith('.bz2'): + return bz2.open(file, mode=mode) else: - self.logf = open(myfile) + return open(file, mode=mode) + + def openfile(self, file): + self.logf = self.open(file) def refresh_file_pad(self): """ @@ -528,7 +524,7 @@ class ElogViewer: """ Get the highest elog class in a file """ - with open(filepath) as f: + with self.open(filepath) as f: classes = re.findall("LOG:|INFO:|WARN:|ERROR:", f.read()) if "ERROR:" in classes: diff --git a/pyproject.toml b/pyproject.toml index 88ad65f..0476844 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,3 @@ dependencies = ["portage"] [project.urls] homepage = "https://gitweb.gentoo.org/proj/elogv.git/" - -[project.optional-dependencies] -lzma = [ "pyliblzma" ] |