diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index f044939..b2d9683 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -253,7 +253,13 @@ def cmd_importer(opts, conf, paths): # create a new dotfile dotfile = Dotfile('', dst, src) - linkit = opts['link'] or opts['link_by_default'] + + linktype = LinkTypes.NOLINK + if opts['link'] or opts['link_by_default']: + linktype = LinkTypes.PARENTS + elif opts['link_children']: + linktype = LinkTypes.CHILDREN + if opts['debug']: LOG.dbg('new dotfile: {}'.format(dotfile)) @@ -272,7 +278,7 @@ def cmd_importer(opts, conf, paths): cmd = ['cp', '-R', '-L', dst, srcf] if opts['dry']: LOG.dry('would run: {}'.format(' '.join(cmd))) - if linkit: + if linktype == LinkTypes.PARENTS: LOG.dry('would symlink {} to {}'.format(srcf, dst)) else: r, _ = run(cmd, raw=False, debug=opts['debug'], checkerr=True) @@ -280,11 +286,11 @@ def cmd_importer(opts, conf, paths): LOG.err('importing \"{}\" failed!'.format(path)) ret = False continue - if linkit: + if linktype == LinkTypes.PARENTS: remove(dst) os.symlink(srcf, dst) retconf, dotfile = conf.new(dotfile, opts['profile'], - link=linkit, debug=opts['debug']) + link=linktype, debug=opts['debug']) if retconf: LOG.sub('\"{}\" imported'.format(path)) cnt += 1 diff --git a/tests/helpers.py b/tests/helpers.py index 472069b..be55796 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -88,6 +88,7 @@ def load_config(confpath, profile): opts['safe'] = True opts['installdiff'] = True opts['link'] = False + opts['link_children'] = False opts['showdiff'] = True opts['debug'] = True opts['dopts'] = '' diff --git a/tests/test_install.py b/tests/test_install.py index 5ebef41..51e0368 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -4,14 +4,18 @@ Copyright (c) 2017, deadc0de6 basic unittest for the install function """ +import os import unittest import filecmp -from tests.helpers import * +from dotdrop.config import Cfg +from tests.helpers import create_dir, get_string, get_tempdir, clean, \ + create_random_file, load_config from dotdrop.dotfile import Dotfile from dotdrop.installer import Installer from dotdrop.action import Action from dotdrop.dotdrop import cmd_install +from dotdrop.linktypes import LinkTypes class TestInstall(unittest.TestCase): @@ -50,7 +54,10 @@ exec bspwm f.write(' {}:\n'.format(d.key)) f.write(' dst: {}\n'.format(d.dst)) f.write(' src: {}\n'.format(d.src)) - f.write(' link: {}\n'.format(str(d.link).lower())) + f.write(' link: {}\n' + .format(str(d.link == LinkTypes.PARENTS).lower())) + f.write(' link_children: {}\n' + .format(str(d.link == LinkTypes.CHILDREN).lower())) if len(d.actions) > 0: f.write(' actions:\n') for action in d.actions: @@ -101,7 +108,7 @@ exec bspwm # to test backup f4, c4 = create_random_file(tmp) dst4 = os.path.join(dst, get_string(6)) - d4 = Dotfile(get_string(6), dst4, os.path.basename(f4)) + d4 = Dotfile(key=get_string(6), dst=dst4, src=os.path.basename(f4)) with open(dst4, 'w') as f: f.write(get_string(16)) diff --git a/tests/test_update.py b/tests/test_update.py index 74f26ee..74808c3 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -7,14 +7,12 @@ basic unittest for the update function import unittest import os -import yaml -from dotdrop.config import Cfg from dotdrop.dotdrop import cmd_update from dotdrop.dotdrop import cmd_importer -from dotdrop.dotfile import Dotfile -from tests.helpers import * +from tests.helpers import create_dir, get_string, get_tempdir, clean, \ + create_random_file, create_fake_config, load_config, edit_content class TestUpdate(unittest.TestCase):