Skip to content

Commit

Permalink
Merge pull request #19 from arcticicestudio/bugfix/ghi-#18-only-last-…
Browse files Browse the repository at this point in the history
…duplicate-link-item-processed-when-using-host-specific-option

#18 Only last duplicate link item processed when using host specific option
  • Loading branch information
arcticicestudio authored Jan 28, 2017
2 parents e318b8d + d4ed045 commit b921c48
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions snowsaw/plugins/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _process_links(self, links):
force = defaults.get("force", False)
relink = defaults.get("relink", False)
create = defaults.get("create", False)
hosts = defaults.get("hosts", [])
hosts = defaults.get("hosts", {})
if isinstance(source, dict):
relative = source.get("relative", relative)
force = source.get("force", force)
Expand All @@ -46,9 +46,13 @@ def _process_links(self, links):
path = self._default_source(destination, source)
path = os.path.expandvars(os.path.expanduser(path))

if not self._is_target_host(hosts, hostname):
self._log.lowinfo("Skipped host specific link {} -> {}".format(destination, os.path.join(self._context.snowblock_dir(), path)))
continue
if hosts:
for host in hosts.items():
if not host[0] == hostname:
self._log.lowinfo("Skipped host specific link {} -> {}".format(destination, os.path.join(self._context.snowblock_dir(), host[1])))
continue
else:
path = os.path.expandvars(os.path.expanduser(hosts.get(hostname)))

if not self._exists(os.path.join(self._context.snowblock_dir(), path)):
success = False
Expand Down Expand Up @@ -97,18 +101,6 @@ def _is_link(self, path):
"""
return os.path.islink(os.path.expanduser(path))

def _is_target_host(self, hosts, host):
"""
Checks if the specified host is a target.
A empty default list of target hosts indicates that all hosts are allowed.
:param hosts: The list of target hosts
:param host: The name of the host to check
:return: True if the specified host is listed or the hosts list is empty, False otherwise
"""
return True if not hosts or host in hosts else False

def _link_destination(self, path):
"""
Gets the destination of the specified symbolic link.
Expand Down

0 comments on commit b921c48

Please sign in to comment.