|
4 | 4 | requirements.""" |
5 | 5 |
|
6 | 6 | import argparse |
7 | | -import json |
8 | 7 | import os |
9 | | -import plistlib |
10 | 8 | import sys |
11 | 9 | from contextlib import contextmanager |
12 | 10 | from distutils.version import LooseVersion |
13 | | -from xml.parsers.expat import ExpatError |
14 | | - |
15 | | -from ruamel import yaml |
16 | 11 |
|
17 | 12 | from pre_commit_hooks.util import ( |
| 13 | + load_autopkg_recipe, |
18 | 14 | validate_pkginfo_key_types, |
19 | 15 | validate_required_keys, |
20 | 16 | validate_restart_action_key, |
@@ -486,35 +482,10 @@ def main(argv=None): |
486 | 482 | retval = 0 |
487 | 483 | for filename in args.filenames: |
488 | 484 |
|
489 | | - if filename.endswith(".yaml"): |
490 | | - try: |
491 | | - # try to read it as yaml |
492 | | - with open(filename, "rb") as f: |
493 | | - recipe = yaml.safe_load(f) |
494 | | - except Exception as err: |
495 | | - print("{}: yaml parsing error: {}".format(filename, err)) |
496 | | - retval = 1 |
497 | | - break # No need to continue checking this file |
498 | | - |
499 | | - elif filename.endswith(".json"): |
500 | | - try: |
501 | | - # try to read it as json |
502 | | - with open(filename, "rb") as f: |
503 | | - recipe = json.load(f) |
504 | | - except Exception as err: |
505 | | - print("{}: json parsing error: {}".format(filename, err)) |
506 | | - retval = 1 |
507 | | - break # No need to continue checking this file |
508 | | - |
509 | | - else: |
510 | | - try: |
511 | | - # try to read it as a plist |
512 | | - with open(filename, "rb") as f: |
513 | | - recipe = plistlib.load(f) |
514 | | - except Exception as err: |
515 | | - print("{}: plist parsing error: {}".format(filename, err)) |
516 | | - retval = 1 |
517 | | - break # No need to continue checking this file |
| 485 | + recipe = load_autopkg_recipe(filename) |
| 486 | + if not recipe: |
| 487 | + retval = 1 |
| 488 | + break # No need to continue checking this file |
518 | 489 |
|
519 | 490 | # For future implementation of validate_unused_input_vars() |
520 | 491 | # with open(filename, "r") as openfile: |
|
0 commit comments