1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-10 18:29:17 +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('') LOG.log('')
def cmd_list_files(o): def cmd_files(o):
"""list all dotfiles for a specific profile""" """list all dotfiles for a specific profile"""
if o.profile not in [p.key for p in o.profiles]: if o.profile not in [p.key for p in o.profiles]:
LOG.warn('unknown profile \"{}\"'.format(o.profile)) LOG.warn('unknown profile \"{}\"'.format(o.profile))
@@ -525,17 +525,21 @@ def cmd_list_files(o):
if not Templategen.is_template(src): if not Templategen.is_template(src):
continue continue
if o.files_grepable: if o.files_grepable:
fmt = '{},dst:{},src:{},link:{},chmod:{}' fmt = '{},dst:{},src:{},link:{}'
fmt = fmt.format(dotfile.key, dotfile.dst, fmt = fmt.format(dotfile.key, dotfile.dst,
dotfile.src, dotfile.link.name.lower(), dotfile.src, dotfile.link.name.lower())
dotfile.chmod) if dotfile.chmod:
fmt += ',chmod:{:o}'
else:
fmt += ',chmod:None'
LOG.raw(fmt) LOG.raw(fmt)
else: else:
LOG.log('{}'.format(dotfile.key), bold=True) LOG.log('{}'.format(dotfile.key), bold=True)
LOG.sub('dst: {}'.format(dotfile.dst)) LOG.sub('dst: {}'.format(dotfile.dst))
LOG.sub('src: {}'.format(dotfile.src)) LOG.sub('src: {}'.format(dotfile.src))
LOG.sub('link: {}'.format(dotfile.link.name.lower())) 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('') LOG.log('')
@@ -773,7 +777,7 @@ def main():
command = 'files' command = 'files'
if o.debug: if o.debug:
LOG.dbg('running cmd: {}'.format(command)) LOG.dbg('running cmd: {}'.format(command))
cmd_list_files(o) cmd_files(o)
elif o.cmd_install: elif o.cmd_install:
# install the dotfiles stored in dotdrop # install the dotfiles stored in dotdrop

View File

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

View File

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

View File

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

View File

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