From bb51cf709315c2b0616bf1f52a313dec6eabf726 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 20 Nov 2023 09:02:16 -0800 Subject: [PATCH 1/3] Fix traceback when checking "nopkg" type items in Munki Follow up to https://github.com/homebysix/pre-commit-macadmin/pull/66 --- pre_commit_hooks/check_munki_pkgsinfo.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pre_commit_hooks/check_munki_pkgsinfo.py b/pre_commit_hooks/check_munki_pkgsinfo.py index 26b7768..f8ca21e 100755 --- a/pre_commit_hooks/check_munki_pkgsinfo.py +++ b/pre_commit_hooks/check_munki_pkgsinfo.py @@ -39,6 +39,8 @@ def build_argument_parser(): def _check_case_sensitive_path(path): + """Check whether a path exists, and on case-sensitive filesystems check + that there is no case conflict.""" # Return immediately if the file does not exist if not os.path.exists(path): return False @@ -131,14 +133,9 @@ def main(argv=None): ) retval = 1 - # Check for missing installer items - if all( - ( - "installer_item_location" in pkginfo, - not _check_case_sensitive_path( - os.path.join("pkgs", pkginfo.get("installer_item_location")) - ), - ) + # Check for missing or case-conflicted installer items + if not _check_case_sensitive_path( + os.path.join("pkgs", pkginfo.get("installer_item_location", "")) ): print( "{}: installer item does not exist or path is not case sensitive".format( From 2b430ac889b9e7563230ca4f72572db73cc18707 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 20 Nov 2023 09:18:49 -0800 Subject: [PATCH 2/3] Specify utf-8 encoding when reading/writing plain text files --- pre_commit_hooks/check_autopkg_recipe_list.py | 6 +++--- pre_commit_hooks/check_autopkg_recipes.py | 6 +++--- pre_commit_hooks/check_jamf_extension_attributes.py | 2 +- pre_commit_hooks/check_jamf_scripts.py | 3 +-- pre_commit_hooks/check_munkipkg_buildinfo.py | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pre_commit_hooks/check_autopkg_recipe_list.py b/pre_commit_hooks/check_autopkg_recipe_list.py index b3b6236..d9808b6 100755 --- a/pre_commit_hooks/check_autopkg_recipe_list.py +++ b/pre_commit_hooks/check_autopkg_recipe_list.py @@ -37,7 +37,7 @@ def main(argv=None): for filename in args.filenames: recipe_list = None if filename.endswith(".txt"): - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: recipe_list = [ line for line in openfile.read().splitlines() @@ -54,7 +54,7 @@ def main(argv=None): # AutoPkg does not support YAML recipe lists, but AutoPkg users # may have developed custom tooling for this. try: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: recipe_list = yaml.load(openfile) except Exception as err: print("{}: yaml parsing error: {}".format(filename, err)) @@ -63,7 +63,7 @@ def main(argv=None): # AutoPkg does not support JSON recipe lists, but AutoPkg users # may have developed custom tooling for this. try: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: recipe_list = json.load(openfile) except Exception as err: print("{}: json parsing error: {}".format(filename, err)) diff --git a/pre_commit_hooks/check_autopkg_recipes.py b/pre_commit_hooks/check_autopkg_recipes.py index 348f8fe..3be42ae 100755 --- a/pre_commit_hooks/check_autopkg_recipes.py +++ b/pre_commit_hooks/check_autopkg_recipes.py @@ -20,7 +20,7 @@ # Import AutoPkg libraries, but ignore any warnings generated by the import. @contextmanager def suppress_stdout(): - with open(os.devnull, "w") as devnull: + with open(os.devnull, "w", encoding="utf-8") as devnull: old_stdout = sys.stdout sys.stdout = devnull try: @@ -100,7 +100,7 @@ def validate_comments(filename, strict): plutil -convert xml1.""" passed = True - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: recipe_text = openfile.read() if "" in recipe_text: if strict: @@ -548,7 +548,7 @@ def main(argv=None): break # No need to continue checking this file # For future implementation of validate_unused_input_vars() - # with open(filename, "r") as openfile: + # with open(filename, "r", encoding='utf-8') as openfile: # recipe_text = openfile.read() # Top level keys that all AutoPkg recipes should contain. diff --git a/pre_commit_hooks/check_jamf_extension_attributes.py b/pre_commit_hooks/check_jamf_extension_attributes.py index 4d79670..21fa95d 100644 --- a/pre_commit_hooks/check_jamf_extension_attributes.py +++ b/pre_commit_hooks/check_jamf_extension_attributes.py @@ -25,7 +25,7 @@ def main(argv=None): retval = 0 for filename in args.filenames: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: ea_content = openfile.read() if "" not in ea_content or "" not in ea_content: diff --git a/pre_commit_hooks/check_jamf_scripts.py b/pre_commit_hooks/check_jamf_scripts.py index e517908..ec2479c 100644 --- a/pre_commit_hooks/check_jamf_scripts.py +++ b/pre_commit_hooks/check_jamf_scripts.py @@ -3,7 +3,6 @@ """Check Jamf scripts for common issues.""" import argparse -import os def build_argument_parser(): @@ -25,7 +24,7 @@ def main(argv=None): retval = 0 for filename in args.filenames: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: script_content = openfile.read() # Ensure script starts with a shebang of some sort. diff --git a/pre_commit_hooks/check_munkipkg_buildinfo.py b/pre_commit_hooks/check_munkipkg_buildinfo.py index cab4bf7..67d28f4 100755 --- a/pre_commit_hooks/check_munkipkg_buildinfo.py +++ b/pre_commit_hooks/check_munkipkg_buildinfo.py @@ -89,7 +89,7 @@ def main(argv=None): break # no need to continue testing this file elif filename.endswith((".yaml", ".yml")): try: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: buildinfo = yaml.load(openfile) except Exception as err: print("{}: yaml parsing error: {}".format(filename, err)) @@ -97,7 +97,7 @@ def main(argv=None): break # no need to continue testing this file elif filename.endswith(".json"): try: - with open(filename, "r") as openfile: + with open(filename, "r", encoding="utf-8") as openfile: buildinfo = json.load(openfile) except Exception as err: print("{}: json parsing error: {}".format(filename, err)) From ee23677fc52b3a128086e21d1f435b245f08f83d Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 20 Nov 2023 09:25:03 -0800 Subject: [PATCH 3/3] Update change log for 1.14.1 --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efbf21..019e3b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file. This projec Nothing yet. +## [1.14.1] - 2023-11-20 + +### Fixed + +- Fixed a bug that would cause a Python traceback when checking Munki repos that use `nopkg` type items. + ## [1.14.0] - 2023-11-19 ### Added @@ -318,7 +324,9 @@ Nothing yet. - Initial release -[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.13.0...HEAD +[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.14.1...HEAD +[1.14.1]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.14.0...v1.14.1 +[1.14.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.13.0...v1.14.0 [1.13.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.12.4...v1.13.0 [1.12.4]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.12.3...v1.12.4 [1.12.3]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.12.2...v1.12.3