summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/patchcheck.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-08-09 12:24:20 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-08-09 12:24:20 (GMT)
commite4a3380bb07a1bae5fde5d7b4e96519ca603319c (patch)
treedaec3d767896f943aa29af95cf1090b58b4ebddd /Tools/scripts/patchcheck.py
parentaba74bddd69f98217e6148e117aec0d607f1d7f7 (diff)
downloadcpython-e4a3380bb07a1bae5fde5d7b4e96519ca603319c.zip
cpython-e4a3380bb07a1bae5fde5d7b4e96519ca603319c.tar.gz
cpython-e4a3380bb07a1bae5fde5d7b4e96519ca603319c.tar.bz2
Clean up syntax for some scripts.
Diffstat (limited to 'Tools/scripts/patchcheck.py')
-rw-r--r--Tools/scripts/patchcheck.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py
index 7d001e8..1e2002f 100644
--- a/Tools/scripts/patchcheck.py
+++ b/Tools/scripts/patchcheck.py
@@ -9,6 +9,7 @@ def n_files_str(count):
"""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 @@ def status(message, modal=False, info=None):
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 @@ def report_modified_files(file_paths):
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 @@ def normalize_whitespace(file_paths):
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."""