mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 10:48:00 +00:00
adding key_prefix and key_separator for #335
This commit is contained in:
@@ -28,7 +28,6 @@ class CfgAggregator:
|
||||
|
||||
file_prefix = 'f'
|
||||
dir_prefix = 'd'
|
||||
key_sep = '_'
|
||||
|
||||
def __init__(self, path, profile_key, debug=False, dry=False):
|
||||
"""
|
||||
@@ -228,6 +227,8 @@ class CfgAggregator:
|
||||
|
||||
# settings
|
||||
self.settings = Settings.parse(None, self.cfgyaml.settings)
|
||||
self.key_prefix = self.settings.key_prefix
|
||||
self.key_separator = self.settings.key_separator
|
||||
|
||||
# dotfiles
|
||||
self.dotfiles = Dotfile.parse_dict(self.cfgyaml.dotfiles)
|
||||
@@ -333,8 +334,12 @@ class CfgAggregator:
|
||||
absolute path of path
|
||||
"""
|
||||
dirs = self._split_path_for_key(path)
|
||||
prefix = self.dir_prefix if os.path.isdir(path) else self.file_prefix
|
||||
key = self.key_sep.join([prefix] + dirs)
|
||||
prefix = []
|
||||
if self.key_prefix:
|
||||
prefix = [self.file_prefix]
|
||||
if os.path.isdir(path):
|
||||
prefix = [self.dir_prefix]
|
||||
key = self.key_separator.join(prefix + dirs)
|
||||
return self._uniq_key(key, keys)
|
||||
|
||||
def _get_short_key(self, path, keys):
|
||||
@@ -344,11 +349,15 @@ class CfgAggregator:
|
||||
"""
|
||||
dirs = self._split_path_for_key(path)
|
||||
dirs.reverse()
|
||||
prefix = self.dir_prefix if os.path.isdir(path) else self.file_prefix
|
||||
prefix = []
|
||||
if self.key_prefix:
|
||||
prefix = [self.file_prefix]
|
||||
if os.path.isdir(path):
|
||||
prefix = [self.dir_prefix]
|
||||
entries = []
|
||||
for dri in dirs:
|
||||
entries.insert(0, dri)
|
||||
key = self.key_sep.join([prefix] + entries)
|
||||
key = self.key_separator.join(prefix + entries)
|
||||
if key not in keys:
|
||||
return key
|
||||
return self._uniq_key(key, keys)
|
||||
@@ -360,7 +369,7 @@ class CfgAggregator:
|
||||
while newkey in keys:
|
||||
# if unable to get a unique path
|
||||
# get a random one
|
||||
newkey = self.key_sep.join([key, str(cnt)])
|
||||
newkey = self.key_separator.join([key, str(cnt)])
|
||||
cnt += 1
|
||||
return newkey
|
||||
|
||||
|
||||
@@ -134,6 +134,8 @@ class Options(AttrMonitor):
|
||||
self.chmod_on_import = None
|
||||
self.check_version = None
|
||||
self.clear_workdir = None
|
||||
self.key_prefix = None
|
||||
self.key_separator = None
|
||||
|
||||
# args parsing
|
||||
self.args = {}
|
||||
@@ -223,8 +225,9 @@ class Options(AttrMonitor):
|
||||
self.conf = Cfg(self.confpath, self.profile, debug=self.debug,
|
||||
dry=self.dry)
|
||||
# transform the config settings to self attribute
|
||||
debug_dict('effective settings', self.conf.get_settings(), self.debug)
|
||||
for k, val in self.conf.get_settings().items():
|
||||
settings = self.conf.get_settings()
|
||||
debug_dict('effective settings', settings, self.debug)
|
||||
for k, val in settings.items():
|
||||
setattr(self, k, val)
|
||||
|
||||
def _apply_args_files(self):
|
||||
|
||||
@@ -48,6 +48,8 @@ class Settings(DictParser):
|
||||
key_check_version = 'check_version'
|
||||
key_clear_workdir = 'clear_workdir'
|
||||
key_compare_workdir = 'compare_workdir'
|
||||
key_key_prefix = 'key_prefix'
|
||||
key_key_separator = 'key_separator'
|
||||
|
||||
# import keys
|
||||
key_import_actions = 'import_actions'
|
||||
@@ -69,7 +71,8 @@ class Settings(DictParser):
|
||||
ignore_missing_in_dotdrop=False,
|
||||
force_chmod=False, chmod_on_import=False,
|
||||
check_version=False, clear_workdir=False,
|
||||
compare_workdir=False):
|
||||
compare_workdir=False, key_prefix=True,
|
||||
key_separator='_'):
|
||||
self.backup = backup
|
||||
self.banner = banner
|
||||
self.create = create
|
||||
@@ -102,6 +105,8 @@ class Settings(DictParser):
|
||||
self.check_version = check_version
|
||||
self.clear_workdir = clear_workdir
|
||||
self.compare_workdir = compare_workdir
|
||||
self.key_prefix = key_prefix
|
||||
self.key_separator = key_separator
|
||||
|
||||
def _serialize_seq(self, name, dic):
|
||||
"""serialize attribute 'name' into 'dic'"""
|
||||
@@ -131,6 +136,8 @@ class Settings(DictParser):
|
||||
self.key_check_version: self.check_version,
|
||||
self.key_clear_workdir: self.clear_workdir,
|
||||
self.key_compare_workdir: self.compare_workdir,
|
||||
self.key_key_prefix: self.key_prefix,
|
||||
self.key_key_separator: self.key_separator,
|
||||
}
|
||||
self._serialize_seq(self.key_default_actions, dic)
|
||||
self._serialize_seq(self.key_import_actions, dic)
|
||||
|
||||
@@ -246,7 +246,7 @@ def must_ignore(paths, ignores, debug=False):
|
||||
nign = nign[1:]
|
||||
if debug:
|
||||
msg = 'trying to match :\"{}\" with non-ignore-pattern:\"{}\"'
|
||||
LOG.dbg(msg.format(path, nign))
|
||||
LOG.dbg(msg.format(path, nign), force=True)
|
||||
if fnmatch.fnmatch(path, nign):
|
||||
if debug:
|
||||
msg = 'negative ignore \"{}\" match: {}'.format(nign, path)
|
||||
@@ -444,23 +444,23 @@ def debug_list(title, elems, debug):
|
||||
"""pretty print list"""
|
||||
if not debug:
|
||||
return
|
||||
LOG.dbg('{}:'.format(title))
|
||||
LOG.dbg('{}:'.format(title), force=debug)
|
||||
for elem in elems:
|
||||
LOG.dbg('\t- {}'.format(elem))
|
||||
LOG.dbg('\t- {}'.format(elem), force=debug)
|
||||
|
||||
|
||||
def debug_dict(title, elems, debug):
|
||||
"""pretty print dict"""
|
||||
if not debug:
|
||||
return
|
||||
LOG.dbg('{}:'.format(title))
|
||||
LOG.dbg('{}:'.format(title), force=debug)
|
||||
for k, val in elems.items():
|
||||
if isinstance(val, list):
|
||||
LOG.dbg('\t- \"{}\":'.format(k))
|
||||
LOG.dbg('\t- \"{}\":'.format(k), force=debug)
|
||||
for i in val:
|
||||
LOG.dbg('\t\t- {}'.format(i))
|
||||
LOG.dbg('\t\t- {}'.format(i), force=debug)
|
||||
else:
|
||||
LOG.dbg('\t- \"{}\": {}'.format(k, val))
|
||||
LOG.dbg('\t- \"{}\": {}'.format(k, val), force=debug)
|
||||
|
||||
|
||||
def check_version():
|
||||
|
||||
Reference in New Issue
Block a user