Skip to content

Commit b911345

Browse files
committed
Move plist types to shared utils
1 parent e1a5570 commit b911345

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

pre_commit_hooks/check_preference_manifests.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,8 @@
1010
import argparse
1111
import plistlib
1212
from datetime import datetime
13-
from xml.parsers.expat import ExpatError
14-
15-
from pre_commit_hooks.util import validate_required_keys
16-
17-
# Plist types expected in preference manifests, and their Python equivalents
18-
PFM_TYPES = {
19-
"string": str,
20-
"boolean": bool,
21-
"dict": dict,
22-
"dictionary": dict,
23-
"integer": int,
24-
"array": list,
25-
"data": None, # TODO: How to represent this?
26-
"float": float,
27-
"real": float,
28-
"date": datetime,
29-
}
13+
14+
from pre_commit_hooks.util import PLIST_TYPES, validate_required_keys
3015

3116
# List keys and their expected item types
3217
PFM_LIST_TYPES = {
@@ -180,7 +165,7 @@ def validate_pfm_type_strings(subkey, filename):
180165
# print('{}: Subkey type "{}" is deprecated'.format(filename, subkey["pfm_type"]))
181166
# passed = False
182167
pass # DEBUG ONLY
183-
elif subkey["pfm_type"] not in PFM_TYPES:
168+
elif subkey["pfm_type"] not in PLIST_TYPES:
184169
print('{}: Unexpected subkey type "{}"'.format(filename, subkey["pfm_type"]))
185170
passed = False
186171

@@ -280,11 +265,11 @@ def validate_pfm_default(subkey, filename):
280265
# TODO: Should we validate pfm_value_placeholder here too?
281266
for test_key in ("pfm_default",):
282267
if test_key in subkey:
283-
if PFM_TYPES[subkey["pfm_type"]] == list:
268+
if PLIST_TYPES[subkey["pfm_type"]] == list:
284269
desired_type = type(subkey["pfm_subkeys"][0])
285270
else:
286271
try:
287-
desired_type = PFM_TYPES[subkey["pfm_type"]]
272+
desired_type = PLIST_TYPES[subkey["pfm_type"]]
288273
except IndexError:
289274
# Unknown desired type
290275
continue
@@ -294,7 +279,7 @@ def validate_pfm_default(subkey, filename):
294279
filename,
295280
test_key,
296281
subkey.get("pfm_name"),
297-
PFM_TYPES[subkey["pfm_type"]],
282+
PLIST_TYPES[subkey["pfm_type"]],
298283
type(subkey[test_key]),
299284
)
300285
)

pre_commit_hooks/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
from ruamel import yaml
1010

11+
# Plist data types and their Python equivalents
12+
PLIST_TYPES = {
13+
"string": str,
14+
"boolean": bool,
15+
"dict": dict,
16+
"dictionary": dict,
17+
"integer": int,
18+
"array": list,
19+
"data": None, # TODO: How to represent this?
20+
"float": float,
21+
"real": float,
22+
"date": datetime,
23+
}
24+
1125

1226
def load_autopkg_recipe(path):
1327
"""Loads an AutoPkg recipe in plist, yaml, or json format."""

0 commit comments

Comments
 (0)