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

refactor string format to .format

This commit is contained in:
deadc0de6
2018-05-02 21:27:37 +02:00
parent f68ddeb06f
commit 445ec3e89c
9 changed files with 108 additions and 106 deletions

View File

@@ -20,7 +20,7 @@ class Action:
def execute(self): def execute(self):
ret = 1 ret = 1
self.log.sub('executing \"%s\"' % (self.action)) self.log.sub('executing \"{}\"'.format(self.action))
try: try:
ret = subprocess.call(self.action, shell=True) ret = subprocess.call(self.action, shell=True)
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -32,12 +32,12 @@ class Action:
where {0} is the file to transform and where {0} is the file to transform and
{1} is the result file''' {1} is the result file'''
if os.path.exists(arg1): if os.path.exists(arg1):
msg = 'transformation destination exists: %s' msg = 'transformation destination exists: {}'
self.log.warn(msg % (arg1)) self.log.warn(msg.format(arg1))
return False return False
ret = 1 ret = 1
cmd = self.action.format(arg0, arg1) cmd = self.action.format(arg0, arg1)
self.log.sub('transforming with \"%s\"' % (cmd)) self.log.sub('transforming with \"{}\"'.format(cmd))
try: try:
ret = subprocess.call(cmd, shell=True) ret = subprocess.call(cmd, shell=True)
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -45,7 +45,7 @@ class Action:
return ret == 0 return ret == 0
def __str__(self): def __str__(self):
return 'key:%s -> \"%s\"' % (self.key, self.action) return 'key:{} -> \"{}\"'.format(self.key, self.action)
def __eq__(self, other): def __eq__(self, other):
return self.__dict__ == other.__dict__ return self.__dict__ == other.__dict__

View File

