diff --git a/src/usr/bin/diffuse b/src/usr/bin/diffuse index 130c8c4..ba21102 100755 --- a/src/usr/bin/diffuse +++ b/src/usr/bin/diffuse @@ -75,7 +75,7 @@ if __name__ == '__main__': args = sys.argv argc = len(args) if argc == 2 and args[1] in [ '-v', '--version' ]: - print('%s %s\n%s' % (APP_NAME, VERSION, COPYRIGHT)) + print(f'{APP_NAME} {VERSION}\n{COPYRIGHT}') sys.exit(0) if argc == 2 and args[1] in [ '-h', '-?', '--help' ]: print(_('''Usage: @@ -156,7 +156,7 @@ if not hasattr(__builtins__, 'WindowsError'): # convenience function to display debug messages def logDebug(s): - pass #sys.stderr.write('%s: %s\n', (APP_NAME, s)) + pass #sys.stderr.write(f'{APP_NAME}: {s}\n') # avoid some dictionary lookups when string.whitespace is used in loops # this is sorted based upon frequency to speed up code for stripping whitespace @@ -164,7 +164,7 @@ whitespace = ' \t\n\r\x0b\x0c' # escape special glob characters def globEscape(s): - m = dict([ (c, u'[%s]' % (c, )) for c in u'[]?*' ]) + m = dict([ (c, f'[{c}]') for c in u'[]?*' ]) return u''.join([ m.get(c, c) for c in s ]) # associate our icon with all of our windows @@ -544,7 +544,7 @@ class Resources: try: return self.colours[symbol] except KeyError: - logDebug('Warning: unknown colour "%s"' % (symbol, )) + logDebug(f'Warning: unknown colour "{symbol}"') self.colours[symbol] = v = Colour(0.0, 0.0, 0.0) return v @@ -553,7 +553,7 @@ class Resources: try: return self.floats[symbol] except KeyError: - logDebug('Warning: unknown float "%s"' % (symbol, )) + logDebug(f'Warning: unknown float "{symbol}"') self.floats[symbol] = v = 0.5 return v @@ -562,7 +562,7 @@ class Resources: try: return self.strings[symbol] except KeyError: - logDebug('Warning: unknown string "%s"' % (symbol, )) + logDebug(f'Warning: unknown string "{symbol}"') self.strings[symbol] = v = '' return v @@ -949,10 +949,10 @@ class Preferences: except ValueError: # this may happen if the prefs were written by a # different version -- don't bother the user - logDebug('Error processing line %d of %s.' % (j + 1, self.path)) + logDebug(f'Error processing line {j + 1} of {self.path}.') except IOError: # bad $HOME value? -- don't bother the user - logDebug('Error reading %s.' % (self.path, )) + logDebug(f'Error reading {self.path}.') # recursively traverses 'template' to discover the preferences and # initialise their default values in self.bool_prefs, self.int_prefs, and @@ -1011,16 +1011,17 @@ class Preferences: ss = [] for k, v in self.bool_prefs.items(): if v != self.default_bool_prefs[k]: - ss.append('%s %s\n' % (k, v)) + ss.append(f'{k} {v}\n') for k, v in self.int_prefs.items(): if v != self.default_int_prefs[k]: - ss.append('%s %s\n' % (k, v)) + ss.append(f'{k} {v}\n') for k, v in self.string_prefs.items(): if v != self.default_string_prefs[k]: - ss.append('%s "%s"\n' % (k, v.replace('\\', '\\\\').replace('"', '\\"'))) + v_escaped = v.replace('\\', '\\\\').replace('"', '\\"') + ss.append(f'{k} "{v_escaped}"\n') ss.sort() f = open(self.path, 'w') - f.write('# This prefs file was generated by %s %s.\n\n' % (APP_NAME, VERSION)) + f.write(f'# This prefs file was generated by {APP_NAME} {VERSION}.\n\n') for s in ss: f.write(s) f.close() @@ -1351,7 +1352,7 @@ def popenRead(dn, cmd, prefs, bash_pref, success_results=None): success_results = [ 0 ] if isWindows() and prefs.getBool(bash_pref): # launch the command from a bash shell is requested - cmd = [ prefs.convertToNativePath('/bin/bash.exe'), '-l', '-c', 'cd %s; %s' % (bashEscape(dn), ' '.join([ bashEscape(arg) for arg in cmd ])) ] + cmd = [ prefs.convertToNativePath('/bin/bash.exe'), '-l', '-c', 'cd {}; {}'.format(bashEscape(dn), ' '.join([ bashEscape(arg) for arg in cmd ])) ] dn = None # use subprocess.Popen to retrieve the file contents if isWindows(): @@ -1948,7 +1949,7 @@ class _Git: return result def getRevision(self, prefs, name, rev): - return popenRead(self.root, [ prefs.getString('git_bin'), 'show', '%s:%s' % (rev, relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')) ], prefs, 'git_bash') + return popenRead(self.root, [ prefs.getString('git_bin'), 'show', '{}:{}'.format(rev, relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')) ], prefs, 'git_bash') def _get_git_repo(path, prefs): if 'GIT_DIR' in os.environ: @@ -2003,7 +2004,7 @@ class _Hg: prev = prev[:-1] self.working_rev = prev return self.working_rev - return 'p1(%s)' % (rev, ) + return f'p1({rev})' def getFileTemplate(self, prefs, name): return [ (name, self._getPreviousRevision(prefs, None)), (name, None) ] @@ -2488,7 +2489,7 @@ class _Svn: # determine which are directories added = {} for p, v in m.items(): - for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', rev, '%s/%s' % (self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): + for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', rev, '{}/{}'.format(self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): if s in v: # confirmed as added file k = os.path.join(self.root, os.path.join(p, s)) @@ -2514,7 +2515,7 @@ class _Svn: m[d].add(b) removed_dir, removed = set(), {} for p, v in m.items(): - for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', prev, '%s/%s' % (self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): + for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', prev, '{}/{}'.format(self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): if s.endswith('/'): s = s[:-1] if s in v: @@ -2532,7 +2533,7 @@ class _Svn: tmp = removed_dir removed_dir = set() for p in tmp: - for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', prev, '%s/%s' % (self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): + for s in popenReadLines(self.root, [ vcs_bin, 'list', '-r', prev, '{}/{}'.format(self._getURL(prefs), p.replace(os.sep, '/')) ], prefs, vcs_bash): if s.endswith('/'): # confirmed item as directory removed_dir.add(os.path.join(p, s[:-1])) @@ -2561,8 +2562,8 @@ class _Svn: def getRevision(self, prefs, name, rev): vcs_bin = prefs.getString('svn_bin') if rev in [ 'BASE', 'COMMITTED', 'PREV' ]: - return popenRead(self.root, [ vcs_bin, 'cat', '%s@%s' % (safeRelativePath(self.root, name, prefs, 'svn_cygwin'), rev) ], prefs, 'svn_bash') - return popenRead(self.root, [ vcs_bin, 'cat', '%s/%s@%s' % (self._getURL(prefs), relpath(self.root, os.path.abspath(name)).replace(os.sep, '/'), rev) ], prefs, 'svn_bash') + return popenRead(self.root, [ vcs_bin, 'cat', '{}@{}'.format(safeRelativePath(self.root, name, prefs, 'svn_cygwin'), rev) ], prefs, 'svn_bash') + return popenRead(self.root, [ vcs_bin, 'cat', '{}/{}@{}'.format(self._getURL(prefs), relpath(self.root, os.path.abspath(name)).replace(os.sep, '/'), rev) ], prefs, 'svn_bash') def _get_svn_repo(path, prefs): p = _find_parent_dir_with(path, '.svn') @@ -2592,7 +2593,7 @@ class _Svk(_Svn): return str(int(rev) - 1) def getRevision(self, prefs, name, rev): - return popenRead(self.root, [ prefs.getString('svk_bin'), 'cat', '-r', rev, '%s/%s' % (self._getURL(prefs), relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')) ], prefs, 'svk_bash') + return popenRead(self.root, [ prefs.getString('svk_bin'), 'cat', '-r', rev, '{}/{}'.format(self._getURL(prefs), relpath(self.root, os.path.abspath(name)).replace(os.sep, '/')) ], prefs, 'svk_bash') def _get_svk_repo(path, prefs): name = path @@ -7654,10 +7655,10 @@ class Diffuse(Gtk.Window): except ValueError: # this may happen if the state was written by a # different version -- don't bother the user - logDebug('Error processing line %d of %s.' % (j + 1, statepath)) + logDebug(f'Error processing line {j + 1} of {statepath}.') except IOError: # bad $HOME value? -- don't bother the user - logDebug('Error reading %s.' % (statepath, )) + logDebug(f'Error reading {statepath}.') self.move(self.int_state['window_x'], self.int_state['window_y']) self.resize(self.int_state['window_width'], self.int_state['window_height']) @@ -7669,18 +7670,18 @@ class Diffuse(Gtk.Window): try: ss = [] for k, v in self.bool_state.items(): - ss.append('%s %s\n' % (k, v)) + ss.append(f'{k} {v}\n') for k, v in self.int_state.items(): - ss.append('%s %s\n' % (k, v)) + ss.append(f'{k} {v}\n') ss.sort() f = open(statepath, 'w') - f.write("# This state file was generated by %s %s.\n\n" % (APP_NAME, VERSION)) + f.write(f"# This state file was generated by {APP_NAME} {VERSION}.\n\n") for s in ss: f.write(s) f.close() except IOError: # bad $HOME value? -- don't bother the user - logDebug('Error writing %s.' % (statepath, )) + logDebug(f'Error writing {statepath}.') # select viewer for a newly selected file in the confirm close dialogue def __confirmClose_row_activated_cb(self, tree, path, col, model): @@ -7801,7 +7802,7 @@ class Diffuse(Gtk.Window): # update window's title def updateTitle(self, viewer): title = self.notebook.get_tab_label(viewer).get_text() - self.set_title('%s - %s' % (title, APP_NAME)) + self.set_title(f'{title} - {APP_NAME}') # update the message in the status bar def setStatus(self, s):