From dd144a2044319e3d7d99bed499188c0df09d8fc1 Mon Sep 17 00:00:00 2001 From: Brian Knobbs Date: Wed, 6 May 2015 18:02:31 -0400 Subject: [PATCH] Added the ability to use environment variables in link paths, and setup the HOSTNAME environment variable if it isn't already set. This makes linking host specific configs very easy --- dotbot/cli.py | 4 ++++ dotbot/executor/linker.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dotbot/cli.py b/dotbot/cli.py index dc90909..c0e4365 100644 --- a/dotbot/cli.py +++ b/dotbot/cli.py @@ -1,3 +1,5 @@ +import os +import socket from argparse import ArgumentParser from .config import ConfigReader, ReadingError from .dispatcher import Dispatcher, DispatchError @@ -24,6 +26,8 @@ def read_config(config_file): def main(): log = Messenger() + + os.environ.setdefault("HOSTNAME", socket.gethostname()) try: parser = ArgumentParser() add_options(parser) diff --git a/dotbot/executor/linker.py b/dotbot/executor/linker.py index f0e94bc..729c7a1 100644 --- a/dotbot/executor/linker.py +++ b/dotbot/executor/linker.py @@ -107,7 +107,7 @@ class Linker(Executor): Returns true if successfully linked files. ''' success = False - source = os.path.join(self._base_directory, source) + source = os.path.expandvars(os.path.join(self._base_directory, source)) if (not self._exists(link_name) and self._is_link(link_name) and self._link_destination(link_name) != source): self._log.warning('Invalid link %s -> %s' %