From 180123fee2640fe9639249dd01f0f4decda6af73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Sat, 3 Jan 2015 09:17:00 +0100 Subject: [PATCH] Improved 7zip detection --- kcc/cbxarchive.py | 3 ++- kcc/shared.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kcc/cbxarchive.py b/kcc/cbxarchive.py index 216c1fa..6a7c598 100644 --- a/kcc/cbxarchive.py +++ b/kcc/cbxarchive.py @@ -27,6 +27,7 @@ from subprocess import STDOUT, PIPE from psutil import Popen from shutil import move, copy from . import rarfile +from .shared import check7ZFile as is_7zfile class CBxArchive: @@ -36,7 +37,7 @@ class CBxArchive: self.compressor = 'zip' elif rarfile.is_rarfile(origFileName): self.compressor = 'rar' - elif origFileName.endswith('.7z') or origFileName.endswith('.cb7'): + elif is_7zfile(origFileName): self.compressor = '7z' else: self.compressor = None diff --git a/kcc/shared.py b/kcc/shared.py index 418abf1..dbbdd44 100644 --- a/kcc/shared.py +++ b/kcc/shared.py @@ -52,3 +52,9 @@ def md5Checksum(filePath): break m.update(data) return m.hexdigest() + + +def check7ZFile(filePath): + with open(filePath, 'rb') as fh: + header = fh.read(6) + return header == b"7z\xbc\xaf'\x1c" \ No newline at end of file