1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 14:23:48 +00:00

provide an option to install all dotfiles to a temporary directory

This commit is contained in:
deadc0de6
2018-09-02 15:48:43 +02:00
parent 0d590e987a
commit b2998734ca
3 changed files with 58 additions and 23 deletions

View File

@@ -272,6 +272,10 @@ $ dotdrop.sh compare
The diffing is done by diff in the backend, one can provide specific
options to diff using the `-o` switch.
It is also possible to install all dotfiles for a specific profile
in a temporary directory in order to manually compare them with
the local version by using `install` and the `-t` switch.
## Import dotfiles
Dotdrop allows to import dotfiles directly from the
@@ -477,16 +481,37 @@ $ sudo pip3 install dotdrop --upgrade
## Update dotfiles
Dotfiles managed by dotdrop can be updated using the `update` command.
There are two cases:
* the dotfile doesn't use [templating](#template): the new version of the dotfile is copied to the
*dotfiles* directory and overwrites the old version. If git is used to version the dotfiles stored
by dotdrop, the git command `diff` can be used to view the changes.
* the dotfile uses [templating](#template): the dotfile must be manually updated, the use of
the dotdrop command `compare` can be helpful to identify the changes to apply to the template.
**The dotfile doesn't use [templating](#template)**
```
The new version of the dotfile is copied to the *dotfiles* directory and overwrites
the old version. If git is used to version the dotfiles stored by dotdrop, the git command
`diff` can be used to view the changes.
```bash
$ dotdrop.sh update ~/.vimrc
$ git diff
```
**The dotfile uses [templating](#template)**
The dotfile must be manually updated, two solutions can be used to identify the
changes to apply to the template:
* Use dotdrop's `compare` command
* Install the dotfiles to a temporary directory (using the `install` command and the
`-t` switch) and compare the generated dotfile with the local one.
```bash
# use compare to identify change(s)
$ ./dotdrop.sh compare --files=~/.vimrc
# use install to identify change(s)
$ ./dotdrop.sh install -t
Installed to tmp /tmp/dotdrop-6kix7555
$ diff ~/.vimrc /tmp/dotdrop-6kix7555/home/user/.vimrc
```
## Store sensitive dotfiles

View File

@@ -41,14 +41,14 @@ USAGE = """
{}
Usage:
dotdrop install [-fndVb] [-c <path>] [-p <profile>]
dotdrop import [-ldVb] [-c <path>] [-p <profile>] <paths>...
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
[-o <opts>] [-i <name>...]
[--files=<files>]
dotdrop update [-fdVb] [-c <path>] <paths>...
dotdrop listfiles [-Vb] [-c <path>] [-p <profile>]
dotdrop list [-Vb] [-c <path>]
dotdrop install [-tfndVb] [-c <path>] [-p <profile>]
dotdrop import [-ldVb] [-c <path>] [-p <profile>] <paths>...
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
[-o <opts>] [-i <name>...]
[--files=<files>]
dotdrop update [-fdVb] [-c <path>] <paths>...
dotdrop listfiles [-Vb] [-c <path>] [-p <profile>]
dotdrop list [-Vb] [-c <path>]
dotdrop --help
dotdrop --version
@@ -59,6 +59,7 @@ Options:
-i --ignore=<name> File name to ignore when diffing.
-o --dopts=<opts> Diff options [default: ].
-n --nodiff Do not diff when installing.
-t --temp Install to a temporary directory for review.
-l --link Import and link.
-f --force Do not warn if exists.
-V --verbose Be verbose.
@@ -74,7 +75,7 @@ Options:
###########################################################
def install(opts, conf):
def install(opts, conf, temporary=False):
"""install all dotfiles for this profile"""
dotfiles = conf.get_dotfiles(opts['profile'])
if dotfiles == []:
@@ -83,10 +84,13 @@ def install(opts, conf):
return False
t = Templategen(opts['profile'], base=opts['dotpath'],
variables=opts['variables'], debug=opts['debug'])
tmpdir = None
if temporary:
tmpdir = get_tmpdir()
inst = Installer(create=opts['create'], backup=opts['backup'],
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
workdir=opts['workdir'], diff=opts['installdiff'],
debug=opts['debug'])
debug=opts['debug'], totemp=tmpdir)
installed = []
for dotfile in dotfiles:
if dotfile.actions and Cfg.key_actions_pre in dotfile.actions:
@@ -126,6 +130,8 @@ def install(opts, conf):
LOG.dbg('executing post action {}'.format(action))
action.execute()
installed.extend(r)
if temporary:
LOG.log('\nInstalled to tmp {}.'.format(tmpdir))
LOG.log('\n{} dotfile(s) installed.'.format(len(installed)))
return True
@@ -154,7 +160,6 @@ def apply_trans(opts, dotfile):
def _select(selections, dotfiles):
ret = True
selected = []
for selection in selections:
df = next(
@@ -166,8 +171,7 @@ def _select(selections, dotfiles):
selected.append(df)
else:
LOG.err('no dotfile matches \"{}\"'.format(selection))
ret = False
return selected, ret
return selected
def compare(opts, conf, tmp, focus=None, ignore=[]):
@@ -181,7 +185,7 @@ def compare(opts, conf, tmp, focus=None, ignore=[]):
same = True
selected = dotfiles
if focus:
selected, ret = _select(focus.replace(' ', '').split(','), dotfiles)
selected = _select(focus.replace(' ', '').split(','), dotfiles)
if len(selected) < 1:
return False
@@ -362,13 +366,14 @@ def main():
elif args['install']:
# install the dotfiles stored in dotdrop
ret = install(opts, conf)
ret = install(opts, conf, temporary=args['--temp'])
elif args['compare']:
# compare local dotfiles with dotfiles stored in dotdrop
tmp = get_tmpdir()
opts['dopts'] = args['--dopts']
ret = compare(opts, conf, tmp, args['--files'], args['--ignore'])
ret = compare(opts, conf, tmp, focus=args['--files'],
ignore=args['--ignore'])
if os.listdir(tmp):
LOG.raw('\ntemporary files available under {}'.format(tmp))
else:

View File

@@ -20,7 +20,7 @@ class Installer:
def __init__(self, base='.', create=True, backup=True,
dry=False, safe=False, workdir='~/.config/dotdrop',
debug=False, diff=True):
debug=False, diff=True, totemp=None):
self.create = create
self.backup = backup
self.dry = dry
@@ -29,6 +29,7 @@ class Installer:
self.base = base
self.debug = debug
self.diff = diff
self.totemp = totemp
self.comparing = False
self.log = Logger()
@@ -36,6 +37,8 @@ class Installer:
"""install the src to dst using a template"""
src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.expanduser(dst)
if self.totemp:
dst = self._pivot_path(dst, self.totemp)
if utils.samefile(src, dst):
# symlink loop
self.log.err('dotfile points to itself: {}'.format(dst))
@@ -50,6 +53,8 @@ class Installer:
"""set src as the link target of dst"""
src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.expanduser(dst)
if self.totemp:
return self.install(templater, src, dst)
if Templategen.is_template(src):
if self.debug: