mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 05:39:43 +00:00
implement user input for #318
This commit is contained in:
@@ -206,10 +206,11 @@ class CfgAggregator:
|
||||
# parsing
|
||||
########################################################
|
||||
|
||||
def _load(self):
|
||||
def _load(self, reloading=False):
|
||||
"""load lower level config"""
|
||||
self.cfgyaml = CfgYaml(self.path,
|
||||
self.profile_key,
|
||||
reloading=reloading,
|
||||
debug=self.debug)
|
||||
|
||||
# settings
|
||||
@@ -361,7 +362,7 @@ class CfgAggregator:
|
||||
self.log.dbg('reloading config')
|
||||
olddebug = self.debug
|
||||
self.debug = False
|
||||
self._load()
|
||||
self._load(reloading=True)
|
||||
self.debug = olddebug
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -33,7 +33,7 @@ from dotdrop.settings import Settings
|
||||
from dotdrop.logger import Logger
|
||||
from dotdrop.templategen import Templategen
|
||||
from dotdrop.linktypes import LinkTypes
|
||||
from dotdrop.utils import shellrun, uniq_list
|
||||
from dotdrop.utils import shellrun, uniq_list, userinput
|
||||
from dotdrop.exceptions import YamlException, UndefinedException
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class CfgYaml:
|
||||
key_trans_w = 'trans_write'
|
||||
key_variables = 'variables'
|
||||
key_dvariables = 'dynvariables'
|
||||
key_uvariables = 'uservariables'
|
||||
|
||||
action_pre = 'pre'
|
||||
action_post = 'post'
|
||||
@@ -98,16 +99,19 @@ class CfgYaml:
|
||||
allowed_link_val = [lnk_nolink, lnk_link, lnk_children]
|
||||
top_entries = [key_dotfiles, key_settings, key_profiles]
|
||||
|
||||
def __init__(self, path, profile=None, addprofiles=None, debug=False):
|
||||
def __init__(self, path, profile=None, addprofiles=None,
|
||||
reloading=False, debug=False):
|
||||
"""
|
||||
config parser
|
||||
@path: config file path
|
||||
@profile: the selected profile
|
||||
@addprofiles: included profiles
|
||||
@reloading: true when reloading
|
||||
@debug: debug flag
|
||||
"""
|
||||
self._path = os.path.abspath(path)
|
||||
self._profile = profile
|
||||
self._reloading = reloading
|
||||
self._debug = debug
|
||||
self._log = Logger(debug=self._debug)
|
||||
# config needs to be written
|
||||
@@ -163,6 +167,10 @@ class CfgYaml:
|
||||
dvariables = self._parse_blk_dynvariables(self._yaml_dict)
|
||||
self._add_variables(dvariables, template=False)
|
||||
|
||||
# parse the "uservariables" block
|
||||
uvariables = self._parse_blk_uservariables(self._yaml_dict)
|
||||
self._add_variables(uvariables, template=False)
|
||||
|
||||
# now template variables and dynvariables from the same pool
|
||||
self._rec_resolve_variables(self.variables)
|
||||
# and execute dvariables
|
||||
@@ -565,6 +573,24 @@ class CfgYaml:
|
||||
self._debug_dict('dynvariables block', dvariables)
|
||||
return dvariables
|
||||
|
||||
def _parse_blk_uservariables(self, dic):
|
||||
"""parse the "uservariables" block"""
|
||||
uvariables = self._get_entry(dic,
|
||||
self.key_uvariables,
|
||||
mandatory=False)
|
||||
|
||||
uvars = {}
|
||||
if not self._reloading and uvariables:
|
||||
for k, v in uvariables.items():
|
||||
content = userinput(v, debug=self._debug)
|
||||
uvars[k] = content
|
||||
|
||||
if uvars:
|
||||
uvars = uvars.copy()
|
||||
if self._debug:
|
||||
self._debug_dict('uservariables block', uvars)
|
||||
return uvars
|
||||
|
||||
########################################################
|
||||
# parsing helpers
|
||||
########################################################
|
||||
|
||||
@@ -69,6 +69,20 @@ def shellrun(cmd, debug=False):
|
||||
return ret == 0, out
|
||||
|
||||
|
||||
def userinput(prompt, debug=False):
|
||||
"""
|
||||
get user input
|
||||
return user input
|
||||
"""
|
||||
if debug:
|
||||
LOG.dbg('get user input for \"{}\"'.format(prompt), force=True)
|
||||
pre = 'Please provide the value for \"{}\": '.format(prompt)
|
||||
res = input(pre)
|
||||
if debug:
|
||||
LOG.dbg('user input result: {}'.format(res), force=True)
|
||||
return res
|
||||
|
||||
|
||||
def fastdiff(left, right):
|
||||
"""fast compare files and returns True if different"""
|
||||
return not filecmp.cmp(left, right, shallow=False)
|
||||
|
||||
Reference in New Issue
Block a user