mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-15 20:50:05 +00:00
rename quiet as debug
This commit is contained in:
@@ -83,7 +83,7 @@ def install(opts, conf):
|
|||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
||||||
diff=opts['installdiff'], quiet=opts['quiet'])
|
diff=opts['installdiff'], debug=opts['debug'])
|
||||||
installed = []
|
installed = []
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
if hasattr(dotfile, 'link') and dotfile.link:
|
if hasattr(dotfile, 'link') and dotfile.link:
|
||||||
@@ -131,7 +131,7 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], base=opts['dotpath'],
|
dry=opts['dry'], base=opts['dotpath'],
|
||||||
quiet=opts['quiet'])
|
debug=opts['debug'])
|
||||||
|
|
||||||
# compare only specific files
|
# compare only specific files
|
||||||
ret = True
|
ret = True
|
||||||
@@ -158,8 +158,8 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
dotfile.src, dotfile.dst,
|
dotfile.src, dotfile.dst,
|
||||||
opts=opts['dopts'])
|
opts=opts['dopts'])
|
||||||
if same:
|
if same:
|
||||||
if not opts['quiet']:
|
if not opts['debug']:
|
||||||
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key,
|
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
|
||||||
dotfile.dst))
|
dotfile.dst))
|
||||||
LOG.raw('same file')
|
LOG.raw('same file')
|
||||||
else:
|
else:
|
||||||
@@ -203,7 +203,7 @@ def update(opts, conf, path):
|
|||||||
if opts['safe'] and not LOG.ask(msg):
|
if opts['safe'] and not LOG.ask(msg):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False, log=False)
|
run(cmd, raw=False)
|
||||||
LOG.log('\"%s\" updated from \"%s\".' % (src, path))
|
LOG.log('\"%s\" updated from \"%s\".' % (src, path))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -236,14 +236,14 @@ def importer(opts, conf, paths):
|
|||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False, log=False)
|
run(cmd, raw=False)
|
||||||
cmd = ['cp', '-R', '-L', dst, srcf]
|
cmd = ['cp', '-R', '-L', dst, srcf]
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||||
if opts['link']:
|
if opts['link']:
|
||||||
LOG.dry('would symlink %s to %s' % (srcf, dst))
|
LOG.dry('would symlink %s to %s' % (srcf, dst))
|
||||||
else:
|
else:
|
||||||
run(cmd, raw=False, log=False)
|
run(cmd, raw=False)
|
||||||
if opts['link']:
|
if opts['link']:
|
||||||
remove(dst)
|
remove(dst)
|
||||||
os.symlink(srcf, dst)
|
os.symlink(srcf, dst)
|
||||||
@@ -299,7 +299,10 @@ def main():
|
|||||||
opts['safe'] = not args['--force']
|
opts['safe'] = not args['--force']
|
||||||
opts['installdiff'] = not args['--nodiff']
|
opts['installdiff'] = not args['--nodiff']
|
||||||
opts['link'] = args['--link']
|
opts['link'] = args['--link']
|
||||||
opts['quiet'] = not args['--verbose']
|
opts['debug'] = not args['--verbose']
|
||||||
|
|
||||||
|
if opts['debug']:
|
||||||
|
LOG.debug = True
|
||||||
|
|
||||||
header()
|
header()
|
||||||
|
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ class Installer:
|
|||||||
BACKUP_SUFFIX = '.dotdropbak'
|
BACKUP_SUFFIX = '.dotdropbak'
|
||||||
|
|
||||||
def __init__(self, base='.', create=True, backup=True,
|
def __init__(self, base='.', create=True, backup=True,
|
||||||
dry=False, safe=False, quiet=False, diff=True):
|
dry=False, safe=False, debug=False, diff=True):
|
||||||
self.create = create
|
self.create = create
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
self.dry = dry
|
self.dry = dry
|
||||||
self.safe = safe
|
self.safe = safe
|
||||||
self.base = base
|
self.base = base
|
||||||
self.quiet = quiet
|
self.debug = debug
|
||||||
self.diff = diff
|
self.diff = diff
|
||||||
self.comparing = False
|
self.comparing = False
|
||||||
self.log = Logger()
|
self.log = Logger(debug=self.debug)
|
||||||
|
|
||||||
def install(self, templater, profile, src, dst):
|
def install(self, templater, profile, src, dst):
|
||||||
'''Install the dotfile for profile "profile"'''
|
'''Install the dotfile for profile "profile"'''
|
||||||
@@ -83,8 +83,7 @@ class Installer:
|
|||||||
self.log.err('installing \"%s\" to \"%s\"' % (src, dst))
|
self.log.err('installing \"%s\" to \"%s\"' % (src, dst))
|
||||||
return []
|
return []
|
||||||
if ret > 0:
|
if ret > 0:
|
||||||
if not self.quiet:
|
self.log.dbg('ignoring \"%s\", same content' % (dst))
|
||||||
self.log.sub('ignoring \"%s\", same content' % (dst))
|
|
||||||
return []
|
return []
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
if not self.dry and not self.comparing:
|
if not self.dry and not self.comparing:
|
||||||
@@ -189,8 +188,7 @@ class Installer:
|
|||||||
src, dst,
|
src, dst,
|
||||||
tmpfolder)
|
tmpfolder)
|
||||||
if ret:
|
if ret:
|
||||||
diff = utils.diff(tmpdst, dst, log=False,
|
diff = utils.diff(tmpdst, dst, raw=False, opts=opts)
|
||||||
raw=False, opts=opts)
|
|
||||||
if diff == '':
|
if diff == '':
|
||||||
retval = True, ''
|
retval = True, ''
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ class Logger:
|
|||||||
RESET = '\033[0m'
|
RESET = '\033[0m'
|
||||||
EMPH = '\033[33m'
|
EMPH = '\033[33m'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, debug=False):
|
||||||
pass
|
self.debug = debug
|
||||||
|
|
||||||
def log(self, string, end='\n', pre=''):
|
def log(self, string, end='\n', pre=''):
|
||||||
cs = self._color(self.BLUE)
|
cs = self._color(self.BLUE)
|
||||||
@@ -45,6 +45,11 @@ class Logger:
|
|||||||
ce = self._color(self.RESET)
|
ce = self._color(self.RESET)
|
||||||
sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce))
|
sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce))
|
||||||
|
|
||||||
|
def dbg(self, string):
|
||||||
|
cs = self._color(self.MAGENTA)
|
||||||
|
ce = self._color(self.RESET)
|
||||||
|
sys.stderr.write('%s[DEBUG] %s%s\n' % (cs, string, ce))
|
||||||
|
|
||||||
def dry(self, string, end='\n'):
|
def dry(self, string, end='\n'):
|
||||||
cs = self._color(self.GREEN)
|
cs = self._color(self.GREEN)
|
||||||
ce = self._color(self.RESET)
|
ce = self._color(self.RESET)
|
||||||
|
|||||||
@@ -14,13 +14,8 @@ from shutil import rmtree
|
|||||||
from dotdrop.logger import Logger
|
from dotdrop.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
LOG = Logger()
|
def run(cmd, raw=True):
|
||||||
|
''' expects a list '''
|
||||||
|
|
||||||
def run(cmd, log=False, raw=True):
|
|
||||||
""" expects a list """
|
|
||||||
if log:
|
|
||||||
LOG.log('cmd: \"%s\"' % (' '.join(cmd)))
|
|
||||||
p = subprocess.Popen(cmd, shell=False,
|
p = subprocess.Popen(cmd, shell=False,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
if raw:
|
if raw:
|
||||||
@@ -29,10 +24,10 @@ def run(cmd, log=False, raw=True):
|
|||||||
return ''.join(lines)
|
return ''.join(lines)
|
||||||
|
|
||||||
|
|
||||||
def diff(src, dst, log=False, raw=True, opts=''):
|
def diff(src, dst, raw=True, opts=''):
|
||||||
''' call diff to compare two files '''
|
''' call diff to compare two files '''
|
||||||
cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst)
|
cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst)
|
||||||
return run(shlex.split(cmd), log=log, raw=raw)
|
return run(shlex.split(cmd), raw=raw)
|
||||||
|
|
||||||
|
|
||||||
def get_tmpdir():
|
def get_tmpdir():
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def load_config(confpath, profile):
|
|||||||
opts['safe'] = True
|
opts['safe'] = True
|
||||||
opts['installdiff'] = True
|
opts['installdiff'] = True
|
||||||
opts['link'] = False
|
opts['link'] = False
|
||||||
opts['quiet'] = True
|
opts['debug'] = True
|
||||||
opts['dopts'] = ''
|
opts['dopts'] = ''
|
||||||
return conf, opts
|
return conf, opts
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.assertTrue(len(dotfiles) == nbdotfiles)
|
self.assertTrue(len(dotfiles) == nbdotfiles)
|
||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'])
|
||||||
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'], debug=True)
|
||||||
results = {}
|
results = {}
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
same, _ = inst.compare(t, tmp, opts['profile'],
|
same, _ = inst.compare(t, tmp, opts['profile'],
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ exec bspwm
|
|||||||
# install them
|
# install them
|
||||||
conf, opts = load_config(confpath, profile)
|
conf, opts = load_config(confpath, profile)
|
||||||
opts['safe'] = False
|
opts['safe'] = False
|
||||||
opts['quiet'] = True
|
opts['debug'] = True
|
||||||
install(opts, conf)
|
install(opts, conf)
|
||||||
|
|
||||||
# now compare the generated files
|
# now compare the generated files
|
||||||
|
|||||||
Reference in New Issue
Block a user