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

Import only used functions

This commit is contained in:
Marcel Robitaille
2018-12-29 15:35:29 -04:00
parent fffe55ecd9
commit 67be049407

View File

@@ -19,7 +19,7 @@ from dotdrop.updater import Updater
from dotdrop.comparator import Comparator from dotdrop.comparator import Comparator
from dotdrop.dotfile import Dotfile from dotdrop.dotfile import Dotfile
from dotdrop.config import Cfg from dotdrop.config import Cfg
import dotdrop.utils as dd from dotdrop.utils import get_tmpdir, remove, strip_home, run
from dotdrop.linktypes import LinkTypes from dotdrop.linktypes import LinkTypes
LOG = Logger() LOG = Logger()
@@ -92,7 +92,7 @@ def cmd_install(opts, conf, temporary=False, keys=[]):
variables=opts['variables'], debug=opts['debug']) variables=opts['variables'], debug=opts['debug'])
tmpdir = None tmpdir = None
if temporary: if temporary:
tmpdir = dd.get_tmpdir() tmpdir = get_tmpdir()
inst = Installer(create=opts['create'], backup=opts['backup'], inst = Installer(create=opts['create'], backup=opts['backup'],
dry=opts['dry'], safe=opts['safe'], dry=opts['dry'], safe=opts['safe'],
base=opts['dotpath'], workdir=opts['workdir'], base=opts['dotpath'], workdir=opts['workdir'],
@@ -123,7 +123,7 @@ def cmd_install(opts, conf, temporary=False, keys=[]):
if tmp: if tmp:
tmp = os.path.join(opts['dotpath'], tmp) tmp = os.path.join(opts['dotpath'], tmp)
if os.path.exists(tmp): if os.path.exists(tmp):
dd.remove(tmp) remove(tmp)
if len(r) > 0: if len(r) > 0:
if Cfg.key_actions_post in dotfile.actions: if Cfg.key_actions_post in dotfile.actions:
actions = dotfile.actions[Cfg.key_actions_post] actions = dotfile.actions[Cfg.key_actions_post]
@@ -191,7 +191,7 @@ def cmd_compare(opts, conf, tmp, focus=[], ignore=[]):
# clean tmp transformed dotfile if any # clean tmp transformed dotfile if any
tmpsrc = os.path.join(opts['dotpath'], tmpsrc) tmpsrc = os.path.join(opts['dotpath'], tmpsrc)
if os.path.exists(tmpsrc): if os.path.exists(tmpsrc):
dd.remove(tmpsrc) remove(tmpsrc)
if diff == '': if diff == '':
if opts['debug']: if opts['debug']:
LOG.dbg('diffing \"{}\" VS \"{}\"'.format(dotfile.key, LOG.dbg('diffing \"{}\" VS \"{}\"'.format(dotfile.key,
@@ -245,7 +245,7 @@ def cmd_importer(opts, conf, paths):
continue continue
dst = path.rstrip(os.sep) dst = path.rstrip(os.sep)
dst = os.path.abspath(dst) dst = os.path.abspath(dst)
src = dd.strip_home(dst) src = strip_home(dst)
strip = '.' + os.sep strip = '.' + os.sep
if opts['keepdot']: if opts['keepdot']:
strip = os.sep strip = os.sep
@@ -264,7 +264,7 @@ def cmd_importer(opts, conf, paths):
if opts['dry']: if opts['dry']:
LOG.dry('would run: {}'.format(' '.join(cmd))) LOG.dry('would run: {}'.format(' '.join(cmd)))
else: else:
r, _ = dd.run(cmd, raw=False, debug=opts['debug'], checkerr=True) r, _ = run(cmd, raw=False, debug=opts['debug'], checkerr=True)
if not r: if not r:
LOG.err('importing \"{}\" failed!'.format(path)) LOG.err('importing \"{}\" failed!'.format(path))
ret = False ret = False
@@ -275,13 +275,13 @@ def cmd_importer(opts, conf, paths):
if linkit: if linkit:
LOG.dry('would symlink {} to {}'.format(srcf, dst)) LOG.dry('would symlink {} to {}'.format(srcf, dst))
else: else:
r, _ = dd.run(cmd, raw=False, debug=opts['debug'], checkerr=True) r, _ = run(cmd, raw=False, debug=opts['debug'], checkerr=True)
if not r: if not r:
LOG.err('importing \"{}\" failed!'.format(path)) LOG.err('importing \"{}\" failed!'.format(path))
ret = False ret = False
continue continue
if linkit: if linkit:
dd.remove(dst) remove(dst)
os.symlink(srcf, dst) os.symlink(srcf, dst)
retconf, dotfile = conf.new(dotfile, opts['profile'], retconf, dotfile = conf.new(dotfile, opts['profile'],
link=linkit, debug=opts['debug']) link=linkit, debug=opts['debug'])
@@ -402,7 +402,7 @@ def apply_trans(opts, dotfile):
msg = 'transformation \"{}\" failed for {}' msg = 'transformation \"{}\" failed for {}'
LOG.err(msg.format(trans.key, dotfile.key)) LOG.err(msg.format(trans.key, dotfile.key))
if new_src and os.path.exists(new_src): if new_src and os.path.exists(new_src):
dd.remove(new_src) remove(new_src)
return None return None
return new_src return new_src
@@ -471,12 +471,12 @@ def main():
# compare local dotfiles with dotfiles stored in dotdrop # compare local dotfiles with dotfiles stored in dotdrop
if opts['debug']: if opts['debug']:
LOG.dbg('running cmd: compare') LOG.dbg('running cmd: compare')
tmp = dd.get_tmpdir() tmp = get_tmpdir()
opts['dopts'] = args['--dopts'] opts['dopts'] = args['--dopts']
ret = cmd_compare(opts, conf, tmp, focus=args['--file'], ret = cmd_compare(opts, conf, tmp, focus=args['--file'],
ignore=args['--ignore']) ignore=args['--ignore'])
# clean tmp directory # clean tmp directory
dd.remove(tmp) remove(tmp)
elif args['import']: elif args['import']:
# import dotfile(s) # import dotfile(s)