@@ -58,13 +58,13 @@ class Cfg:
def _is_valid(self): def _is_valid(self):
if self.key_profiles not in self.content: 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 return False
if self.key_config not in self.content: 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 return False
if self.key_dotfiles not in self.content: 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 return False
if self.content[self.key_profiles]: if self.content[self.key_profiles]:
# make sure dotfiles are in a sub called "dotfiles" # make sure dotfiles are in a sub called "dotfiles"
@@ -85,7 +85,7 @@ class Cfg:
res = [] res = []
for entry in entries: for entry in entries:
if entry not in actions.keys(): if entry not in actions.keys():
self.log.warn('unknown action \"%s\"' % (entry)) self.log.warn('unknown action \"{}\"'.format(entry))
continue continue
res.append(actions[entry]) res.append(actions[entry])
return res return res
@@ -131,8 +131,8 @@ class Cfg:
self.key_dotfiles_trans in v else [] self.key_dotfiles_trans in v else []
trans = self._parse_actions(self.trans, entries) trans = self._parse_actions(self.trans, entries)
if len(trans) > 0 and link: if len(trans) > 0 and link:
msg = 'transformations disabled for \"%s\"' % (dst) msg = 'transformations disabled for \"{}\"'.format(dst)
msg += ' as link is True' % (dst) msg += ' because link is True'
self.log.warn(msg) self.log.warn(msg)
trans = [] trans = []
self.dotfiles[k] = Dotfile(k, dst, src, link=link, self.dotfiles[k] = Dotfile(k, dst, src, link=link,
@@ -172,7 +172,7 @@ class Cfg:
return included return included
for other in self.profiles[profile][self.key_profiles_incl]: for other in self.profiles[profile][self.key_profiles_incl]:
if other not in self.prodots: if other not in self.prodots:
self.log.warn('unknown included profile \"%s\"' % (other)) self.log.warn('unknown included profile \"{}\"'.format(other))
continue continue
included.extend(self.prodots[other]) included.extend(self.prodots[other])
return included return included
@@ -206,7 +206,7 @@ class Cfg:
if dotfile.key in self.dotfiles.keys(): if dotfile.key in self.dotfiles.keys():
# already in it # already in it
if profile in self.prodots and dotfile in self.prodots[profile]: 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 return False
# add for this profile # add for this profile

View File

@@ -37,11 +37,11 @@ TRANS_SUFFIX = 'trans'
BANNER = """ _ _ _ BANNER = """ _ _ _
__| | ___ | |_ __| |_ __ ___ _ __ __| | ___ | |_ __| |_ __ ___ _ __
/ _` |/ _ \| __/ _` | '__/ _ \| '_ | / _` |/ _ \| __/ _` | '__/ _ \| '_ |
\__,_|\___/ \__\__,_|_| \___/| .__/ v%s \__,_|\___/ \__\__,_|_| \___/| .__/ v{}
|_|""" % (VERSION) |_|""".format(VERSION)
USAGE = """ USAGE = """
%s {}
Usage: Usage:
dotdrop install [-fndV] [-c <path>] [-p <profile>] dotdrop install [-fndV] [-c <path>] [-p <profile>]
@@ -55,7 +55,7 @@ Usage:
dotdrop --version dotdrop --version
Options: 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]. -c --cfg=<path> Path to the config [default: config.yaml].
--files=<files> Comma separated list of files to compare. --files=<files> Comma separated list of files to compare.
-o --dopts=<opts> Diff options [default: ]. -o --dopts=<opts> Diff options [default: ].
@@ -67,7 +67,7 @@ Options:
-v --version Show version. -v --version Show version.
-h --help Show this screen. -h --help Show this screen.
""" % (BANNER, HOSTNAME) """.format(BANNER, HOSTNAME)
########################################################### ###########################################################
# entry point # entry point
@@ -77,8 +77,8 @@ Options:
def install(opts, conf): def install(opts, conf):
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\")' % msg = 'no dotfiles defined for this profile (\"{}\")'
(opts['profile'])) LOG.err(msg.format(opts['profile']))
return False return False
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'],
@@ -93,15 +93,15 @@ def install(opts, conf):
src = dotfile.src src = dotfile.src
tmp = None tmp = None
if dotfile.trans: if dotfile.trans:
tmp = '%s.%s' % (src, TRANS_SUFFIX) tmp = '{}.{}'.format(src, TRANS_SUFFIX)
err = False err = False
for trans in dotfile.trans: for trans in dotfile.trans:
LOG.dbg('executing transformation {}'.format(trans)) LOG.dbg('executing transformation {}'.format(trans))
s = os.path.join(opts['dotpath'], src) s = os.path.join(opts['dotpath'], src)
temp = os.path.join(opts['dotpath'], tmp) temp = os.path.join(opts['dotpath'], tmp)
if not trans.transform(s, temp): if not trans.transform(s, temp):
msg = 'transformation \"%s\" failed for %s' msg = 'transformation \"{}\" failed for {}'
LOG.err(msg % (trans.key, dotfile.key)) LOG.err(msg.format(trans.key, dotfile.key))
err = True err = True
break break
if err: if err:
@@ -120,7 +120,7 @@ def install(opts, conf):
LOG.dbg('executing action {}'.format(action)) LOG.dbg('executing action {}'.format(action))
action.execute() action.execute()
installed.extend(r) installed.extend(r)
LOG.log('\n%u dotfile(s) installed.' % (len(installed))) LOG.log('\n{} dotfile(s) installed.'.format(len(installed)))
return True return True
@@ -128,8 +128,8 @@ def compare(opts, conf, tmp, focus=None):
'''compare dotfiles and return True if all same''' '''compare dotfiles and return True if all same'''
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\")' % msg = 'no dotfiles defined for this profile (\"{}\")'
(opts['profile'])) LOG.err(msg.format(opts['profile']))
return True return True
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'],
@@ -146,7 +146,7 @@ def compare(opts, conf, tmp, focus=None):
if df: if df:
selected.append(df) selected.append(df)
else: else:
LOG.err('no dotfile matches \"%s\"' % (selection)) LOG.err('no dotfile matches \"{}\"'.format(selection))
ret = False ret = False
if len(selected) < 1: if len(selected) < 1:
@@ -155,18 +155,19 @@ def compare(opts, conf, tmp, focus=None):
for dotfile in selected: for dotfile in selected:
LOG.dbg('comparing {}'.format(dotfile)) LOG.dbg('comparing {}'.format(dotfile))
if dotfile.trans: if dotfile.trans:
msg = 'ignore %s as it uses transformation(s)' msg = 'ignore {} as it uses transformation(s)'
LOG.log(msg % (dotfile.key)) LOG.log(msg.format(dotfile.key))
continue continue
same, diff = inst.compare(t, tmp, opts['profile'], same, diff = inst.compare(t, tmp, opts['profile'],
dotfile.src, dotfile.dst, dotfile.src, dotfile.dst,
opts=opts['dopts']) opts=opts['dopts'])
if same: if same:
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key, LOG.dbg('diffing \"{}\" VS \"{}\"'.format(dotfile.key,
dotfile.dst)) dotfile.dst))
LOG.dbg('same file') LOG.dbg('same file')
else: else:
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst)) LOG.log('diffing \"{}\" VS \"{}\"'.format(dotfile.key,
dotfile.dst))
LOG.emph(diff) LOG.emph(diff)
ret = False ret = False
@@ -175,7 +176,7 @@ def compare(opts, conf, tmp, focus=None):
def update(opts, conf, path): def update(opts, conf, path):
if not os.path.exists(path): if not os.path.exists(path):
LOG.err('\"%s\" does not exist!' % (path)) LOG.err('\"{}\" does not exist!'.format(path))
return False return False
home = os.path.expanduser(TILD) home = os.path.expanduser(TILD)
path = os.path.expanduser(path) path = os.path.expanduser(path)
@@ -187,27 +188,27 @@ def update(opts, conf, path):
dotfiles = conf.get_dotfiles(opts['profile']) dotfiles = conf.get_dotfiles(opts['profile'])
subs = [d for d in dotfiles if d.dst == path] subs = [d for d in dotfiles if d.dst == path]
if not subs: if not subs:
LOG.err('\"%s\" is not managed!' % (path)) LOG.err('\"{}\" is not managed!'.format(path))
return False return False
if len(subs) > 1: if len(subs) > 1:
found = ','.join([d.src for d in dotfiles]) found = ','.join([d.src for d in dotfiles])
LOG.err('multiple dotfiles found: %s' % (found)) LOG.err('multiple dotfiles found: {}'.format(found))
return False return False
dotfile = subs[0] dotfile = subs[0]
src = os.path.join(conf.get_abs_dotpath(opts['dotpath']), dotfile.src) src = os.path.join(conf.get_abs_dotpath(opts['dotpath']), dotfile.src)
if Templategen.get_marker() in open(src, 'r').read(): 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 return False
cmd = ['cp', '-R', '-L', os.path.expanduser(path), src] cmd = ['cp', '-R', '-L', os.path.expanduser(path), src]
if opts['dry']: if opts['dry']:
LOG.dry('would run: %s' % (' '.join(cmd))) LOG.dry('would run: {}'.format(' '.join(cmd)))
else: else:
msg = 'Overwrite \"%s\" with \"%s\"?' % (src, path) msg = 'Overwrite \"{}\" with \"{}\"?'.format(src, 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) run(cmd, raw=False)
LOG.log('\"%s\" updated from \"%s\".' % (src, path)) LOG.log('\"{}\" updated from \"{}\".'.format(src, path))
return True return True
@@ -216,7 +217,7 @@ def importer(opts, conf, paths):
cnt = 0 cnt = 0
for path in paths: for path in paths:
if not os.path.exists(path): if not os.path.exists(path):
LOG.err('\"%s\" does not exist, ignored !' % (path)) LOG.err('\"{}\" does not exist, ignored !'.format(path))
continue continue
dst = path.rstrip(os.sep) dst = path.rstrip(os.sep)
key = dst.split(os.sep)[-1] key = dst.split(os.sep)[-1]
@@ -224,9 +225,9 @@ def importer(opts, conf, paths):
key = '_'.join(dst.split(os.sep)[-2:]) key = '_'.join(dst.split(os.sep)[-2:])
key = key.lstrip('.').lower() key = key.lstrip('.').lower()
if os.path.isdir(dst): if os.path.isdir(dst):
key = 'd_%s' % (key) key = 'd_{}'.format(key)
else: else:
key = 'f_%s' % (key) key = 'f_{}'.format(key)
src = dst src = dst
if dst.startswith(home): if dst.startswith(home):
src = dst[len(home):] src = dst[len(home):]
@@ -235,32 +236,32 @@ def importer(opts, conf, paths):
srcf = os.path.join(CUR, opts['dotpath'], src) srcf = os.path.join(CUR, opts['dotpath'], src)
retconf = conf.new(dotfile, opts['profile'], opts['link']) retconf = conf.new(dotfile, opts['profile'], opts['link'])
if not os.path.exists(srcf): 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']: if opts['dry']:
LOG.dry('would run: %s' % (' '.join(cmd))) LOG.dry('would run: {}'.format(' '.join(cmd)))
else: else:
run(cmd, raw=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: {}'.format(' '.join(cmd)))
if opts['link']: if opts['link']:
LOG.dry('would symlink %s to %s' % (srcf, dst)) LOG.dry('would symlink {} to {}'.format(srcf, dst))
else: else:
run(cmd, raw=False) run(cmd, raw=False)
if opts['link']: if opts['link']:
remove(dst) remove(dst)
os.symlink(srcf, dst) os.symlink(srcf, dst)
if retconf: if retconf:
LOG.sub('\"%s\" imported' % (path)) LOG.sub('\"{}\" imported'.format(path))
cnt += 1 cnt += 1
else: else:
LOG.warn('\"%s\" ignored' % (path)) LOG.warn('\"{}\" ignored'.format(path))
if opts['dry']: if opts['dry']:
LOG.dry('new config file would be:') LOG.dry('new config file would be:')
LOG.raw(conf.dump()) LOG.raw(conf.dump())
else: else:
conf.save() conf.save()
LOG.log('\n%u file(s) imported.' % (cnt)) LOG.log('\n{} file(s) imported.'.format(cnt))
def list_profiles(conf): def list_profiles(conf):
@@ -272,13 +273,13 @@ def list_profiles(conf):
def list_files(opts, conf): def list_files(opts, conf):
if not opts['profile'] in conf.get_profiles(): if not opts['profile'] in conf.get_profiles():
LOG.warn('unknown profile \"%s\"' % (opts['profile'])) LOG.warn('unknown profile \"{}\"'.format(opts['profile']))
return 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']): for dotfile in conf.get_dotfiles(opts['profile']):
LOG.log('%s (file: \"%s\", link: %s)' % (dotfile.key, dotfile.src, LOG.log('{} (file: \"{}\", link: {})'.format(dotfile.key, dotfile.src,
str(dotfile.link))) dotfile.link))
LOG.sub('%s' % (dotfile.dst)) LOG.sub('{}'.format(dotfile.dst))
LOG.log('') LOG.log('')
@@ -293,7 +294,7 @@ def main():
try: try:
conf = Cfg(os.path.expanduser(args['--cfg'])) conf = Cfg(os.path.expanduser(args['--cfg']))
except ValueError as e: except ValueError as e:
LOG.err('error: %s' % (str(e))) LOG.err('error: {}'.format(str(e)))
return False return False
opts = conf.get_configs() opts = conf.get_configs()
@@ -329,7 +330,7 @@ def main():
opts['dopts'] = args['--dopts'] opts['dopts'] = args['--dopts']
ret = compare(opts, conf, tmp, args['--files']) ret = compare(opts, conf, tmp, args['--files'])
if os.listdir(tmp): if os.listdir(tmp):
LOG.raw('\ntemporary files available under %s' % (tmp)) LOG.raw('\ntemporary files available under {}'.format(tmp))
else: else:
os.rmdir(tmp) os.rmdir(tmp)

View File

@@ -23,8 +23,8 @@ class Dotfile:
self.trans = trans self.trans = trans
def __str__(self): def __str__(self):
return 'key:\"%s\", src:\"%s\", dst:\"%s\", link:\"%s\"' % (self.key, self.src, msg = 'key:\"{}\", src:\"{}\", dst:\"{}\", link:\"{}\"'
self.dst, self.link) return msg.format(self.key, self.src, self.dst, self.link)
def __eq__(self, other): def __eq__(self, other):
return self.__dict__ == other.__dict__ return self.__dict__ == other.__dict__

View File

@@ -42,30 +42,30 @@ class Installer:
dst = os.path.join(self.base, os.path.expanduser(dst)) dst = os.path.join(self.base, os.path.expanduser(dst))
if os.path.exists(dst): if os.path.exists(dst):
if os.path.realpath(dst) == os.path.realpath(src): 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 [] return []
if self.dry: if self.dry:
self.log.dry('would remove %s and link it to %s' self.log.dry('would remove {} and link to {}'.format(dst, src))
% (dst, src))
return [] return []
if self.safe and \ msg = 'Remove "{}" for link creation?'.format(dst)
not self.log.ask('Remove "%s" for link creation?' % dst): if self.safe and not self.log.ask(msg):
self.log.warn('ignoring "%s", link was not created' % dst) msg = 'ignoring "{}", link was not created'
self.log.warn(msg.format(dst))
return [] return []
try: try:
utils.remove(dst) utils.remove(dst)
except OSError: except OSError:
self.log.err('something went wrong with %s' % src) self.log.err('something went wrong with {}'.format(src))
return [] return []
if self.dry: if self.dry:
self.log.dry('would link %s to %s' % (dst, src)) self.log.dry('would link {} to {}'.format(dst, src))
return [] return []
base = os.path.dirname(dst) base = os.path.dirname(dst)
if not self._create_dirs(base): if not self._create_dirs(base):
self.log.err('creating directory for \"%s\"' % (dst)) self.log.err('creating directory for \"{}\"'.format(dst))
return [] return []
os.symlink(src, dst) 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 # Follows original developer's behavior
return [(src, dst)] return [(src, dst)]
@@ -74,22 +74,22 @@ class Installer:
self.log.dbg('generate template for {}'.format(src)) self.log.dbg('generate template for {}'.format(src))
content = templater.generate(src, profile) content = templater.generate(src, profile)
if content is None: if content is None:
self.log.err('generate from template \"%s\"' % (src)) self.log.err('generate from template \"{}\"'.format(src))
return [] return []
if not os.path.exists(src): 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 [] return []
st = os.stat(src) st = os.stat(src)
ret = self._write(dst, content, st.st_mode) ret = self._write(dst, content, st.st_mode)
if ret < 0: if ret < 0:
self.log.err('installing \"%s\" to \"%s\"' % (src, dst)) self.log.err('installing \"{}\" to \"{}\"'.format(src, dst))
return [] return []
if ret > 0: if ret > 0:
self.log.dbg('ignoring \"%s\", same content' % (dst)) self.log.dbg('ignoring \"{}\", same content'.format(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:
self.log.sub('copied \"%s\" to \"%s\"' % (src, dst)) self.log.sub('copied \"{}\" to \"{}\"'.format(src, dst))
return [(src, dst)] return [(src, dst)]
return [] return []
@@ -121,28 +121,28 @@ class Installer:
1 when already exists 1 when already exists
-1 when error''' -1 when error'''
if self.dry: if self.dry:
self.log.dry('would install %s' % (dst)) self.log.dry('would install {}'.format(dst))
return 0 return 0
if os.path.exists(dst): if os.path.exists(dst):
samerights = os.stat(dst).st_mode == rights samerights = os.stat(dst).st_mode == rights
if self.diff and self._fake_diff(dst, content) and samerights: if self.diff and self._fake_diff(dst, content) and samerights:
self.log.dbg('{} is the same'.format(dst)) self.log.dbg('{} is the same'.format(dst))
return 1 return 1
if self.safe and not self.log.ask('Overwrite \"%s\"' % (dst)): if self.safe and not self.log.ask('Overwrite \"{}\"'.format(dst)):
self.log.warn('ignoring \"%s\", already present' % (dst)) self.log.warn('ignoring \"{}\", already present'.format(dst))
return 1 return 1
if self.backup and os.path.exists(dst): if self.backup and os.path.exists(dst):
self._backup(dst) self._backup(dst)
base = os.path.dirname(dst) base = os.path.dirname(dst)
if not self._create_dirs(base): if not self._create_dirs(base):
self.log.err('creating directory for \"%s\"' % (dst)) self.log.err('creating directory for \"{}\"'.format(dst))
return -1 return -1
self.log.dbg('write content to {}'.format(dst)) self.log.dbg('write content to {}'.format(dst))
try: try:
with open(dst, 'wb') as f: with open(dst, 'wb') as f:
f.write(content) f.write(content)
except NotADirectoryError as e: except NotADirectoryError as e:
self.log.err('opening dest file: %s' % (e)) self.log.err('opening dest file: {}'.format(e))
return -1 return -1
os.chmod(dst, rights) os.chmod(dst, rights)
return 0 return 0
@@ -162,7 +162,7 @@ class Installer:
if self.dry: if self.dry:
return return
dst = path.rstrip(os.sep) + self.BACKUP_SUFFIX 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) os.rename(path, dst)
def _install_to_temp(self, templater, profile, src, dst, tmpdir): def _install_to_temp(self, templater, profile, src, dst, tmpdir):
@@ -187,7 +187,7 @@ class Installer:
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
self.log.dbg('comparing {} and {}'.format(src, dst)) self.log.dbg('comparing {} and {}'.format(src, dst))
if not os.path.exists(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: else:
ret, tmpdst = self._install_to_temp(templater, ret, tmpdst = self._install_to_temp(templater,
profile, profile,

View File

@@ -24,27 +24,27 @@ class Logger:
def log(self, string, end='\n', pre=''): def log(self, string, end='\n', pre=''):
cs = self._color(self.BLUE) cs = self._color(self.BLUE)
ce = self._color(self.RESET) 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): def sub(self, string):
cs = self._color(self.BLUE) cs = self._color(self.BLUE)
ce = self._color(self.RESET) 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): def emph(self, string):
cs = self._color(self.EMPH) cs = self._color(self.EMPH)
ce = self._color(self.RESET) 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'): def err(self, string, end='\n'):
cs = self._color(self.RED) cs = self._color(self.RED)
ce = self._color(self.RESET) 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'): def warn(self, string, end='\n'):
cs = self._color(self.YELLOW) cs = self._color(self.YELLOW)
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('{}[WARN] {} {}{}'.format(cs, string, end, ce))
def dbg(self, string): def dbg(self, string):
if not self.debug: if not self.debug:
@@ -54,20 +54,21 @@ class Logger:
func = inspect.stack()[1][3] func = inspect.stack()[1][3]
cs = self._color(self.MAGENTA) cs = self._color(self.MAGENTA)
ce = self._color(self.RESET) 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'): 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)
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'): def raw(self, string, end='\n'):
sys.stdout.write('%s%s' % (string, end)) sys.stdout.write('{}{}'.format(string, end))
def ask(self, query): def ask(self, query):
cs = self._color(self.BLUE) cs = self._color(self.BLUE)
ce = self._color(self.RESET) ce = self._color(self.RESET)
q = '%s%s%s' % (cs, query + ' [y/N] ? ', ce) q = '{}{}{}'.format(cs, query + ' [y/N] ? ', ce)
r = input(q) r = input(q)
return r == 'y' return r == 'y'

View File

@@ -26,7 +26,7 @@ def run(cmd, raw=True):
def diff(src, dst, 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 {} \"{}\" \"{}\"'.format(opts, src, dst)
return run(shlex.split(cmd), raw=raw) return run(shlex.split(cmd), raw=raw)
@@ -42,10 +42,10 @@ def get_tmpfile():
def remove(path): def remove(path):
''' Remove a file / directory / symlink ''' ''' Remove a file / directory / symlink '''
if not os.path.exists(path): 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): if os.path.islink(path) or os.path.isfile(path):
os.unlink(path) os.unlink(path)
elif os.path.isdir(path): elif os.path.isdir(path):
rmtree(path) rmtree(path)
else: else:
raise OSError("Unsupported file type for deletion: %s" % path) raise OSError("Unsupported file type for deletion: {}".format(path))

View File

@@ -99,9 +99,9 @@ def create_fake_config(directory, configname='config.yaml',
path = os.path.join(directory, configname) path = os.path.join(directory, configname)
with open(path, 'w') as f: with open(path, 'w') as f:
f.write('config:\n') f.write('config:\n')
f.write(' backup: %s\n' % (str(backup))) f.write(' backup: {}\n'.format(str(backup)))
f.write(' create: %s\n' % (str(create))) f.write(' create: {}\n'.format(str(create)))
f.write(' dotpath: %s\n' % (dotpath)) f.write(' dotpath: {}\n'.format(dotpath))
f.write('dotfiles:\n') f.write('dotfiles:\n')
f.write('profiles:\n') f.write('profiles:\n')
f.write('actions:\n') f.write('actions:\n')

View File

@@ -37,32 +37,32 @@ exec bspwm
with open(path, 'w') as f: with open(path, 'w') as f:
f.write('actions:\n') f.write('actions:\n')
for action in actions: 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') f.write('trans:\n')
for action in trans: 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('config:\n')
f.write(' backup: true\n') f.write(' backup: true\n')
f.write(' create: true\n') f.write(' create: true\n')
f.write(' dotpath: %s\n' % (dotpath)) f.write(' dotpath: {}\n'.format(dotpath))
f.write('dotfiles:\n') f.write('dotfiles:\n')
for d in dotfiles: for d in dotfiles:
f.write(' %s:\n' % (d.key)) f.write(' {}:\n'.format(d.key))
f.write(' dst: %s\n' % (d.dst)) f.write(' dst: {}\n'.format(d.dst))
f.write(' src: %s\n' % (d.src)) f.write(' src: {}\n'.format(d.src))
f.write(' link: %s\n' % str(d.link).lower()) f.write(' link: {}\n'.format(str(d.link).lower()))
if len(d.actions) > 0: if len(d.actions) > 0:
f.write(' actions:\n') f.write(' actions:\n')
for action in d.actions: for action in d.actions:
f.write(' - %s\n' % (action.key)) f.write(' - {}\n'.format(action.key))
if len(d.trans) > 0: if len(d.trans) > 0:
f.write(' trans:\n') f.write(' trans:\n')
for action in d.trans: for action in d.trans:
f.write(' - %s\n' % (action.key)) f.write(' - {}\n'.format(action.key))
f.write('profiles:\n') f.write('profiles:\n')
f.write(' %s:\n' % (profile)) f.write(' {}:\n'.format(profile))
for d in dotfiles: for d in dotfiles:
f.write(' - %s\n' % (d.key)) f.write(' - {}\n'.format(d.key))
return path return path
def test_install(self): def test_install(self):
@@ -135,7 +135,7 @@ exec bspwm
# to test actions # to test actions
value = get_string(12) value = get_string(12)
fact = '/tmp/action' fact = '/tmp/action'
act1 = Action('testaction', 'echo "%s" > %s' % (value, fact)) act1 = Action('testaction', 'echo "{}" > {}'.format(value, fact))
f8, c8 = create_random_file(tmp) f8, c8 = create_random_file(tmp)
dst8 = os.path.join(dst, get_string(6)) dst8 = os.path.join(dst, get_string(6))
d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1]) d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1])