diff --git a/bin/find-non-ascii b/bin/find-non-ascii index b8fbcac..c8b12d1 100755 --- a/bin/find-non-ascii +++ b/bin/find-non-ascii @@ -62,11 +62,7 @@ def ignore_file(filename, globs): if not globs: return False - for glob in globs: - if fnmatch.fnmatch(filename, glob): - return False - - return True + return not any(fnmatch.fnmatch(filename, glob) for glob in globs) def find_files(args): diff --git a/bin/svn-ignore b/bin/svn-ignore index 9996d10..af37cd0 100755 --- a/bin/svn-ignore +++ b/bin/svn-ignore @@ -70,9 +70,9 @@ def main(): if filename not in svnignore_data: continue svnignore_data.remove(filename) + elif filename in svnignore_data: + continue else: - if filename in svnignore_data: - continue svnignore_data.append(filename) # Optionally sort. diff --git a/bin/unicode2ascii b/bin/unicode2ascii index e21cf7a..226ec46 100755 --- a/bin/unicode2ascii +++ b/bin/unicode2ascii @@ -66,20 +66,14 @@ def main(): args.files.append("-") for arg in args.files: - if arg == "-": - text = sys.stdin.read() - else: - text = open(arg, "rb").read() + text = sys.stdin.read() if arg == "-" else open(arg, "rb").read() utext = text.decode("utf8") utext = unicodedata.normalize("NFKD", utext) utext = utext.translate(XTABLE) try: utext.encode("ascii", "strict") except UnicodeEncodeError as err: - if arg == "-": - errfile = "" - else: - errfile = "In '%s', " % arg + errfile = "" if arg == "-" else "In '%s', " % arg sys.stderr.write( "ERROR: %s%s\n" % (errfile, str(err)) ) diff --git a/install.py b/install.py index d496a09..5399d3e 100755 --- a/install.py +++ b/install.py @@ -136,12 +136,11 @@ def clean_link(args, linkname, backup=True): os.unlink(link_pathname) elif os.path.exists(link_pathname): - if os.path.isdir(link_pathname): - if not os.listdir(link_pathname): - print("Removing empty directory '{0}'.".format(link_pathname)) - if not args.dryrun: - os.rmdir(link_pathname) - return + if os.path.isdir(link_pathname) and not os.listdir(link_pathname): + print("Removing empty directory '{0}'.".format(link_pathname)) + if not args.dryrun: + os.rmdir(link_pathname) + return # The destination exists as a file or dir. Back it up. if backup: @@ -552,13 +551,13 @@ def xfwm4_remove_key_binding(args, binding): binding ] output = force_run_command(cmdargs) - if output.find("does not exist on channel") != -1: - if args.verbose: - print("Key binding '{0}' already removed.".format(binding)) - else: + if output.find("does not exist on channel") == -1: print("Removing key binding '{0}'.".format(binding)) run_command(args, cmdargs + ["--reset"]) + elif args.verbose: + print("Key binding '{0}' already removed.".format(binding)) + def xfwm4_add_key_binding(args, binding, command): """Add a xfwm4 key binding.""" @@ -850,10 +849,10 @@ def main(): args.is_cygwin = sys.platform == "cygwin" args.is_windows = sys.platform.startswith("win") args.is_xwindows = ( - exe_in_path("xterm") and - not (args.is_cygwin or args.is_windows) + exe_in_path("xterm") and not args.is_cygwin and not args.is_windows ) + # Ensure that directories exist. mkdir(args, True, args.cache_dir, 0o700) mkdir(args, True, explicit_cache_dir, 0o700) diff --git a/pythonstartup.py b/pythonstartup.py index 3220e4a..6dc7d31 100644 --- a/pythonstartup.py +++ b/pythonstartup.py @@ -38,8 +38,7 @@ def _history_pathname(): Default is ~/.python_history, but we are trying to cleanup the user's home directory. """ - pathname = os.path.join(xdg_cache_home, "python", "history") - return pathname + return os.path.join(xdg_cache_home, "python", "history") def _save_history():