mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 07:58:48 +00:00
use magic for determining file types and remove mkdir dependency
This commit is contained in:
@@ -133,11 +133,10 @@ $ ./dotdrop.sh --cfg <my-config-file> files
|
||||
Beside the python dependencies defined in [requirements.txt](https://github.com/deadc0de6/dotdrop/blob/master/requirements.txt),
|
||||
dotdrop depends on following tools:
|
||||
|
||||
* `file`
|
||||
* `diff`
|
||||
* `mkdir`
|
||||
* `git` (for the entry point script [dotdrop.sh](https://github.com/deadc0de6/dotdrop/blob/master/dotdrop.sh))
|
||||
* `readlink` or `realpath` (for the entry point script [dotdrop.sh](https://github.com/deadc0de6/dotdrop/blob/master/dotdrop.sh))
|
||||
* `file` (if libmagic is not installed, see <https://github.com/ahupp/python-magic>)
|
||||
* `git` (only if using the entry point script [dotdrop.sh](https://github.com/deadc0de6/dotdrop/blob/master/dotdrop.sh))
|
||||
* `readlink` or `realpath` (only if using the entry point script [dotdrop.sh](https://github.com/deadc0de6/dotdrop/blob/master/dotdrop.sh))
|
||||
|
||||
For MacOS users, make sure to install `realpath` (part of `coreutils`) through [homebrew](https://brew.sh/).
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from dotdrop.installer import Installer
|
||||
from dotdrop.updater import Updater
|
||||
from dotdrop.comparator import Comparator
|
||||
from dotdrop.utils import get_tmpdir, remove, strip_home, \
|
||||
run, uniq_list, patch_ignores, dependencies_met
|
||||
uniq_list, patch_ignores, dependencies_met
|
||||
from dotdrop.linktypes import LinkTypes
|
||||
from dotdrop.exceptions import YamlException, UndefinedException
|
||||
|
||||
@@ -438,12 +438,13 @@ def cmd_importer(o):
|
||||
if o.debug:
|
||||
LOG.dbg('will overwrite: {}'.format(overwrite))
|
||||
if overwrite:
|
||||
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
||||
cmd = 'mkdir -p {}'.format(os.path.dirname(srcf))
|
||||
if o.dry:
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
LOG.dry('would run: {}'.format(cmd))
|
||||
else:
|
||||
r, _ = run(cmd, raw=False, debug=o.debug, checkerr=True)
|
||||
if not r:
|
||||
try:
|
||||
os.makedirs(os.path.dirname(srcf), exist_ok=True)
|
||||
except Exception:
|
||||
LOG.err('importing \"{}\" failed!'.format(path))
|
||||
ret = False
|
||||
continue
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
Jinja2; python_version > '3.4'
|
||||
docopt; python_version > '3.4'
|
||||
ruamel.yaml; python_version > '3.4'
|
||||
python-magic; python_version > '3.4'
|
||||
|
||||
Reference in New Issue
Block a user