From 4415d2f81d48243798cce7df1863a4ca8f7f1ae8 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Thu, 15 Nov 2018 18:27:07 +0100 Subject: [PATCH] adding command to list dotfiles details (#65) --- dotdrop/dotdrop.py | 53 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 3fe14eb..0c5f860 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -48,6 +48,7 @@ Usage: [-o ] [-C ...] [-i ...] dotdrop update [-fdVbk] [-c ] [-p ] [...] dotdrop listfiles [-VTb] [-c ] [-p ] + dotdrop detail [-Vb] [-c ] [-p ] [...] dotdrop list [-Vb] [-c ] dotdrop --help dotdrop --version @@ -311,22 +312,58 @@ def cmd_list_files(opts, conf, templateonly=False): what = 'Dotfile(s)' if templateonly: what = 'Template(s)' - LOG.log('{} for profile \"{}\":\n'.format(what, opts['profile'])) + LOG.emph('{} for profile \"{}\"\n'.format(what, opts['profile'])) for dotfile in conf.get_dotfiles(opts['profile']): if templateonly: - p = os.path.join(opts['dotpath'], dotfile.src) - if not Templategen.is_template(p): + src = os.path.join(opts['dotpath'], dotfile.src) + if not Templategen.is_template(src): continue - LOG.log('{} (file: \"{}\", link: {})'.format(dotfile.key, dotfile.src, - dotfile.link)) + LOG.log('{} (src: \"{}\", link: {})'.format(dotfile.key, dotfile.src, + dotfile.link)) LOG.sub('{}'.format(dotfile.dst)) LOG.log('') + +def cmd_detail(opts, conf, keys=None): + """list details on all files for all dotfile entries""" + if not opts['profile'] in conf.get_profiles(): + LOG.warn('unknown profile \"{}\"'.format(opts['profile'])) + return + dotfiles = conf.get_dotfiles(opts['profile']) + if keys: + # filtered dotfiles to install + dotfiles = [d for d in dotfiles if d.key in set(keys)] + LOG.emph('dotfiles details for profile \"{}\":\n'.format(opts['profile'])) + for d in dotfiles: + _detail(opts['dotpath'], d) + LOG.log('') + + ########################################################### # helpers ########################################################### +def _detail(dotpath, dotfile): + """print details on all files under a dotfile entry""" + LOG.log('{} (dst: \"{}\", link: {})'.format(dotfile.key, dotfile.dst, + dotfile.link)) + path = os.path.join(dotpath, os.path.expanduser(dotfile.src)) + if not os.path.isdir(path): + template = 'no' + if Templategen.is_template(path): + template = 'yes' + LOG.sub('{} (template:{})'.format(path, template)) + else: + for root, dir, files in os.walk(path): + for f in files: + p = os.path.join(root, f) + template = 'no' + if Templategen.is_template(p): + template = 'yes' + LOG.sub('{} (template:{})'.format(p, template)) + + def _header(): """print the header""" LOG.log(BANNER) @@ -451,6 +488,12 @@ def main(): iskey = args['--key'] ret = cmd_update(opts, conf, args[''], iskey=iskey) + elif args['detail']: + # detail files + if opts['debug']: + LOG.dbg('running cmd: update') + cmd_detail(opts, conf, keys=args['']) + except KeyboardInterrupt: LOG.err('interrupted') ret = False