mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 15:27:59 +00:00
adding dynamic/interpreted template variables
This commit is contained in:
@@ -13,6 +13,7 @@ import shlex
|
||||
from dotdrop.dotfile import Dotfile
|
||||
from dotdrop.logger import Logger
|
||||
from dotdrop.action import Action, Transform
|
||||
from dotdrop.utils import *
|
||||
|
||||
|
||||
TILD = '~'
|
||||
@@ -44,6 +45,8 @@ class Cfg:
|
||||
|
||||
# template variables
|
||||
key_variables = 'variables'
|
||||
# shell variable
|
||||
key_dynvariables = 'dynvariables'
|
||||
|
||||
# dotfiles keys
|
||||
key_dotfiles = 'dotfiles'
|
||||
@@ -521,9 +524,15 @@ class Cfg:
|
||||
return self.lnk_settings.copy()
|
||||
|
||||
def get_variables(self):
|
||||
variables = {}
|
||||
if self.key_variables in self.content:
|
||||
return self.content[self.key_variables]
|
||||
return {}
|
||||
variables.update(self.content[self.key_variables])
|
||||
if self.key_dynvariables in self.content:
|
||||
# interpret dynamic variables
|
||||
dynvars = self.content[self.key_dynvariables]
|
||||
for key, cmd in dynvars.items():
|
||||
variables[key] = shell(cmd)
|
||||
return variables
|
||||
|
||||
def dump(self):
|
||||
"""return a dump of the config"""
|
||||
|
||||
@@ -19,7 +19,7 @@ LOG = Logger()
|
||||
|
||||
|
||||
def run(cmd, raw=True, debug=False, checkerr=False):
|
||||
"""run a command in the shell (expects a list)"""
|
||||
"""run a command (expects a list)"""
|
||||
if debug:
|
||||
LOG.dbg('exec: {}'.format(' '.join(cmd)))
|
||||
p = subprocess.Popen(cmd, shell=False,
|
||||
@@ -38,6 +38,11 @@ def run(cmd, raw=True, debug=False, checkerr=False):
|
||||
return ret == 0, lines
|
||||
|
||||
|
||||
def shell(cmd):
|
||||
"""run a command in the shell (expects a string)"""
|
||||
return subprocess.getoutput(cmd)
|
||||
|
||||
|
||||
def diff(src, dst, raw=True, opts='', debug=False):
|
||||
"""call unix diff to compare two files"""
|
||||
cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, src, dst)
|
||||
|
||||
Reference in New Issue
Block a user