chg: [import_dir] fix is_gzip test, use magic number

This commit is contained in:
Terrtia 2020-02-27 14:21:32 +01:00
parent 998f8cc8e1
commit 873797d87f
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0

View file

@ -7,9 +7,9 @@ from io import StringIO
import datetime
import gzip
import argparse
import binascii
import os
import time, datetime
import magic
import re
'''
@ -37,6 +37,8 @@ import re
'
'''
def is_gzip_file(magic_nuber):
return binascii.hexlify(magic_nuber) == b'1f8b'
def is_hierachy_valid(path):
var = path.split('/')
@ -82,7 +84,7 @@ if __name__ == "__main__":
messagedata = f.read()
#verify that the data is gzipEncoded. if not compress it
if 'text/plain' in str(magic.from_buffer(messagedata, mime=True)):
if not is_gzip_file(messagedata[0:2]):
messagedata = gzip.compress(messagedata)
complete_path += '.gz'