Skip to content

Commit f79163d

Browse files
authored
Merge pull request #73 from kbrewersq/add_more_flexibility
Add the ability to provide munki_repo location and only warn about missing icons
2 parents 3fea144 + 9e3aeb9 commit f79163d

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,23 @@ After adding a hook to your pre-commit config, it's not a bad idea to run `pre-c
9797

9898
This hook checks Munki pkginfo files to ensure they are valid.
9999

100-
- Specify your preferred list of pkginfo catalogs, if you wish to enforce it, followed by `--` to signal the end of the list:
100+
- Specify your preferred list of pkginfo catalogs, if you wish to enforce it, followed by `--` to signal the end of the list:
101101
`args: ['--catalogs', 'testing', 'stable', '--']`
102102

103-
- Specify your preferred list of pkginfo categories, if you wish to enforce it, followed by `--`:
103+
- Specify your preferred list of pkginfo categories, if you wish to enforce it, followed by `--`:
104104
`args: ['--categories', 'Productivity', 'Design', 'Utilities', 'Web Browsers', '--']`
105105

106-
- Specify required pkginfo keys, followed by `--`:
107-
`args: ['--required-keys', 'category', 'description', 'developer', 'name', 'version', '--']`
106+
- Specify required pkginfo keys, followed by `--`:
107+
`args: ['--required-keys', 'category', 'description', 'developer', 'name', 'version', '--']`
108108
(default: description, name)
109109

110+
- Specify an alternate munki repo location by passing the argument:
111+
`args: ['--munki-repo', './my_repo_location']`
112+
(default: ".")
113+
114+
- Choose to just warn on missing icons with a flag, note if no other issues exist this will allow pre-commit to pass without seeing the warnings:
115+
`args: ['--warn-on-missing-icons]`
116+
110117
- __check-munkiadmin-scripts__
111118

112119
This hook ensures MunkiAdmin scripts are executable.

pre_commit_hooks/check_munki_pkgsinfo.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ def build_argument_parser():
3535
help="Require a blocking_applications array for pkg installers.",
3636
)
3737
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
38+
parser.add_argument(
39+
"--munki-repo",
40+
default=".",
41+
help="path to local munki repo defaults to '.'"
42+
)
43+
parser.add_argument(
44+
"--warn-on-missing-icons",
45+
help="If added, this will only warn on missing icons.",
46+
action="store_true",
47+
default=False,
48+
)
3849
return parser
3950

4051

@@ -135,7 +146,7 @@ def main(argv=None):
135146

136147
# Check for missing or case-conflicted installer items
137148
if not _check_case_sensitive_path(
138-
os.path.join("pkgs", pkginfo.get("installer_item_location", ""))
149+
os.path.join(args.munki_repo, "pkgs", pkginfo.get("installer_item_location", ""))
139150
):
140151
print(
141152
"{}: installer item does not exist or path is not case sensitive".format(
@@ -174,12 +185,19 @@ def main(argv=None):
174185
if not any(
175186
(
176187
pkginfo.get("icon_name"),
177-
os.path.isfile("icons/{}.png".format(pkginfo["name"])),
188+
os.path.isfile(
189+
os.path.join(
190+
args.munki_repo, "icons/{}.png".format(pkginfo["name"])
191+
)
192+
),
178193
pkginfo.get("installer_type") == "apple_update_metadata",
179194
)
180195
):
181-
print("{}: missing icon".format(filename))
182-
retval = 1
196+
if args.warn_on_missing_icons:
197+
print("WARNING: {}: missing icon".format(filename))
198+
else:
199+
print("{}: missing icon".format(filename))
200+
retval = 1
183201

184202
# Ensure uninstall method is set correctly if uninstall_script exists.
185203
if "uninstall_script" in pkginfo:

0 commit comments

Comments
 (0)