mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 12:03:49 +00:00
refactor string format to .format
This commit is contained in:
@@ -20,7 +20,7 @@ class Action:
|
||||
|
||||
def execute(self):
|
||||
ret = 1
|
||||
self.log.sub('executing \"%s\"' % (self.action))
|
||||
self.log.sub('executing \"{}\"'.format(self.action))
|
||||
try:
|
||||
ret = subprocess.call(self.action, shell=True)
|
||||
except KeyboardInterrupt:
|
||||
@@ -32,12 +32,12 @@ class Action:
|
||||
where {0} is the file to transform and
|
||||
{1} is the result file'''
|
||||
if os.path.exists(arg1):
|
||||
msg = 'transformation destination exists: %s'
|
||||
self.log.warn(msg % (arg1))
|
||||
msg = 'transformation destination exists: {}'
|
||||
self.log.warn(msg.format(arg1))
|
||||
return False
|
||||
ret = 1
|
||||
cmd = self.action.format(arg0, arg1)
|
||||
self.log.sub('transforming with \"%s\"' % (cmd))
|
||||
self.log.sub('transforming with \"{}\"'.format(cmd))
|
||||
try:
|
||||
ret = subprocess.call(cmd, shell=True)
|
||||
except KeyboardInterrupt:
|
||||
@@ -45,7 +45,7 @@ class Action:
|
||||
return ret == 0
|
||||
|
||||
def __str__(self):
|
||||
return 'key:%s -> \"%s\"' % (self.key, self.action)
|
||||
return 'key:{} -> \"{}\"'.format(self.key, self.action)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
@@ -58,13 +58,13 @@ class Cfg:
|
||||
|
||||
def _is_valid(self):
|
||||
if self.key_profiles not in self.content:
|
||||
self.log.err('missing \"%s\" in config' % (self.key_profiles))
|
||||
self.log.err('missing \"{}\" in config'.format(self.key_profiles))
|
||||
return False
|
||||
if self.key_config not in self.content:
|
||||
self.log.err('missing \"%s\" in config' % (self.key_config))
|
||||
self.log.err('missing \"{}\" in config'.format(self.key_config))
|
||||
return False
|
||||
if self.key_dotfiles not in self.content:
|
||||
self.log.err('missing \"%s\" in config' % (self.key_dotfiles))
|
||||
self.log.err('missing \"{}\" in config'.format(self.key_dotfiles))
|
||||
return False
|
||||
if self.content[self.key_profiles]:
|
||||
# make sure dotfiles are in a sub called "dotfiles"
|
||||
@@ -85,7 +85,7 @@ class Cfg:
|
||||
res = []
|
||||
for entry in entries:
|
||||
if entry not in actions.keys():
|
||||
self.log.warn('unknown action \"%s\"' % (entry))
|
||||
self.log.warn('unknown action \"{}\"'.format(entry))
|
||||
continue
|
||||
res.append(actions[entry])
|
||||
return res
|
||||
@@ -131,8 +131,8 @@ class Cfg:
|
||||
self.key_dotfiles_trans in v else []
|
||||
trans = self._parse_actions(self.trans, entries)
|
||||
if len(trans) > 0 and link:
|
||||
msg = 'transformations disabled for \"%s\"' % (dst)
|
||||
msg += ' as link is True' % (dst)
|
||||
msg = 'transformations disabled for \"{}\"'.format(dst)
|
||||
msg += ' because link is True'
|
||||
self.log.warn(msg)
|
||||
trans = []
|
||||
self.dotfiles[k] = Dotfile(k, dst, src, link=link,
|
||||
@@ -172,7 +172,7 @@ class Cfg:
|
||||
return included
|
||||
for other in self.profiles[profile][self.key_profiles_incl]:
|
||||
if other not in self.prodots:
|
||||
self.log.warn('unknown included profile \"%s\"' % (other))
|
||||
self.log.warn('unknown included profile \"{}\"'.format(other))
|
||||
continue
|
||||
included.extend(self.prodots[other])
|
||||
return included
|
||||
@@ -206,7 +206,7 @@ class Cfg:
|
||||
if dotfile.key in self.dotfiles.keys():
|
||||
# already in it
|
||||
if profile in self.prodots and dotfile in self.prodots[profile]:
|
||||
self.log.err('\"%s\" already present' % (dotfile.key))
|
||||
self.log.err('\"{}\" already present'.format(dotfile.key))
|
||||
return False
|
||||
|
||||
# add for this profile
|
||||
|
||||
@@ -37,11 +37,11 @@ TRANS_SUFFIX = 'trans'
|
||||
BANNER = """ _ _ _
|
||||
__| | ___ | |_ __| |_ __ ___ _ __
|
||||
/ _` |/ _ \| __/ _` | '__/ _ \| '_ |
|
||||
\__,_|\___/ \__\__,_|_| \___/| .__/ v%s
|
||||
|_|""" % (VERSION)
|
||||
\__,_|\___/ \__\__,_|_| \___/| .__/ v{}
|
||||
|_|""".format(VERSION)
|
||||
|
||||
USAGE = """
|
||||
%s
|
||||
{}
|
||||
|
||||
Usage:
|
||||
dotdrop install [-fndV] [-c <path>] [-p <profile>]
|
||||
@@ -55,7 +55,7 @@ Usage:
|
||||
dotdrop --version
|
||||
|
||||
Options:
|
||||
-p --profile=<profile> Specify the profile to use [default: %s].
|
||||
-p --profile=<profile> Specify the profile to use [default: {}].
|
||||
-c --cfg=<path> Path to the config [default: config.yaml].
|
||||
--files=<files> Comma separated list of files to compare.
|
||||
-o --dopts=<opts> Diff options [default: ].
|
||||
@@ -67,7 +67,7 @@ Options:
|
||||
-v --version Show version.
|
||||
-h --help Show this screen.
|
||||
|
||||
""" % (BANNER, HOSTNAME)
|
||||
""".format(BANNER, HOSTNAME)
|
||||
|
||||
###########################################################
|
||||
# entry point
|
||||
@@ -77,8 +77,8 @@ Options:
|
||||
def install(opts, conf):
|
||||
dotfiles = conf.get_dotfiles(opts['profile'])
|
||||
if dotfiles == []:
|
||||
LOG.err('no dotfiles defined for this profile (\"%s\")' %
|
||||
(opts['profile']))
|
||||
msg = 'no dotfiles defined for this profile (\"{}\")'
|
||||
LOG.err(msg.format(opts['profile']))
|
||||
return False
|
||||
t = Templategen(base=opts['dotpath'])
|
||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||
@@ -93,15 +93,15 @@ def install(opts, conf):
|
||||
src = dotfile.src
|
||||
tmp = None
|
||||
if dotfile.trans:
|
||||
tmp = '%s.%s' % (src, TRANS_SUFFIX)
|
||||
tmp = '{}.{}'.format(src, TRANS_SUFFIX)
|
||||
err = False
|
||||
for trans in dotfile.trans:
|
||||
LOG.dbg('executing transformation {}'.format(trans))
|
||||
s = os.path.join(opts['dotpath'], src)
|
||||
temp = os.path.join(opts['dotpath'], tmp)
|
||||
if not trans.transform(s, temp):
|
||||
msg = 'transformation \"%s\" failed for %s'
|
||||
LOG.err(msg % (trans.key, dotfile.key))
|
||||
msg = 'transformation \"{}\" failed for {}'
|
||||
LOG.err(msg.format(trans.key, dotfile.key))
|
||||
err = True
|
||||
break
|
||||
if err:
|
||||
@@ -120,7 +120,7 @@ def install(opts, conf):
|
||||
LOG.dbg('executing action {}'.format(action))
|
||||
action.execute()
|
||||
installed.extend(r)
|
||||
LOG.log('\n%u dotfile(s) installed.' % (len(installed)))
|
||||
LOG.log('\n{} dotfile(s) installed.'.format(len(installed)))
|
||||
return True
|
||||
|
||||
|
||||
@@ -128,8 +128,8 @@ def compare(opts, conf, tmp, focus=None):
|
||||
'''compare dotfiles and return True if all same'''
|
||||
dotfiles = conf.get_dotfiles(opts['profile'])
|
||||
if dotfiles == []:
|
||||
LOG.err('no dotfiles defined for this profile (\"%s\")' %
|
||||
(opts['profile']))
|
||||
msg = 'no dotfiles defined for this profile (\"{}\")'
|
||||
LOG.err(msg.format(opts['profile']))
|
||||
return True
|
||||
t = Templategen(base=opts['dotpath'])
|
||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||
@@ -146,7 +146,7 @@ def compare(opts, conf, tmp, focus=None):
|
||||
if df:
|
||||
selected.append(df)
|
||||
else:
|
||||
LOG.err('no dotfile matches \"%s\"' % (selection))
|
||||
LOG.err('no dotfile matches \"{}\"'.format(selection))
|
||||
ret = False
|
||||
|
||||
if len(selected) < 1:
|
||||
@@ -155,18 +155,19 @@ def compare(opts, conf, tmp, focus=None):
|
||||
for dotfile in selected:
|
||||
LOG.dbg('comparing {}'.format(dotfile))
|
||||
if dotfile.trans:
|
||||
msg = 'ignore %s as it uses transformation(s)'
|
||||
LOG.log(msg % (dotfile.key))
|
||||
msg = 'ignore {} as it uses transformation(s)'
|
||||
LOG.log(msg.format(dotfile.key))
|
||||
continue
|
||||
same, diff = inst.compare(t, tmp, opts['profile'],
|
||||
dotfile.src, dotfile.dst,
|
||||
opts=opts['dopts'])
|
||||
if same:
|
||||
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
|
||||
LOG.dbg('diffing \"{}\" VS \"{}\"'.format(dotfile.key,
|
||||
dotfile.dst))
|
||||
LOG.dbg('same file')
|
||||
else:
|
||||
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
|
||||
LOG.log('diffing \"{}\" VS \"{}\"'.format(dotfile.key,
|
||||
dotfile.dst))
|
||||
LOG.emph(diff)
|
||||
ret = False
|
||||
|
||||
@@ -175,7 +176,7 @@ def compare(opts, conf, tmp, focus=None):
|
||||
|
||||
def update(opts, conf, path):
|
||||
if not os.path.exists(path):
|
||||
LOG.err('\"%s\" does not exist!' % (path))
|
||||
LOG.err('\"{}\" does not exist!'.format(path))
|
||||
return False
|
||||
home = os.path.expanduser(TILD)
|
||||
path = os.path.expanduser(path)
|
||||
@@ -187,27 +188,27 @@ def update(opts, conf, path):
|
||||
dotfiles = conf.get_dotfiles(opts['profile'])
|
||||
subs = [d for d in dotfiles if d.dst == path]
|
||||
if not subs:
|
||||
LOG.err('\"%s\" is not managed!' % (path))
|
||||
LOG.err('\"{}\" is not managed!'.format(path))
|
||||
return False
|
||||
if len(subs) > 1:
|
||||
found = ','.join([d.src for d in dotfiles])
|
||||
LOG.err('multiple dotfiles found: %s' % (found))
|
||||
LOG.err('multiple dotfiles found: {}'.format(found))
|
||||
return False
|
||||
dotfile = subs[0]
|
||||
src = os.path.join(conf.get_abs_dotpath(opts['dotpath']), dotfile.src)
|
||||
if Templategen.get_marker() in open(src, 'r').read():
|
||||
LOG.warn('\"%s\" uses template, please update manually' % (src))
|
||||
LOG.warn('\"{}\" uses template, please update manually'.format(src))
|
||||
return False
|
||||
cmd = ['cp', '-R', '-L', os.path.expanduser(path), src]
|
||||
if opts['dry']:
|
||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
else:
|
||||
msg = 'Overwrite \"%s\" with \"%s\"?' % (src, path)
|
||||
msg = 'Overwrite \"{}\" with \"{}\"?'.format(src, path)
|
||||
if opts['safe'] and not LOG.ask(msg):
|
||||
return False
|
||||
else:
|
||||
run(cmd, raw=False)
|
||||
LOG.log('\"%s\" updated from \"%s\".' % (src, path))
|
||||
LOG.log('\"{}\" updated from \"{}\".'.format(src, path))
|
||||
return True
|
||||
|
||||
|
||||
@@ -216,7 +217,7 @@ def importer(opts, conf, paths):
|
||||
cnt = 0
|
||||
for path in paths:
|
||||
if not os.path.exists(path):
|
||||
LOG.err('\"%s\" does not exist, ignored !' % (path))
|
||||
LOG.err('\"{}\" does not exist, ignored !'.format(path))
|
||||
continue
|
||||
dst = path.rstrip(os.sep)
|
||||
key = dst.split(os.sep)[-1]
|
||||
@@ -224,9 +225,9 @@ def importer(opts, conf, paths):
|
||||
key = '_'.join(dst.split(os.sep)[-2:])
|
||||
key = key.lstrip('.').lower()
|
||||
if os.path.isdir(dst):
|
||||
key = 'd_%s' % (key)
|
||||
key = 'd_{}'.format(key)
|
||||
else:
|
||||
key = 'f_%s' % (key)
|
||||
key = 'f_{}'.format(key)
|
||||
src = dst
|
||||
if dst.startswith(home):
|
||||
src = dst[len(home):]
|
||||
@@ -235,32 +236,32 @@ def importer(opts, conf, paths):
|
||||
srcf = os.path.join(CUR, opts['dotpath'], src)
|
||||
retconf = conf.new(dotfile, opts['profile'], opts['link'])
|
||||
if not os.path.exists(srcf):
|
||||
cmd = ['mkdir', '-p', '%s' % (os.path.dirname(srcf))]
|
||||
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
||||
if opts['dry']:
|
||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
else:
|
||||
run(cmd, raw=False)
|
||||
cmd = ['cp', '-R', '-L', dst, srcf]
|
||||
if opts['dry']:
|
||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
if opts['link']:
|
||||
LOG.dry('would symlink %s to %s' % (srcf, dst))
|
||||
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
||||
else:
|
||||
run(cmd, raw=False)
|
||||
if opts['link']:
|
||||
remove(dst)
|
||||
os.symlink(srcf, dst)
|
||||
if retconf:
|
||||
LOG.sub('\"%s\" imported' % (path))
|
||||
LOG.sub('\"{}\" imported'.format(path))
|
||||
cnt += 1
|
||||
else:
|
||||
LOG.warn('\"%s\" ignored' % (path))
|
||||
LOG.warn('\"{}\" ignored'.format(path))
|
||||
if opts['dry']:
|
||||
LOG.dry('new config file would be:')
|
||||
LOG.raw(conf.dump())
|
||||
else:
|
||||
conf.save()
|
||||
LOG.log('\n%u file(s) imported.' % (cnt))
|
||||
LOG.log('\n{} file(s) imported.'.format(cnt))
|
||||
|
||||
|
||||
def list_profiles(conf):
|
||||
@@ -272,13 +273,13 @@ def list_profiles(conf):
|
||||
|
||||
def list_files(opts, conf):
|
||||
if not opts['profile'] in conf.get_profiles():
|
||||
LOG.warn('unknown profile \"%s\"' % (opts['profile']))
|
||||
LOG.warn('unknown profile \"{}\"'.format(opts['profile']))
|
||||
return
|
||||
LOG.log('Dotfile(s) for profile \"%s\":\n' % (opts['profile']))
|
||||
LOG.log('Dotfile(s) for profile \"{}\":\n'.format(opts['profile']))
|
||||
for dotfile in conf.get_dotfiles(opts['profile']):
|
||||
LOG.log('%s (file: \"%s\", link: %s)' % (dotfile.key, dotfile.src,
|
||||
str(dotfile.link)))
|
||||
LOG.sub('%s' % (dotfile.dst))
|
||||
LOG.log('{} (file: \"{}\", link: {})'.format(dotfile.key, dotfile.src,
|
||||
dotfile.link))
|
||||
LOG.sub('{}'.format(dotfile.dst))
|
||||
LOG.log('')
|
||||
|
||||
|
||||
@@ -293,7 +294,7 @@ def main():
|
||||
try:
|
||||
conf = Cfg(os.path.expanduser(args['--cfg']))
|
||||
except ValueError as e:
|
||||
LOG.err('error: %s' % (str(e)))
|
||||
LOG.err('error: {}'.format(str(e)))
|
||||
return False
|
||||
|
||||
opts = conf.get_configs()
|
||||
@@ -329,7 +330,7 @@ def main():
|
||||
opts['dopts'] = args['--dopts']
|
||||
ret = compare(opts, conf, tmp, args['--files'])
|
||||
if os.listdir(tmp):
|
||||
LOG.raw('\ntemporary files available under %s' % (tmp))
|
||||
LOG.raw('\ntemporary files available under {}'.format(tmp))
|
||||
else:
|
||||
os.rmdir(tmp)
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ class Dotfile:
|
||||
self.trans = trans
|
||||
|
||||
def __str__(self):
|
||||
return 'key:\"%s\", src:\"%s\", dst:\"%s\", link:\"%s\"' % (self.key, self.src,
|
||||
self.dst, self.link)
|
||||
msg = 'key:\"{}\", src:\"{}\", dst:\"{}\", link:\"{}\"'
|
||||
return msg.format(self.key, self.src, self.dst, self.link)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
@@ -42,30 +42,30 @@ class Installer:
|
||||
dst = os.path.join(self.base, os.path.expanduser(dst))
|
||||
if os.path.exists(dst):
|
||||
if os.path.realpath(dst) == os.path.realpath(src):
|
||||
self.log.sub('ignoring "%s", link exists' % dst)
|
||||
self.log.sub('ignoring "{}", link exists'.format(dst))
|
||||
return []
|
||||
if self.dry:
|
||||
self.log.dry('would remove %s and link it to %s'
|
||||
% (dst, src))
|
||||
self.log.dry('would remove {} and link to {}'.format(dst, src))
|
||||
return []
|
||||
if self.safe and \
|
||||
not self.log.ask('Remove "%s" for link creation?' % dst):
|
||||
self.log.warn('ignoring "%s", link was not created' % dst)
|
||||
msg = 'Remove "{}" for link creation?'.format(dst)
|
||||
if self.safe and not self.log.ask(msg):
|
||||
msg = 'ignoring "{}", link was not created'
|
||||
self.log.warn(msg.format(dst))
|
||||
return []
|
||||
try:
|
||||
utils.remove(dst)
|
||||
except OSError:
|
||||
self.log.err('something went wrong with %s' % src)
|
||||
self.log.err('something went wrong with {}'.format(src))
|
||||
return []
|
||||
if self.dry:
|
||||
self.log.dry('would link %s to %s' % (dst, src))
|
||||
self.log.dry('would link {} to {}'.format(dst, src))
|
||||
return []
|
||||
base = os.path.dirname(dst)
|
||||
if not self._create_dirs(base):
|
||||
self.log.err('creating directory for \"%s\"' % (dst))
|
||||
self.log.err('creating directory for \"{}\"'.format(dst))
|
||||
return []
|
||||
os.symlink(src, dst)
|
||||
self.log.sub('linked %s to %s' % (dst, src))
|
||||
self.log.sub('linked {} to {}'.format(dst, src))
|
||||
# Follows original developer's behavior
|
||||
return [(src, dst)]
|
||||
|
||||
@@ -74,22 +74,22 @@ class Installer:
|
||||
self.log.dbg('generate template for {}'.format(src))
|
||||
content = templater.generate(src, profile)
|
||||
if content is None:
|
||||
self.log.err('generate from template \"%s\"' % (src))
|
||||
self.log.err('generate from template \"{}\"'.format(src))
|
||||
return []
|
||||
if not os.path.exists(src):
|
||||
self.log.err('source dotfile does not exist: \"%s\"' % (src))
|
||||
self.log.err('source dotfile does not exist: \"{}\"'.format(src))
|
||||
return []
|
||||
st = os.stat(src)
|
||||
ret = self._write(dst, content, st.st_mode)
|
||||
if ret < 0:
|
||||
self.log.err('installing \"%s\" to \"%s\"' % (src, dst))
|
||||
self.log.err('installing \"{}\" to \"{}\"'.format(src, dst))
|
||||
return []
|
||||
if ret > 0:
|
||||
self.log.dbg('ignoring \"%s\", same content' % (dst))
|
||||
self.log.dbg('ignoring \"{}\", same content'.format(dst))
|
||||
return []
|
||||
if ret == 0:
|
||||
if not self.dry and not self.comparing:
|
||||
self.log.sub('copied \"%s\" to \"%s\"' % (src, dst))
|
||||
self.log.sub('copied \"{}\" to \"{}\"'.format(src, dst))
|
||||
return [(src, dst)]
|
||||
return []
|
||||
|
||||
@@ -121,28 +121,28 @@ class Installer:
|
||||
1 when already exists
|
||||
-1 when error'''
|
||||
if self.dry:
|
||||
self.log.dry('would install %s' % (dst))
|
||||
self.log.dry('would install {}'.format(dst))
|
||||
return 0
|
||||
if os.path.exists(dst):
|
||||
samerights = os.stat(dst).st_mode == rights
|
||||
if self.diff and self._fake_diff(dst, content) and samerights:
|
||||
self.log.dbg('{} is the same'.format(dst))
|
||||
return 1
|
||||
if self.safe and not self.log.ask('Overwrite \"%s\"' % (dst)):
|
||||
self.log.warn('ignoring \"%s\", already present' % (dst))
|
||||
if self.safe and not self.log.ask('Overwrite \"{}\"'.format(dst)):
|
||||
self.log.warn('ignoring \"{}\", already present'.format(dst))
|
||||
return 1
|
||||
if self.backup and os.path.exists(dst):
|
||||
self._backup(dst)
|
||||
base = os.path.dirname(dst)
|
||||
if not self._create_dirs(base):
|
||||
self.log.err('creating directory for \"%s\"' % (dst))
|
||||
self.log.err('creating directory for \"{}\"'.format(dst))
|
||||
return -1
|
||||
self.log.dbg('write content to {}'.format(dst))
|
||||
try:
|
||||
with open(dst, 'wb') as f:
|
||||
f.write(content)
|
||||
except NotADirectoryError as e:
|
||||
self.log.err('opening dest file: %s' % (e))
|
||||
self.log.err('opening dest file: {}'.format(e))
|
||||
return -1
|
||||
os.chmod(dst, rights)
|
||||
return 0
|
||||
@@ -162,7 +162,7 @@ class Installer:
|
||||
if self.dry:
|
||||
return
|
||||
dst = path.rstrip(os.sep) + self.BACKUP_SUFFIX
|
||||
self.log.log('backup %s to %s' % (path, dst))
|
||||
self.log.log('backup {} to {}'.format(path, dst))
|
||||
os.rename(path, dst)
|
||||
|
||||
def _install_to_temp(self, templater, profile, src, dst, tmpdir):
|
||||
@@ -187,7 +187,7 @@ class Installer:
|
||||
dst = os.path.expanduser(dst)
|
||||
self.log.dbg('comparing {} and {}'.format(src, dst))
|
||||
if not os.path.exists(dst):
|
||||
retval = False, '\"%s\" does not exist on local\n' % (dst)
|
||||
retval = False, '\"{}\" does not exist on local\n'.format(dst)
|
||||
else:
|
||||
ret, tmpdst = self._install_to_temp(templater,
|
||||
profile,
|
||||
|
||||
@@ -24,27 +24,27 @@ class Logger:
|
||||
def log(self, string, end='\n', pre=''):
|
||||
cs = self._color(self.BLUE)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stdout.write('%s%s%s%s%s' % (pre, cs, string, end, ce))
|
||||
sys.stdout.write('{}{}{}{}{}'.format(pre, cs, string, end, ce))
|
||||
|
||||
def sub(self, string):
|
||||
cs = self._color(self.BLUE)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stdout.write('\t%s->%s %s\n' % (cs, ce, string))
|
||||
sys.stdout.write('\t{}->{} {}\n'.format(cs, ce, string))
|
||||
|
||||
def emph(self, string):
|
||||
cs = self._color(self.EMPH)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stderr.write('%s%s%s' % (cs, string, ce))
|
||||
sys.stderr.write('{}{}{}'.format(cs, string, ce))
|
||||
|
||||
def err(self, string, end='\n'):
|
||||
cs = self._color(self.RED)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stderr.write('%s[ERR] %s %s%s' % (cs, string, end, ce))
|
||||
sys.stderr.write('{}[ERR] {} {}{}'.format(cs, string, end, ce))
|
||||
|
||||
def warn(self, string, end='\n'):
|
||||
cs = self._color(self.YELLOW)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce))
|
||||
sys.stderr.write('{}[WARN] {} {}{}'.format(cs, string, end, ce))
|
||||
|
||||
def dbg(self, string):
|
||||
if not self.debug:
|
||||
@@ -54,20 +54,21 @@ class Logger:
|
||||
func = inspect.stack()[1][3]
|
||||
cs = self._color(self.MAGENTA)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stderr.write('%s[DEBUG][%s.%s] %s%s\n' % (cs, mod, func, string, ce))
|
||||
line = '{}[DEBUG][{}.{}] {}{}\n'
|
||||
sys.stderr.write(line.format(cs, mod, func, string, ce))
|
||||
|
||||
def dry(self, string, end='\n'):
|
||||
cs = self._color(self.GREEN)
|
||||
ce = self._color(self.RESET)
|
||||
sys.stdout.write('%s[DRY] %s %s%s' % (cs, string, end, ce))
|
||||
sys.stdout.write('{}[DRY] {} {}{}'.format(cs, string, end, ce))
|
||||
|
||||
def raw(self, string, end='\n'):
|
||||
sys.stdout.write('%s%s' % (string, end))
|
||||
sys.stdout.write('{}{}'.format(string, end))
|
||||
|
||||
def ask(self, query):
|
||||
cs = self._color(self.BLUE)
|
||||
ce = self._color(self.RESET)
|
||||
q = '%s%s%s' % (cs, query + ' [y/N] ? ', ce)
|
||||
q = '{}{}{}'.format(cs, query + ' [y/N] ? ', ce)
|
||||
r = input(q)
|
||||
return r == 'y'
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ def run(cmd, raw=True):
|
||||
|
||||
def diff(src, dst, raw=True, opts=''):
|
||||
''' call diff to compare two files '''
|
||||
cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst)
|
||||
cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, src, dst)
|
||||
return run(shlex.split(cmd), raw=raw)
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ def get_tmpfile():
|
||||
def remove(path):
|
||||
''' Remove a file / directory / symlink '''
|
||||
if not os.path.exists(path):
|
||||
raise OSError("File not found: %s" % path)
|
||||
raise OSError("File not found: {}".format(path))
|
||||
if os.path.islink(path) or os.path.isfile(path):
|
||||
os.unlink(path)
|
||||
elif os.path.isdir(path):
|
||||
rmtree(path)
|
||||
else:
|
||||
raise OSError("Unsupported file type for deletion: %s" % path)
|
||||
raise OSError("Unsupported file type for deletion: {}".format(path))
|
||||
|
||||
@@ -99,9 +99,9 @@ def create_fake_config(directory, configname='config.yaml',
|
||||
path = os.path.join(directory, configname)
|
||||
with open(path, 'w') as f:
|
||||
f.write('config:\n')
|
||||
f.write(' backup: %s\n' % (str(backup)))
|
||||
f.write(' create: %s\n' % (str(create)))
|
||||
f.write(' dotpath: %s\n' % (dotpath))
|
||||
f.write(' backup: {}\n'.format(str(backup)))
|
||||
f.write(' create: {}\n'.format(str(create)))
|
||||
f.write(' dotpath: {}\n'.format(dotpath))
|
||||
f.write('dotfiles:\n')
|
||||
f.write('profiles:\n')
|
||||
f.write('actions:\n')
|
||||
|
||||
@@ -37,32 +37,32 @@ exec bspwm
|
||||
with open(path, 'w') as f:
|
||||
f.write('actions:\n')
|
||||
for action in actions:
|
||||
f.write(' %s: %s\n' % (action.key, action.action))
|
||||
f.write(' {}: {}\n'.format(action.key, action.action))
|
||||
f.write('trans:\n')
|
||||
for action in trans:
|
||||
f.write(' %s: %s\n' % (action.key, action.action))
|
||||
f.write(' {}: {}\n'.format(action.key, action.action))
|
||||
f.write('config:\n')
|
||||
f.write(' backup: true\n')
|
||||
f.write(' create: true\n')
|
||||
f.write(' dotpath: %s\n' % (dotpath))
|
||||
f.write(' dotpath: {}\n'.format(dotpath))
|
||||
f.write('dotfiles:\n')
|
||||
for d in dotfiles:
|
||||
f.write(' %s:\n' % (d.key))
|
||||
f.write(' dst: %s\n' % (d.dst))
|
||||
f.write(' src: %s\n' % (d.src))
|
||||
f.write(' link: %s\n' % str(d.link).lower())
|
||||
f.write(' {}:\n'.format(d.key))
|
||||
f.write(' dst: {}\n'.format(d.dst))
|
||||
f.write(' src: {}\n'.format(d.src))
|
||||
f.write(' link: {}\n'.format(str(d.link).lower()))
|
||||
if len(d.actions) > 0:
|
||||
f.write(' actions:\n')
|
||||
for action in d.actions:
|
||||
f.write(' - %s\n' % (action.key))
|
||||
f.write(' - {}\n'.format(action.key))
|
||||
if len(d.trans) > 0:
|
||||
f.write(' trans:\n')
|
||||
for action in d.trans:
|
||||
f.write(' - %s\n' % (action.key))
|
||||
f.write(' - {}\n'.format(action.key))
|
||||
f.write('profiles:\n')
|
||||
f.write(' %s:\n' % (profile))
|
||||
f.write(' {}:\n'.format(profile))
|
||||
for d in dotfiles:
|
||||
f.write(' - %s\n' % (d.key))
|
||||
f.write(' - {}\n'.format(d.key))
|
||||
return path
|
||||
|
||||
def test_install(self):
|
||||
@@ -135,7 +135,7 @@ exec bspwm
|
||||
# to test actions
|
||||
value = get_string(12)
|
||||
fact = '/tmp/action'
|
||||
act1 = Action('testaction', 'echo "%s" > %s' % (value, fact))
|
||||
act1 = Action('testaction', 'echo "{}" > {}'.format(value, fact))
|
||||
f8, c8 = create_random_file(tmp)
|
||||
dst8 = os.path.join(dst, get_string(6))
|
||||
d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1])
|
||||
|
||||
Reference in New Issue
Block a user