From 092588b961b51637235553ba6f4eaf3d6703b7ae Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 1 Sep 2018 19:38:56 +0200 Subject: [PATCH] add base for linking templates --- dotdrop/installer.py | 22 ++++++++++++++++++++++ dotdrop/updater.py | 2 -- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 22ba64e..1ca0595 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -10,12 +10,15 @@ import os # local imports from dotdrop.logger import Logger from dotdrop.comparator import Comparator +from dotdrop.templategen import Templategen import dotdrop.utils as utils class Installer: BACKUP_SUFFIX = '.dotdropbak' + # TODO get this from the config file with a default + DOTDROP_WORK = '{}/.config/dotdrop'.format(os.path.expanduser('~')) def __init__(self, base='.', create=True, backup=True, dry=False, safe=False, debug=False, diff=True): @@ -29,6 +32,9 @@ class Installer: self.comparing = False self.log = Logger() + def _dotdrop_work(self): + os.makedirs(self.DOTDROP_WORK, exist_ok=True) + def install(self, templater, src, dst): """install the src to dst using a template""" src = os.path.join(self.base, os.path.expanduser(src)) @@ -47,6 +53,22 @@ class Installer: """set src as the link target of dst""" src = os.path.join(self.base, os.path.expanduser(src)) dst = os.path.join(self.base, os.path.expanduser(dst)) + + if Templategen.is_template(src): + # TODO + # first make sure the template is generated in the working dir + + # if it's not generate it + + # and then symlink it as any other file + # by udating src and dst + + else: + # is not a template + self._link(src, dst) + + def _link(self, src, dst): + """set src as a link target of dst""" if os.path.lexists(dst): if os.path.realpath(dst) == os.path.realpath(src): if self.debug: diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 3dcd57d..129d0e8 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -19,8 +19,6 @@ TILD = '~' class Updater: - BACKUP_SUFFIX = '.dotdropbak' - def __init__(self, conf, dotpath, dry, safe, debug): self.home = os.path.expanduser(TILD) self.conf = conf