mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 20:19:46 +00:00
adding keepdot option for #43
This commit is contained in:
@@ -443,13 +443,14 @@ the following entries:
|
||||
|
||||
* **config** entry: contains settings for the deployment
|
||||
* `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
|
||||
it doesn't exist
|
||||
it doesn't exist (default *true*)
|
||||
* `dotpath`: path to the directory containing the dotfiles to be managed
|
||||
by dotdrop (absolute path or relative to the config file location)
|
||||
* `banner`: display the banner
|
||||
* `longkey`: use long keys for dotfiles when importing
|
||||
* `banner`: display the banner (default *true*)
|
||||
* `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
|
||||
* 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.
|
||||
|
||||
@@ -27,6 +27,7 @@ class Cfg:
|
||||
key_create = 'create'
|
||||
key_banner = 'banner'
|
||||
key_long = 'longkey'
|
||||
key_keepdot = 'keepdot'
|
||||
|
||||
# actions keys
|
||||
key_actions = 'actions'
|
||||
@@ -55,6 +56,7 @@ class Cfg:
|
||||
default_banner = True
|
||||
default_link = False
|
||||
default_longkey = False
|
||||
default_keepdot = False
|
||||
|
||||
def __init__(self, cfgpath):
|
||||
if not os.path.exists(cfgpath):
|
||||
@@ -281,6 +283,8 @@ class Cfg:
|
||||
self.lnk_settings[self.key_banner] = self.default_banner
|
||||
if self.key_long not in self.lnk_settings:
|
||||
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):
|
||||
"""transform path to an absolute path based on config path"""
|
||||
@@ -473,16 +477,10 @@ class Cfg:
|
||||
# temporary reset dotpath
|
||||
dotpath = self.lnk_settings[self.key_dotpath]
|
||||
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
|
||||
ret = yaml.dump(self.content, default_flow_style=False, indent=2)
|
||||
# restore 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
|
||||
|
||||
def save(self):
|
||||
@@ -490,14 +488,8 @@ class Cfg:
|
||||
# temporary reset dotpath
|
||||
dotpath = self.lnk_settings[self.key_dotpath]
|
||||
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
|
||||
ret = self._save(self.content, self.cfgpath)
|
||||
# restore 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
|
||||
|
||||
@@ -239,7 +239,10 @@ def importer(opts, conf, paths):
|
||||
src = dst
|
||||
if dst.startswith(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
|
||||
dotfile = Dotfile('', dst, src)
|
||||
|
||||
Reference in New Issue
Block a user