Improve validation of removed files

Print nicer output, let git do the check whether files
were removed.

Change-Id: I1ee57eb95aa827005e510160d8a9095a87947e55
This commit is contained in:
Andreas Jaeger 2013-09-22 11:49:53 +02:00
parent 8af4a16bea
commit 99b93dc27e
2 changed files with 99 additions and 92 deletions

29
test.py
View File

@ -155,7 +155,7 @@ def only_www_touched():
return www_changed and not other_changed
def get_modified_files(rootdir):
def get_modified_files(rootdir, filter=None):
"""Get modified files below doc directory"""
# There are several tree traversals in this program that do a
@ -165,6 +165,8 @@ def get_modified_files(rootdir):
try:
args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"]
if filter != None:
args.append(filter)
modified_files = check_output(args).strip().split()
except (subprocess.CalledProcessError, OSError) as e:
print("git failed: %s" % e)
@ -176,18 +178,18 @@ def check_deleted_files(rootdir, file_exceptions):
"""
print("\nChecking for removed files")
modified_files = get_modified_files(rootdir)
deleted_files = []
any_removed = False
for f in modified_files:
full = os.path.abspath(f)
if not os.path.exists(full):
print(" Removed file: %s" % f)
deleted_files.append(full)
any_removed = True
deleted_files = get_modified_files(rootdir, "--diff-filter=D")
if not deleted_files:
print("No files were removed.")
return
if any_removed:
# Figure out whether this file was included anywhere
print(" Removed files:")
for f in deleted_files:
print (" %s" % f)
deleted_files = map(lambda x: os.path.abspath(x), deleted_files)
# Figure out whether files were included anywhere
missing_reference = False
for root, dirs, files in os.walk(rootdir):
@ -227,10 +229,11 @@ def check_deleted_files(rootdir, file_exceptions):
if (os.path.abspath(href) in deleted_files):
print(" File %s has an xi:include on deleted file %s " % (f, href))
missing_reference = True
if missing_reference:
sys.exit(1)
print("Passed removed file check.")
def validate_individual_files(rootdir, exceptions, force=False, niceness=False, voting=True):
schema = get_schema()

View File

@ -141,7 +141,7 @@ def error_message(error_log):
# Check whether only files in www got updated
def only_www_touched():
try:
args = ["git", "diff", "--name-only", "HEAD", "HEAD~1"]
args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"]
modified_files = check_output(args).strip().split()
except (CalledProcessError, OSError) as e:
print("git failed: %s" % e)
@ -157,7 +157,7 @@ def only_www_touched():
return www_changed and not other_changed
def get_modified_files(rootdir):
def get_modified_files(rootdir, filter=None):
"""Get modified files below doc directory"""
# There are several tree traversals in this program that do a
@ -165,7 +165,9 @@ def get_modified_files(rootdir):
# so assure that.
os.chdir(rootdir)
try:
args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"]
args = ["git", "diff", "--name-only", "--relative", "HEAD~1", "HEAD"]
if filter != None:
args.append(filter)
modified_files = check_output(args).strip().split()
except (CalledProcessError, OSError) as e:
print("git failed: %s" % e)
@ -178,18 +180,18 @@ def check_deleted_files(rootdir, file_exceptions):
"""
print("\nChecking for removed files")
modified_files = get_modified_files(rootdir)
deleted_files = []
any_removed = False
for f in modified_files:
full = os.path.abspath(f)
if not os.path.exists(full):
print(" Removed file: %s" % f)
deleted_files.append(full)
any_removed = True
deleted_files = get_modified_files(rootdir, "--diff-filter=D")
if not deleted_files:
print("No files were removed.")
return
if any_removed:
# Figure out whether this file was included anywhere
print(" Removed files:")
for f in deleted_files:
print (" %s" % f)
deleted_files = map(lambda x: os.path.abspath(x), deleted_files)
# Figure out whether files were included anywhere
missing_reference = False
for root, dirs, files in os.walk(rootdir):
@ -232,6 +234,8 @@ def check_deleted_files(rootdir, file_exceptions):
if missing_reference:
sys.exit(1)
print("Passed removed file check.")
def validate_individual_files(rootdir, exceptions, force):
schema = get_schema()