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

adding keepdot option for #43

This commit is contained in:
deadc0de6
2018-06-06 08:49:57 +02:00
parent 70e82dcfdb
commit 15391d9cad
3 changed files with 13 additions and 17 deletions

View File

@@ -443,13 +443,14 @@ the following entries:
* **config** entry: contains settings for the deployment * **config** entry: contains settings for the deployment
* `backup`: create a backup of the dotfile in case it differs from the * `backup`: create a backup of the dotfile in case it differs from the
one that will be installed by dotdrop one that will be installed by dotdrop (default *true*)
* `create`: create directory hierarchy when installing dotfiles if * `create`: create directory hierarchy when installing dotfiles if
it doesn't exist it doesn't exist (default *true*)
* `dotpath`: path to the directory containing the dotfiles to be managed * `dotpath`: path to the directory containing the dotfiles to be managed
by dotdrop (absolute path or relative to the config file location) by dotdrop (absolute path or relative to the config file location)
* `banner`: display the banner * `banner`: display the banner (default *true*)
* `longkey`: use long keys for dotfiles when importing * `longkey`: use long keys for dotfiles when importing (default *false*)
* `keepdot`: preserve leading dot when importing hidden file in the `dotpath` (default *false*)
* **dotfiles** entry: a list of dotfiles * **dotfiles** entry: a list of dotfiles
* When `link` is true, dotdrop will create a symlink instead of copying. Template generation (as in [template](#template)) is not supported when `link` is true. * When `link` is true, dotdrop will create a symlink instead of copying. Template generation (as in [template](#template)) is not supported when `link` is true.

View File

@@ -27,6 +27,7 @@ class Cfg:
key_create = 'create' key_create = 'create'
key_banner = 'banner' key_banner = 'banner'
key_long = 'longkey' key_long = 'longkey'
key_keepdot = 'keepdot'
# actions keys # actions keys
key_actions = 'actions' key_actions = 'actions'
@@ -55,6 +56,7 @@ class Cfg:
default_banner = True default_banner = True
default_link = False default_link = False
default_longkey = False default_longkey = False
default_keepdot = False
def __init__(self, cfgpath): def __init__(self, cfgpath):
if not os.path.exists(cfgpath): if not os.path.exists(cfgpath):
@@ -281,6 +283,8 @@ class Cfg:
self.lnk_settings[self.key_banner] = self.default_banner self.lnk_settings[self.key_banner] = self.default_banner
if self.key_long not in self.lnk_settings: if self.key_long not in self.lnk_settings:
self.lnk_settings[self.key_long] = self.default_longkey self.lnk_settings[self.key_long] = self.default_longkey
if self.key_keepdot not in self.lnk_settings:
self.lnk_settings[self.key_keepdot] = self.default_keepdot
def get_abs(self, path): def get_abs(self, path):
"""transform path to an absolute path based on config path""" """transform path to an absolute path based on config path"""
@@ -473,16 +477,10 @@ class Cfg:
# temporary reset dotpath # temporary reset dotpath
dotpath = self.lnk_settings[self.key_dotpath] dotpath = self.lnk_settings[self.key_dotpath]
self.lnk_settings[self.key_dotpath] = self.curdotpath self.lnk_settings[self.key_dotpath] = self.curdotpath
# reset banner
if self.lnk_settings[self.key_banner]:
del self.lnk_settings[self.key_banner]
# dump # dump
ret = yaml.dump(self.content, default_flow_style=False, indent=2) ret = yaml.dump(self.content, default_flow_style=False, indent=2)
# restore dotpath # restore dotpath
self.lnk_settings[self.key_dotpath] = dotpath self.lnk_settings[self.key_dotpath] = dotpath
# restore banner
if self.key_banner not in self.lnk_settings:
self.lnk_settings[self.key_banner] = self.default_banner
return ret return ret
def save(self): def save(self):
@@ -490,14 +488,8 @@ class Cfg:
# temporary reset dotpath # temporary reset dotpath
dotpath = self.lnk_settings[self.key_dotpath] dotpath = self.lnk_settings[self.key_dotpath]
self.lnk_settings[self.key_dotpath] = self.curdotpath self.lnk_settings[self.key_dotpath] = self.curdotpath
# reset banner
if self.lnk_settings[self.key_banner]:
del self.lnk_settings[self.key_banner]
# save # save
ret = self._save(self.content, self.cfgpath) ret = self._save(self.content, self.cfgpath)
# restore dotpath # restore dotpath
self.lnk_settings[self.key_dotpath] = dotpath self.lnk_settings[self.key_dotpath] = dotpath
# restore banner
if self.key_banner not in self.lnk_settings:
self.lnk_settings[self.key_banner] = self.default_banner
return ret return ret

View File

@@ -239,7 +239,10 @@ def importer(opts, conf, paths):
src = dst src = dst
if dst.startswith(home): if dst.startswith(home):
src = dst[len(home):] src = dst[len(home):]
src = src.lstrip('.' + os.sep) strip = '.' + os.sep
if opts['keepdot']:
strip = os.sep
src = src.lstrip(strip)
# create a new dotfile # create a new dotfile
dotfile = Dotfile('', dst, src) dotfile = Dotfile('', dst, src)