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:
parent
8af4a16bea
commit
99b93dc27e
93
test.py
93
test.py
|
@ -155,7 +155,7 @@ def only_www_touched():
|
||||||
|
|
||||||
return www_changed and not other_changed
|
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"""
|
"""Get modified files below doc directory"""
|
||||||
|
|
||||||
# There are several tree traversals in this program that do a
|
# There are several tree traversals in this program that do a
|
||||||
|
@ -165,6 +165,8 @@ def get_modified_files(rootdir):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"]
|
args = ["git", "diff", "--name-only", "--relative", "HEAD", "HEAD~1"]
|
||||||
|
if filter != None:
|
||||||
|
args.append(filter)
|
||||||
modified_files = check_output(args).strip().split()
|
modified_files = check_output(args).strip().split()
|
||||||
except (subprocess.CalledProcessError, OSError) as e:
|
except (subprocess.CalledProcessError, OSError) as e:
|
||||||
print("git failed: %s" % e)
|
print("git failed: %s" % e)
|
||||||
|
@ -176,60 +178,61 @@ def check_deleted_files(rootdir, file_exceptions):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
print("\nChecking for removed files")
|
print("\nChecking for removed files")
|
||||||
modified_files = get_modified_files(rootdir)
|
deleted_files = get_modified_files(rootdir, "--diff-filter=D")
|
||||||
deleted_files = []
|
if not deleted_files:
|
||||||
any_removed = False
|
print("No files were removed.")
|
||||||
for f in modified_files:
|
return
|
||||||
full = os.path.abspath(f)
|
|
||||||
if not os.path.exists(full):
|
|
||||||
print(" Removed file: %s" % f)
|
|
||||||
deleted_files.append(full)
|
|
||||||
any_removed = True
|
|
||||||
|
|
||||||
if any_removed:
|
print(" Removed files:")
|
||||||
# Figure out whether this file was included anywhere
|
for f in deleted_files:
|
||||||
missing_reference = False
|
print (" %s" % f)
|
||||||
|
|
||||||
|
deleted_files = map(lambda x: os.path.abspath(x), deleted_files)
|
||||||
|
|
||||||
for root, dirs, files in os.walk(rootdir):
|
# Figure out whether files were included anywhere
|
||||||
# Don't descend into 'target' subdirectories
|
missing_reference = False
|
||||||
try:
|
|
||||||
ind = dirs.index('target')
|
|
||||||
del dirs[ind]
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
os.chdir(root)
|
for root, dirs, files in os.walk(rootdir):
|
||||||
|
# Don't descend into 'target' subdirectories
|
||||||
|
try:
|
||||||
|
ind = dirs.index('target')
|
||||||
|
del dirs[ind]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
for f in files:
|
os.chdir(root)
|
||||||
if (f.endswith('.xml') and
|
|
||||||
f != 'pom.xml' and
|
|
||||||
f not in file_exceptions):
|
|
||||||
path = os.path.abspath(os.path.join(root, f))
|
|
||||||
doc = etree.parse(path)
|
|
||||||
|
|
||||||
# Check for inclusion of files as part of imagedata
|
for f in files:
|
||||||
for node in doc.findall('//{http://docbook.org/ns/docbook}imagedata'):
|
if (f.endswith('.xml') and
|
||||||
href = node.get('fileref')
|
f != 'pom.xml' and
|
||||||
if (f not in file_exceptions and
|
f not in file_exceptions):
|
||||||
os.path.abspath(href) in deleted_files):
|
path = os.path.abspath(os.path.join(root, f))
|
||||||
print(" File %s has an imagedata href for deleted file %s " % (f, href))
|
doc = etree.parse(path)
|
||||||
missing_reference = True
|
|
||||||
|
|
||||||
break
|
# Check for inclusion of files as part of imagedata
|
||||||
|
for node in doc.findall('//{http://docbook.org/ns/docbook}imagedata'):
|
||||||
|
href = node.get('fileref')
|
||||||
|
if (f not in file_exceptions and
|
||||||
|
os.path.abspath(href) in deleted_files):
|
||||||
|
print(" File %s has an imagedata href for deleted file %s " % (f, href))
|
||||||
|
missing_reference = True
|
||||||
|
|
||||||
if missing_reference:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check for inclusion of files as part of xi:include
|
if missing_reference:
|
||||||
ns = {"xi": "http://www.w3.org/2001/XInclude"}
|
break
|
||||||
for node in doc.xpath('//xi:include', namespaces=ns):
|
|
||||||
href = node.get('href')
|
|
||||||
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:
|
# Check for inclusion of files as part of xi:include
|
||||||
sys.exit(1)
|
ns = {"xi": "http://www.w3.org/2001/XInclude"}
|
||||||
|
for node in doc.xpath('//xi:include', namespaces=ns):
|
||||||
|
href = node.get('href')
|
||||||
|
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):
|
def validate_individual_files(rootdir, exceptions, force=False, niceness=False, voting=True):
|
||||||
schema = get_schema()
|
schema = get_schema()
|
||||||
|
|
98
validate.py
98
validate.py
|
@ -141,7 +141,7 @@ def error_message(error_log):
|
||||||
# Check whether only files in www got updated
|
# Check whether only files in www got updated
|
||||||
def only_www_touched():
|
def only_www_touched():
|
||||||
try:
|
try:
|
||||||
args = ["git", "diff", "--name-only", "HEAD", "HEAD~1"]
|
args = ["git", "diff", "--name-only", "HEAD~1", "HEAD"]
|
||||||
modified_files = check_output(args).strip().split()
|
modified_files = check_output(args).strip().split()
|
||||||
except (CalledProcessError, OSError) as e:
|
except (CalledProcessError, OSError) as e:
|
||||||
print("git failed: %s" % e)
|
print("git failed: %s" % e)
|
||||||
|
@ -157,7 +157,7 @@ def only_www_touched():
|
||||||
|
|
||||||
return www_changed and not other_changed
|
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"""
|
"""Get modified files below doc directory"""
|
||||||
|
|
||||||
# There are several tree traversals in this program that do a
|
# There are several tree traversals in this program that do a
|
||||||
|
@ -165,7 +165,9 @@ def get_modified_files(rootdir):
|
||||||
# so assure that.
|
# so assure that.
|
||||||
os.chdir(rootdir)
|
os.chdir(rootdir)
|
||||||
try:
|
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()
|
modified_files = check_output(args).strip().split()
|
||||||
except (CalledProcessError, OSError) as e:
|
except (CalledProcessError, OSError) as e:
|
||||||
print("git failed: %s" % e)
|
print("git failed: %s" % e)
|
||||||
|
@ -178,59 +180,61 @@ def check_deleted_files(rootdir, file_exceptions):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
print("\nChecking for removed files")
|
print("\nChecking for removed files")
|
||||||
modified_files = get_modified_files(rootdir)
|
deleted_files = get_modified_files(rootdir, "--diff-filter=D")
|
||||||
deleted_files = []
|
if not deleted_files:
|
||||||
any_removed = False
|
print("No files were removed.")
|
||||||
for f in modified_files:
|
return
|
||||||
full = os.path.abspath(f)
|
|
||||||
if not os.path.exists(full):
|
|
||||||
print(" Removed file: %s" % f)
|
|
||||||
deleted_files.append(full)
|
|
||||||
any_removed = True
|
|
||||||
|
|
||||||
if any_removed:
|
print(" Removed files:")
|
||||||
# Figure out whether this file was included anywhere
|
for f in deleted_files:
|
||||||
missing_reference = False
|
print (" %s" % f)
|
||||||
|
|
||||||
|
deleted_files = map(lambda x: os.path.abspath(x), deleted_files)
|
||||||
|
|
||||||
for root, dirs, files in os.walk(rootdir):
|
# Figure out whether files were included anywhere
|
||||||
# Don't descend into 'target' subdirectories
|
missing_reference = False
|
||||||
try:
|
|
||||||
ind = dirs.index('target')
|
|
||||||
del dirs[ind]
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
os.chdir(root)
|
for root, dirs, files in os.walk(rootdir):
|
||||||
|
# Don't descend into 'target' subdirectories
|
||||||
|
try:
|
||||||
|
ind = dirs.index('target')
|
||||||
|
del dirs[ind]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
for f in files:
|
os.chdir(root)
|
||||||
if (f.endswith('.xml') and
|
|
||||||
f != 'pom.xml' and
|
|
||||||
f not in file_exceptions):
|
|
||||||
path = os.path.abspath(os.path.join(root, f))
|
|
||||||
doc = etree.parse(path)
|
|
||||||
|
|
||||||
# Check for inclusion of files as part of imagedata
|
for f in files:
|
||||||
for node in doc.findall('//{http://docbook.org/ns/docbook}imagedata'):
|
if (f.endswith('.xml') and
|
||||||
href = node.get('fileref')
|
f != 'pom.xml' and
|
||||||
if (f not in file_exceptions and
|
f not in file_exceptions):
|
||||||
os.path.abspath(href) in deleted_files):
|
path = os.path.abspath(os.path.join(root, f))
|
||||||
print(" File %s has an imagedata href for deleted file %s " % (f, href))
|
doc = etree.parse(path)
|
||||||
missing_reference = True
|
|
||||||
|
|
||||||
break
|
# Check for inclusion of files as part of imagedata
|
||||||
|
for node in doc.findall('//{http://docbook.org/ns/docbook}imagedata'):
|
||||||
|
href = node.get('fileref')
|
||||||
|
if (f not in file_exceptions and
|
||||||
|
os.path.abspath(href) in deleted_files):
|
||||||
|
print(" File %s has an imagedata href for deleted file %s " % (f, href))
|
||||||
|
missing_reference = True
|
||||||
|
|
||||||
if missing_reference:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check for inclusion of files as part of xi:include
|
if missing_reference:
|
||||||
ns = {"xi": "http://www.w3.org/2001/XInclude"}
|
break
|
||||||
for node in doc.xpath('//xi:include', namespaces=ns):
|
|
||||||
href = node.get('href')
|
# Check for inclusion of files as part of xi:include
|
||||||
if (os.path.abspath(href) in deleted_files):
|
ns = {"xi": "http://www.w3.org/2001/XInclude"}
|
||||||
print(" File %s has an xi:include on deleted file %s " % (f, href))
|
for node in doc.xpath('//xi:include', namespaces=ns):
|
||||||
missing_reference = True
|
href = node.get('href')
|
||||||
if missing_reference:
|
if (os.path.abspath(href) in deleted_files):
|
||||||
sys.exit(1)
|
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):
|
def validate_individual_files(rootdir, exceptions, force):
|
||||||
|
|
Loading…
Reference in New Issue