From d2e20c77db3811d8d0ef640a743f8dcc85075fdc Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 18 Nov 2016 15:21:27 -0800 Subject: Allow empty link sources If the source for a link is null, use the basename of the destination with a single leading '.' removed, if present. --- plugins/link.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/link.py b/plugins/link.py index ff8685e..ee64175 100644 --- a/plugins/link.py +++ b/plugins/link.py @@ -30,9 +30,9 @@ class Link(dotbot.Plugin): force = source.get('force', force) relink = source.get('relink', relink) create = source.get('create', create) - path = source['path'] + path = self._default_source(destination, source.get('path')) else: - path = source + path = self._default_source(destination, source) path = os.path.expandvars(os.path.expanduser(path)) if create: success &= self._create(destination) @@ -46,6 +46,16 @@ class Link(dotbot.Plugin): self._log.error('Some links were not successfully set up') return success + def _default_source(self, destination, source): + if source is None: + basename = os.path.basename(destination) + if basename.startswith('.'): + return basename[1:] + else: + return basename + else: + return source + def _is_link(self, path): ''' Returns true if the path is a symbolic link. -- cgit v1.2.3