Mercurial > cpython-lru_cache-weakref
diff Tools/scripts/patchcheck.py @ 63872:5ae390ac6c61
Clean up syntax for some scripts.
| author | Florent Xicluna <florent.xicluna@gmail.com> |
|---|---|
| date | Mon, 09 Aug 2010 12:24:20 +0000 |
| parents | 7ffd2a44942c |
| children | 2e19d1f4b612 |
line wrap: on
line diff
--- a/Tools/scripts/patchcheck.py Mon Aug 09 10:47:46 2010 +0000 +++ b/Tools/scripts/patchcheck.py Mon Aug 09 12:24:20 2010 +0000 @@ -9,6 +9,7 @@ """Return 'N file(s)' with the proper plurality on 'file'.""" return "{} file{}".format(count, "s" if count != 1 else "") + def status(message, modal=False, info=None): """Decorator to output status info to stdout.""" def decorated_fxn(fxn): @@ -21,32 +22,25 @@ elif info: print(info(result)) else: - if result: - print("yes") - else: - print("NO") + print("yes" if result else "NO") return result return call_fxn return decorated_fxn + @status("Getting the list of files that have been added/changed", info=lambda x: n_files_str(len(x))) def changed_files(): """Run ``svn status`` and return a set of files that have been - changed/added.""" + changed/added. + """ cmd = 'svn status --quiet --non-interactive --ignore-externals' svn_st = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) svn_st.wait() - output = [x.decode().rstrip() for x in svn_st.stdout.readlines()] - files = set() - for line in output: - if not line[0] in ('A', 'M'): - continue - line_parts = line.split() - path = line_parts[-1] - if os.path.isfile(path): - files.add(path) - return files + output = (x.decode().rstrip().rsplit(None, 1)[-1] + for x in svn_st.stdout if x[0] in b'AM') + return set(path for path in output if os.path.isfile(path)) + def report_modified_files(file_paths): count = len(file_paths) @@ -58,6 +52,7 @@ lines.append(" {}".format(path)) return "\n".join(lines) + @status("Fixing whitespace", info=report_modified_files) def normalize_whitespace(file_paths): """Make sure that the whitespace for .py files have been normalized.""" @@ -68,16 +63,19 @@ fixed.append(path) return fixed + @status("Docs modified", modal=True) def docs_modified(file_paths): """Report if any file in the Doc directory has been changed.""" return bool(file_paths) + @status("Misc/ACKS updated", modal=True) def credit_given(file_paths): """Check if Misc/ACKS has been changed.""" return 'Misc/ACKS' in file_paths + @status("Misc/NEWS updated", modal=True) def reported_news(file_paths): """Check if Misc/NEWS has been changed."""
