mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 15:28:59 +00:00
Fixing src path in dotfiles to allow different dotpaths than the current one
This commit is contained in:
@@ -337,8 +337,12 @@ class Cfg:
|
|||||||
|
|
||||||
dotfiles = self.content[self.key_dotfiles]
|
dotfiles = self.content[self.key_dotfiles]
|
||||||
noempty_default = self.lnk_settings[self.key_ignoreempty]
|
noempty_default = self.lnk_settings[self.key_ignoreempty]
|
||||||
|
dotpath = self.content['config']['dotpath']
|
||||||
for k, v in dotfiles.items():
|
for k, v in dotfiles.items():
|
||||||
src = os.path.normpath(v[self.key_dotfiles_src])
|
src = v[self.key_dotfiles_src]
|
||||||
|
if dotpath not in src:
|
||||||
|
src = os.path.join(dotpath, src)
|
||||||
|
src = os.path.normpath(self._abs_path(src))
|
||||||
dst = os.path.normpath(v[self.key_dotfiles_dst])
|
dst = os.path.normpath(v[self.key_dotfiles_dst])
|
||||||
|
|
||||||
# Fail if both `link` and `link_children` present
|
# Fail if both `link` and `link_children` present
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ def load_options(confpath, profile):
|
|||||||
o = Options(args=args)
|
o = Options(args=args)
|
||||||
o.profile = profile
|
o.profile = profile
|
||||||
o.dry = False
|
o.dry = False
|
||||||
o.profile = profile
|
|
||||||
o.safe = True
|
o.safe = True
|
||||||
o.install_diff = True
|
o.install_diff = True
|
||||||
o.import_link = LinkTypes.NOLINK
|
o.import_link = LinkTypes.NOLINK
|
||||||
@@ -221,9 +220,9 @@ def create_yaml_keyval(pairs, parent_dir=None, top_key=None):
|
|||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
|
||||||
def populate_fake_config(config, dotfiles=(), profiles=(), actions=(),
|
def populate_fake_config(config, dotfiles={}, profiles={}, actions={},
|
||||||
trans=(), trans_write=(), variables=(),
|
trans={}, trans_write={}, variables={},
|
||||||
dynvariables=()):
|
dynvariables={}):
|
||||||
"""Adds some juicy content to config files"""
|
"""Adds some juicy content to config files"""
|
||||||
is_path = isinstance(config, str)
|
is_path = isinstance(config, str)
|
||||||
if is_path:
|
if is_path:
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ class TestImport(unittest.TestCase):
|
|||||||
def assert_file(self, path, o, profile):
|
def assert_file(self, path, o, profile):
|
||||||
"""Make sure path has been inserted in conf for profile"""
|
"""Make sure path has been inserted in conf for profile"""
|
||||||
strip = get_path_strip_version(path)
|
strip = get_path_strip_version(path)
|
||||||
self.assertTrue(strip in [x.src for x in o.dotfiles])
|
self.assertTrue(any(x.src.endswith(strip) for x in o.dotfiles))
|
||||||
dsts = [os.path.expanduser(x.dst) for x in o.dotfiles]
|
dsts = (os.path.expanduser(x.dst) for x in o.dotfiles)
|
||||||
self.assertTrue(path in dsts)
|
self.assertTrue(path in dsts)
|
||||||
|
|
||||||
def assert_in_yaml(self, path, dic, link=False):
|
def assert_in_yaml(self, path, dic, link=False):
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ from unittest.mock import MagicMock, patch
|
|||||||
import filecmp
|
import filecmp
|
||||||
|
|
||||||
from dotdrop.config import Cfg
|
from dotdrop.config import Cfg
|
||||||
from tests.helpers import create_dir, get_string, get_tempdir, clean, \
|
from tests.helpers import (clean, create_dir, create_fake_config,
|
||||||
create_random_file, load_options
|
create_random_file, get_string, get_tempdir,
|
||||||
|
load_options, populate_fake_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
|
||||||
@@ -231,6 +232,107 @@ exec bspwm
|
|||||||
tempcontent = open(dst10, 'r').read().rstrip()
|
tempcontent = open(dst10, 'r').read().rstrip()
|
||||||
self.assertTrue(tempcontent == header())
|
self.assertTrue(tempcontent == header())
|
||||||
|
|
||||||
|
def test_install_import_configs(self):
|
||||||
|
"""Test the install function with imported configs"""
|
||||||
|
# dotpath location
|
||||||
|
tmp = get_tempdir()
|
||||||
|
self.assertTrue(os.path.exists(tmp))
|
||||||
|
self.addCleanup(clean, tmp)
|
||||||
|
|
||||||
|
os.mkdir(os.path.join(tmp, 'importing'))
|
||||||
|
os.mkdir(os.path.join(tmp, 'imported'))
|
||||||
|
|
||||||
|
# where dotfiles will be installed
|
||||||
|
dst = get_tempdir()
|
||||||
|
self.assertTrue(os.path.exists(dst))
|
||||||
|
self.addCleanup(clean, dst)
|
||||||
|
|
||||||
|
# creating random dotfiles
|
||||||
|
imported_dotfile, _ = create_random_file(os.path.join(tmp, 'imported'))
|
||||||
|
imported_dotfile = {
|
||||||
|
'dst': os.path.join(dst, imported_dotfile),
|
||||||
|
'key': 'f_{}'.format(imported_dotfile),
|
||||||
|
'name': imported_dotfile,
|
||||||
|
'src': os.path.join(tmp, 'imported', imported_dotfile),
|
||||||
|
}
|
||||||
|
importing_dotfile, _ = \
|
||||||
|
create_random_file(os.path.join(tmp, 'importing'))
|
||||||
|
importing_dotfile = {
|
||||||
|
'dst': os.path.join(dst, importing_dotfile),
|
||||||
|
'key': 'f_{}'.format(importing_dotfile),
|
||||||
|
'name': importing_dotfile,
|
||||||
|
'src': os.path.join(tmp, 'imported', importing_dotfile),
|
||||||
|
}
|
||||||
|
|
||||||
|
imported = {
|
||||||
|
'config': {
|
||||||
|
'dotpath': 'imported',
|
||||||
|
},
|
||||||
|
'dotfiles': {
|
||||||
|
imported_dotfile['key']: {
|
||||||
|
'dst': imported_dotfile['dst'],
|
||||||
|
'src': imported_dotfile['name'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'profiles': {
|
||||||
|
'host1': {
|
||||||
|
'dotfiles': [imported_dotfile['key']],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
importing = {
|
||||||
|
'config': {
|
||||||
|
'dotpath': 'importing',
|
||||||
|
},
|
||||||
|
'dotfiles': {
|
||||||
|
importing_dotfile['key']: {
|
||||||
|
'dst': importing_dotfile['dst'],
|
||||||
|
'src': importing_dotfile['src'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'profiles': {
|
||||||
|
'host2': {
|
||||||
|
'dotfiles': [importing_dotfile['key']],
|
||||||
|
'include': ['host1'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# create the imported base config file
|
||||||
|
imported_path = create_fake_config(tmp,
|
||||||
|
configname='config-2.yaml',
|
||||||
|
**imported['config'])
|
||||||
|
# create the importing base config file
|
||||||
|
importing_path = create_fake_config(tmp,
|
||||||
|
configname='config.yaml',
|
||||||
|
import_configs=('config-*.yaml',),
|
||||||
|
**importing['config'])
|
||||||
|
|
||||||
|
# edit the imported config
|
||||||
|
populate_fake_config(imported_path, **{
|
||||||
|
k: v
|
||||||
|
for k, v in imported.items()
|
||||||
|
if k != 'config'
|
||||||
|
})
|
||||||
|
|
||||||
|
# edit the importing config
|
||||||
|
populate_fake_config(importing_path, **{
|
||||||
|
k: v
|
||||||
|
for k, v in importing.items()
|
||||||
|
if k != 'config'
|
||||||
|
})
|
||||||
|
|
||||||
|
# install them
|
||||||
|
o = load_options(importing_path, 'host2')
|
||||||
|
o.safe = False
|
||||||
|
o.install_showdiff = True
|
||||||
|
o.variables = {}
|
||||||
|
cmd_install(o)
|
||||||
|
|
||||||
|
# now compare the generated files
|
||||||
|
self.assertTrue(os.path.exists(importing_dotfile['dst']))
|
||||||
|
self.assertTrue(os.path.exists(imported_dotfile['dst']))
|
||||||
|
|
||||||
def test_link_children(self):
|
def test_link_children(self):
|
||||||
"""test the link children"""
|
"""test the link children"""
|
||||||
# create source dir
|
# create source dir
|
||||||
|
|||||||
Reference in New Issue
Block a user