1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 09:08:50 +00:00
This commit is contained in:
deadc0de6
2020-11-19 19:54:09 +01:00
parent 6ab0b00930
commit 5e7309a3ec
5 changed files with 39 additions and 40 deletions

View File

@@ -510,7 +510,7 @@ def cmd_list_profiles(o):
LOG.log('')
def cmd_list_files(o):
def cmd_files(o):
"""list all dotfiles for a specific profile"""
if o.profile not in [p.key for p in o.profiles]:
LOG.warn('unknown profile \"{}\"'.format(o.profile))
@@ -525,17 +525,21 @@ def cmd_list_files(o):
if not Templategen.is_template(src):
continue
if o.files_grepable:
fmt = '{},dst:{},src:{},link:{},chmod:{}'
fmt = '{},dst:{},src:{},link:{}'
fmt = fmt.format(dotfile.key, dotfile.dst,
dotfile.src, dotfile.link.name.lower(),
dotfile.chmod)
dotfile.src, dotfile.link.name.lower())
if dotfile.chmod:
fmt += ',chmod:{:o}'
else:
fmt += ',chmod:None'
LOG.raw(fmt)
else:
LOG.log('{}'.format(dotfile.key), bold=True)
LOG.sub('dst: {}'.format(dotfile.dst))
LOG.sub('src: {}'.format(dotfile.src))
LOG.sub('link: {}'.format(dotfile.link.name.lower()))
LOG.sub('chmod: {}'.format(dotfile.chmod))
if dotfile.chmod:
LOG.sub('chmod: {:o}'.format(dotfile.chmod))
LOG.log('')
@@ -773,7 +777,7 @@ def main():
command = 'files'
if o.debug:
LOG.dbg('running cmd: {}'.format(command))
cmd_list_files(o)
cmd_files(o)
elif o.cmd_install:
# install the dotfiles stored in dotdrop

View File

@@ -145,23 +145,35 @@ class Installer:
actionexec=actionexec,
is_template=is_template)
if self.debug:
self.log.dbg('before chmod: {} err:{}'.format(r, err))
if self.dry:
return self._log_install(r, err)
# handle chmod
# - on success (r, not err)
# - no change (not r, not err)
# but not when
# - error (not r, err)
# - aborted (not r, err)
if (r or (not r and not err)) \
and chmod and not self.dry:
if (r or (not r and not err)):
if not chmod:
chmod = utils.get_file_perm(src)
dstperms = utils.get_file_perm(dst)
if dstperms != chmod:
# apply mode
self.log.sub('chmod {} to {:o}'.format(dst, chmod))
if utils.chmod(dst, chmod, debug=self.debug):
r = True
else:
msg = 'chmod {} to {:o}'.format(dst, chmod)
if self.safe and not self.log.ask(msg):
r = False
err = 'chmod failed'
err = 'aborted'
else:
self.log.sub('chmod {} to {:o}'.format(dst, chmod))
if utils.chmod(dst, chmod, debug=self.debug):
r = True
else:
r = False
err = 'chmod failed'
return self._log_install(r, err)
@@ -536,9 +548,7 @@ class Installer:
if not src_mode:
src_mode = utils.get_file_perm(src)
if self.diff:
if not self._is_different(src, dst,
content=content,
src_mode=src_mode):
if not self._is_different(src, dst, content=content):
if self.debug:
self.log.dbg('{} is the same'.format(dst))
return False, None
@@ -599,29 +609,11 @@ class Installer:
tmp['_dotfile_sub_abs_dst'] = dst
return tmp
def _is_different(self, src, dst, src_mode=None, content=None):
def _is_different(self, src, dst, content=None):
"""
returns True if file is different and
needs to be installed
"""
# check file size
src_size = os.stat(src).st_size
dst_size = os.stat(dst).st_size
if src_size != dst_size:
if self.debug:
self.log.dbg('size differ')
return True
# check file mode
if not src_mode:
src_mode = utils.get_file_perm(src)
dst_mode = utils.get_file_perm(dst)
if src_mode != dst_mode:
if self.debug:
m = 'mode differ ({:o} vs {:o})'
self.log.dbg(m.format(src_mode, dst_mode))
return True
# check file content
if content:
tmp = utils.write_to_tmpfile(content)

View File

@@ -243,6 +243,7 @@ chmod 600 ${tmps}/dotfiles/nomode
echo "nomode" > ${tmpd}/nomode
chmod 600 ${tmpd}/nomode
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p2 -V f_nomode
echo "same mode"
has_rights "${tmpd}/nomode" "600"
## no user confirmation with force
@@ -253,6 +254,7 @@ chmod 600 ${tmps}/dotfiles/nomode
echo "nomode" > ${tmpd}/nomode
chmod 700 ${tmpd}/nomode
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p2 -V f_nomode
echo "different mode (1)"
has_rights "${tmpd}/nomode" "600"
## user confirmation expected
@@ -263,6 +265,7 @@ chmod 600 ${tmps}/dotfiles/nomode
echo "nomode" > ${tmpd}/nomode
chmod 700 ${tmpd}/nomode
cd ${ddpath} | printf 'y\ny\n' | ${bin} install -f -c ${cfg} -p p2 -V f_nomode
echo "different mode (2)"
has_rights "${tmpd}/nomode" "600"
## CLEANING

View File

@@ -10,7 +10,7 @@ import os
from dotdrop.dotdrop import cmd_importer
from dotdrop.dotdrop import cmd_list_profiles
from dotdrop.dotdrop import cmd_list_files
from dotdrop.dotdrop import cmd_files
from dotdrop.dotdrop import cmd_update
from dotdrop.linktypes import LinkTypes
@@ -184,7 +184,7 @@ class TestImport(unittest.TestCase):
self.assertTrue(os.path.exists(s4))
cmd_list_profiles(o)
cmd_list_files(o)
cmd_files(o)
# fake test update
editcontent = 'edited'

View File

@@ -9,7 +9,7 @@ import unittest
import os
from dotdrop.dotdrop import cmd_list_profiles
from dotdrop.dotdrop import cmd_list_files
from dotdrop.dotdrop import cmd_files
from dotdrop.dotdrop import cmd_detail
from dotdrop.dotdrop import cmd_importer
@@ -87,9 +87,9 @@ class TestListings(unittest.TestCase):
# list files
o.files_templateonly = False
cmd_list_files(o)
cmd_files(o)
o.files_templateonly = True
cmd_list_files(o)
cmd_files(o)
# details
o.detail_keys = None