mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 04:23:01 +00:00
refactor linkall to link_children
This commit is contained in:
@@ -63,7 +63,8 @@ def cmd_install(o):
|
|||||||
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.PARENTS:
|
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.PARENTS:
|
||||||
r = inst.link(t, dotfile.src, dotfile.dst, actions=preactions)
|
r = inst.link(t, dotfile.src, dotfile.dst, actions=preactions)
|
||||||
elif hasattr(dotfile, 'link') and dotfile.link == LinkTypes.CHILDREN:
|
elif hasattr(dotfile, 'link') and dotfile.link == LinkTypes.CHILDREN:
|
||||||
r = inst.linkall(t, dotfile.src, dotfile.dst, actions=preactions)
|
r = inst.link_children(t, dotfile.src, dotfile.dst,
|
||||||
|
actions=preactions)
|
||||||
else:
|
else:
|
||||||
src = dotfile.src
|
src = dotfile.src
|
||||||
tmp = None
|
tmp = None
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ class Installer:
|
|||||||
src = tmp
|
src = tmp
|
||||||
return self._link(src, dst, actions=actions)
|
return self._link(src, dst, actions=actions)
|
||||||
|
|
||||||
def linkall(self, templater, src, dst, actions=[]):
|
def link_children(self, templater, src, dst, actions=[]):
|
||||||
"""link all dotfiles in a given directory"""
|
"""link all dotfiles in a given directory"""
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('linkall {} to {}'.format(src, dst))
|
self.log.dbg('link_children {} to {}'.format(src, dst))
|
||||||
self.action_executed = False
|
self.action_executed = False
|
||||||
parent = os.path.join(self.base, os.path.expanduser(src))
|
parent = os.path.join(self.base, os.path.expanduser(src))
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,12 @@ exec bspwm
|
|||||||
f.write(' {}:\n'.format(d.key))
|
f.write(' {}:\n'.format(d.key))
|
||||||
f.write(' dst: {}\n'.format(d.dst))
|
f.write(' dst: {}\n'.format(d.dst))
|
||||||
f.write(' src: {}\n'.format(d.src))
|
f.write(' src: {}\n'.format(d.src))
|
||||||
f.write(' link: {}\n'
|
if d.link == LinkTypes.CHILDREN:
|
||||||
.format(str(d.link == LinkTypes.PARENTS).lower()))
|
f.write(' link_children: {}\n'
|
||||||
f.write(' link_children: {}\n'
|
.format(str(d.link == LinkTypes.CHILDREN).lower()))
|
||||||
.format(str(d.link == LinkTypes.CHILDREN).lower()))
|
else:
|
||||||
|
f.write(' link: {}\n'
|
||||||
|
.format(str(d.link == LinkTypes.PARENTS).lower()))
|
||||||
if len(d.actions) > 0:
|
if len(d.actions) > 0:
|
||||||
f.write(' actions:\n')
|
f.write(' actions:\n')
|
||||||
for action in d.actions:
|
for action in d.actions:
|
||||||
@@ -249,8 +251,8 @@ exec bspwm
|
|||||||
srcs = [create_random_file(src_dir)[0] for _ in range(3)]
|
srcs = [create_random_file(src_dir)[0] for _ in range(3)]
|
||||||
|
|
||||||
installer = Installer()
|
installer = Installer()
|
||||||
installer.linkall(templater=MagicMock(), src=src_dir, dst=dst_dir,
|
installer.link_children(templater=MagicMock(), src=src_dir,
|
||||||
actions=[])
|
dst=dst_dir, actions=[])
|
||||||
|
|
||||||
# Ensure all destination files point to source
|
# Ensure all destination files point to source
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
@@ -265,9 +267,8 @@ exec bspwm
|
|||||||
logger = MagicMock()
|
logger = MagicMock()
|
||||||
installer.log.err = logger
|
installer.log.err = logger
|
||||||
|
|
||||||
res = installer.linkall(templater=MagicMock(),
|
res = installer.link_children(templater=MagicMock(), src=src,
|
||||||
src=src,
|
dst='/dev/null', actions=[])
|
||||||
dst='/dev/null', actions=[])
|
|
||||||
|
|
||||||
self.assertEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
logger.assert_called_with('source dotfile does not exist: {}'
|
logger.assert_called_with('source dotfile does not exist: {}'
|
||||||
@@ -288,8 +289,8 @@ exec bspwm
|
|||||||
installer.log.err = logger
|
installer.log.err = logger
|
||||||
|
|
||||||
# pass src file not src dir
|
# pass src file not src dir
|
||||||
res = installer.linkall(templater=templater, src=src, dst='/dev/null',
|
res = installer.link_children(templater=templater, src=src,
|
||||||
actions=[])
|
dst='/dev/null', actions=[])
|
||||||
|
|
||||||
# ensure nothing performed
|
# ensure nothing performed
|
||||||
self.assertEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
@@ -312,8 +313,8 @@ exec bspwm
|
|||||||
self.assertFalse(os.path.exists(dst_dir))
|
self.assertFalse(os.path.exists(dst_dir))
|
||||||
|
|
||||||
installer = Installer()
|
installer = Installer()
|
||||||
installer.linkall(templater=MagicMock(), src=src_dir, dst=dst_dir,
|
installer.link_children(templater=MagicMock(), src=src_dir,
|
||||||
actions=[])
|
dst=dst_dir, actions=[])
|
||||||
|
|
||||||
# ensure dst dir created
|
# ensure dst dir created
|
||||||
self.assertTrue(os.path.exists(dst_dir))
|
self.assertTrue(os.path.exists(dst_dir))
|
||||||
@@ -344,8 +345,8 @@ exec bspwm
|
|||||||
installer.safe = True
|
installer.safe = True
|
||||||
installer.log.ask = ask
|
installer.log.ask = ask
|
||||||
|
|
||||||
installer.linkall(templater=MagicMock(), src=src_dir, dst=dst,
|
installer.link_children(templater=MagicMock(), src=src_dir, dst=dst,
|
||||||
actions=[])
|
actions=[])
|
||||||
|
|
||||||
# ensure destination now a directory
|
# ensure destination now a directory
|
||||||
self.assertTrue(os.path.isdir(dst))
|
self.assertTrue(os.path.isdir(dst))
|
||||||
@@ -378,8 +379,8 @@ exec bspwm
|
|||||||
# make templategen treat everything as a template
|
# make templategen treat everything as a template
|
||||||
mocked_templategen.is_template.return_value = True
|
mocked_templategen.is_template.return_value = True
|
||||||
|
|
||||||
installer.linkall(templater=templater, src=src_dir, dst=dst_dir,
|
installer.link_children(templater=templater, src=src_dir, dst=dst_dir,
|
||||||
actions=[])
|
actions=[])
|
||||||
|
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
dst = os.path.join(dst_dir, os.path.basename(src))
|
dst = os.path.join(dst_dir, os.path.basename(src))
|
||||||
|
|||||||
Reference in New Issue
Block a user