1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-11 07:54:15 +00:00

Move link from bool to enum

This commit is contained in:
Marcel Robitaille
2019-01-20 15:02:09 -04:00
parent 247653c2c2
commit 170df39c60
4 changed files with 23 additions and 11 deletions

View File

@@ -253,7 +253,13 @@ def cmd_importer(opts, conf, paths):
# create a new dotfile # create a new dotfile
dotfile = Dotfile('', dst, src) 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']: if opts['debug']:
LOG.dbg('new dotfile: {}'.format(dotfile)) LOG.dbg('new dotfile: {}'.format(dotfile))
@@ -272,7 +278,7 @@ def cmd_importer(opts, conf, paths):
cmd = ['cp', '-R', '-L', dst, srcf] cmd = ['cp', '-R', '-L', dst, srcf]
if opts['dry']: if opts['dry']:
LOG.dry('would run: {}'.format(' '.join(cmd))) LOG.dry('would run: {}'.format(' '.join(cmd)))
if linkit: if linktype == LinkTypes.PARENTS:
LOG.dry('would symlink {} to {}'.format(srcf, dst)) LOG.dry('would symlink {} to {}'.format(srcf, dst))
else: else:
r, _ = run(cmd, raw=False, debug=opts['debug'], checkerr=True) 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)) LOG.err('importing \"{}\" failed!'.format(path))
ret = False ret = False
continue continue
if linkit: if linktype == LinkTypes.PARENTS:
remove(dst) remove(dst)
os.symlink(srcf, dst) os.symlink(srcf, dst)
retconf, dotfile = conf.new(dotfile, opts['profile'], retconf, dotfile = conf.new(dotfile, opts['profile'],
link=linkit, debug=opts['debug']) link=linktype, debug=opts['debug'])
if retconf: if retconf:
LOG.sub('\"{}\" imported'.format(path)) LOG.sub('\"{}\" imported'.format(path))
cnt += 1 cnt += 1

View File

@@ -88,6 +88,7 @@ def load_config(confpath, profile):
opts['safe'] = True opts['safe'] = True
opts['installdiff'] = True opts['installdiff'] = True
opts['link'] = False opts['link'] = False
opts['link_children'] = False
opts['showdiff'] = True opts['showdiff'] = True
opts['debug'] = True opts['debug'] = True
opts['dopts'] = '' opts['dopts'] = ''

View File

@@ -4,14 +4,18 @@ Copyright (c) 2017, deadc0de6
basic unittest for the install function basic unittest for the install function
""" """
import os
import unittest import unittest
import filecmp 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.dotfile import Dotfile
from dotdrop.installer import Installer from dotdrop.installer import Installer
from dotdrop.action import Action from dotdrop.action import Action
from dotdrop.dotdrop import cmd_install from dotdrop.dotdrop import cmd_install
from dotdrop.linktypes import LinkTypes
class TestInstall(unittest.TestCase): class TestInstall(unittest.TestCase):
@@ -50,7 +54,10 @@ 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'.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: if len(d.actions) > 0:
f.write(' actions:\n') f.write(' actions:\n')
for action in d.actions: for action in d.actions:
@@ -101,7 +108,7 @@ exec bspwm
# to test backup # to test backup
f4, c4 = create_random_file(tmp) f4, c4 = create_random_file(tmp)
dst4 = os.path.join(dst, get_string(6)) 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: with open(dst4, 'w') as f:
f.write(get_string(16)) f.write(get_string(16))

View File

@@ -7,14 +7,12 @@ basic unittest for the update function
import unittest import unittest
import os import os
import yaml
from dotdrop.config import Cfg
from dotdrop.dotdrop import cmd_update from dotdrop.dotdrop import cmd_update
from dotdrop.dotdrop import cmd_importer 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): class TestUpdate(unittest.TestCase):