-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from rruiter87/product-version
add product version check pre-commit
- Loading branch information
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
|
||
from lxml import etree | ||
|
||
|
||
class PreCommitException(Exception): | ||
pass | ||
|
||
|
||
def check_file(filename): | ||
with open(filename, 'rb') as fd: | ||
original_xml = fd.read() | ||
|
||
xml_parser = etree.XMLParser(remove_blank_text=True) | ||
parse_tree = etree.XML(original_xml, parser=xml_parser).getroottree() | ||
|
||
tc_plc_object = list(parse_tree.iter("TcPlcObject"))[0].attrib | ||
# Check if it contains a product version attribute | ||
if 'ProductVersion' in tc_plc_object: | ||
raise PreCommitException( | ||
f"Detected product version ({tc_plc_object['ProductVersion']}) in {filename}. " | ||
f"To disable this go to Project settings > Advanced and disable 'Write product version in files.'") | ||
|
||
|
||
def main(args=None): | ||
if args is None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filenames', nargs='*') | ||
args = parser.parse_args() | ||
try: | ||
for filename in args.filenames: | ||
check_file(filename) | ||
return 0 | ||
except Exception as exc: | ||
print(exc) | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters