1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-16 21:59:11 +00:00

Changing arg from config keys to file dst

This commit is contained in:
Japorized
2017-08-28 16:41:18 +08:00
parent a6cc47a517
commit a8c9c638b8

View File

@@ -32,7 +32,7 @@ USAGE = """
Usage: Usage:
dotdrop.py install [--profile=<profile>] [--cfg=<path>] dotdrop.py install [--profile=<profile>] [--cfg=<path>]
[(-f | --force)] [--nodiff] [--dry] [(-f | --force)] [--nodiff] [--dry]
dotdrop.py compare [--profile=<profile>] [--cfg=<path>] [--files=<file key>] dotdrop.py compare [--profile=<profile>] [--cfg=<path>] [--files=<filelist>]
dotdrop.py list [--cfg=<path>] dotdrop.py list [--cfg=<path>]
dotdrop.py import [--profile=<profile>] [--cfg=<path>] dotdrop.py import [--profile=<profile>] [--cfg=<path>]
[(-l | --link)] [--dry] <paths>... [(-l | --link)] [--dry] <paths>...
@@ -42,6 +42,7 @@ Usage:
Options: Options:
--profile=<profiles> Specify the profile to use [default: %s]. --profile=<profiles> Specify the profile to use [default: %s].
--cfg=<path> Path to the config [default: %s/config.yaml]. --cfg=<path> Path to the config [default: %s/config.yaml].
--files=<filelist> Comma separated list of file to compare.
--dry Dry run. --dry Dry run.
--nodiff Do not diff when installing [default: False]. --nodiff Do not diff when installing [default: False].
-l --link Import and link [default: False]. -l --link Import and link [default: False].
@@ -77,7 +78,7 @@ def install(opts, conf):
return True return True
def compare(opts, conf, tmp, focus=""): def compare(opts, conf, tmp, focus=None):
dotfiles = conf.get_dotfiles(opts['profile']) dotfiles = conf.get_dotfiles(opts['profile'])
if dotfiles == []: if dotfiles == []:
LOG.err('no dotfiles defined for this profile (\"%s\")' % LOG.err('no dotfiles defined for this profile (\"%s\")' %
@@ -87,30 +88,18 @@ def compare(opts, conf, tmp, focus=""):
inst = Installer(create=opts['create'], backup=opts['backup'], inst = Installer(create=opts['create'], backup=opts['backup'],
dry=opts['dry'], base=opts['dotpath'], quiet=True) dry=opts['dry'], base=opts['dotpath'], quiet=True)
# Selected files or directory must be comma separated without whitespace. # compare only specific files
# We will also make sure that the given arguments match the dotfile keys selected = dotfiles
# in the config file. If a key is not found, terminate the script and if focus:
# let the user know.
if focus is not None:
focus = focus.replace(" ", "")
selected = focus.split(",")
for selection in selected:
exist = False
for dotfile in dotfiles:
if selection == dotfile.key:
exist = True
break
if not exist:
LOG.log('One of the keys is not found. Please double check ' \
'your arguments.')
sys.exit(0)
else:
selected = [] selected = []
for dotfile in dotfiles: for selection in focus.replace(' ', '').split(','):
selected.append(dotfile.key) df = next((x for x in dotfiles if x.dst == selection), None)
if df:
selected.append(df)
else:
LOG.err('no dotfile matches \"%s\"' % (selection))
for dotfile in dotfiles: for dotfile in selected:
if dotfile.key in selected:
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst)) LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst) inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst)
return len(dotfiles) > 0 return len(dotfiles) > 0
@@ -183,7 +172,6 @@ if __name__ == '__main__':
ret = True ret = True
args = docopt(USAGE, version=VERSION) args = docopt(USAGE, version=VERSION)
conf = Cfg(args['--cfg']) conf = Cfg(args['--cfg'])
focus = args['--files']
opts = conf.get_configs() opts = conf.get_configs()
opts['dry'] = args['--dry'] opts['dry'] = args['--dry']
@@ -204,7 +192,7 @@ if __name__ == '__main__':
elif args['compare']: elif args['compare']:
tmp = utils.get_tmpdir() tmp = utils.get_tmpdir()
if compare(opts, conf, tmp, focus): if compare(opts, conf, tmp, args['--files']):
LOG.log('generated temporary files available under %s' % (tmp)) LOG.log('generated temporary files available under %s' % (tmp))
else: else:
os.rmdir(tmp) os.rmdir(tmp)