1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-10 09:14:16 +00:00

use magic for determining file types and remove mkdir dependency

This commit is contained in:
deadc0de6
2020-11-05 22:17:26 +01:00
parent 29d23fe549
commit 8bc6519a25
4 changed files with 19 additions and 13 deletions

View File

@@ -146,12 +146,17 @@ class Templategen:
def _handle_file(self, src):
"""generate the file content from template"""
_, filetype = utils.run(['file', '-b', src],
raw=False, debug=self.debug)
filetype = filetype.strip()
try:
import magic
filetype = magic.from_file(src, mime=True)
istext = filetype.startswith('text')
except ImportError:
_, filetype = utils.run(['file', '-b', src],
raw=False, debug=self.debug)
filetype = filetype.strip()
istext = self._is_text(filetype)
if self.debug:
self.log.dbg('filetype \"{}\": {}'.format(src, filetype))
istext = self._is_text(filetype)
if self.debug:
self.log.dbg('is text \"{}\": {}'.format(src, istext))
if not istext: