Skip to content

Commit

Permalink
Merge pull request #28 from Jamf-Custom-Profile-Schemas/2024-05-24
Browse files Browse the repository at this point in the history
Fixes to build script, pre-commit config update
  • Loading branch information
homebysix authored May 24, 2024
2 parents 4d1f8b0 + 861bd7b commit 288982e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
24 changes: 14 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
args: [--maxkb=100]
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: '\.json$'
- id: fix-byte-order-marker
- id: fix-encoding-pragma
- id: mixed-line-ending
# - id: no-commit-to-branch
# args: [--branch, main]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/ambv/black
rev: 23.1.0
- repo: https://github.com/python/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: ['--py36-plus']
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.3.0]
additional_dependencies: [black==24.4.2]
# - repo: https://github.com/homebysix/pre-commit-macadmin
# rev: profile-manifests
# exclude: "last_build\.json"
Expand Down
19 changes: 11 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2021 Elliot Jordan
# Copyright 2021-2024 Elliot Jordan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,7 +19,7 @@


__author__ = "Elliot Jordan"
__version__ = "1.0.3"
__version__ = "1.1.0"

import argparse
import json
Expand Down Expand Up @@ -202,12 +201,16 @@ def process_subkeys(subkeys):
if "items" in properties[name]:
# If the parent type was array, we're only expecting a single dict
# here, since an array should only contain a single object type.
# TODO: Validate this assumption. Some warnings seen in the wild.
subprop_keys = list(subprop.keys())
if len(subprop_keys) > 1:
print(
"WARNING: Array type should only have one subproperty "
"key. Multiple found: %s" % subprop_keys
"key. Skipping all but the first: %s" % subprop_keys
)
elif len(subprop_keys) == 0:
print("WARNING: No subproperty keys found in %s key." % name)
continue
array_props = subprop[subprop_keys[0]]
properties[name]["items"] = array_props
else:
Expand All @@ -225,7 +228,7 @@ def convert_to_jamf_manifest(data, property_order_increment=5):
# Create schema object
try:
schema = {
"title": "%s (%s)" % (data["pfm_title"], data["pfm_domain"]),
"title": "{} ({})".format(data["pfm_title"], data["pfm_domain"]),
"description": data["pfm_description"],
"properties": process_subkeys(data["pfm_subkeys"]),
}
Expand All @@ -252,7 +255,7 @@ def write_to_file(path, data):
os.makedirs(path_head)

# Write file
with open(os.path.join(path_head, path_tail), "w") as openfile:
with open(os.path.join(path_head, path_tail), "w", encoding="utf-8") as openfile:
openfile.write(
json.dumps(
data,
Expand All @@ -267,7 +270,7 @@ def write_to_file(path, data):
def update_readme(count):
"""Updates README.md file with latest manifest count."""

with open("README.md", "r") as f:
with open("README.md", encoding="utf-8") as f:
readme = f.readlines()
for idx, line in enumerate(readme):
if line.startswith("![Manifest Count]("):
Expand All @@ -276,7 +279,7 @@ def update_readme(count):
% count
)
break
with open("README.md", "w") as f:
with open("README.md", "w", encoding="utf-8") as f:
f.write("".join(readme))
print("Updated README.md")

Expand Down

0 comments on commit 288982e

Please sign in to comment.