-
Notifications
You must be signed in to change notification settings - Fork 24
/
validate_recipes_novaksam.py
executable file
·908 lines (707 loc) · 26.3 KB
/
validate_recipes_novaksam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
#!/usr/local/autopkg/python
# Copyright (C) 2014 Shea G Craig
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""validate_recipes.py
usage: validate_recipes.py [-h] [-v] recipe [recipe ...]
Test recipes for compliance with the jss-recipe style guide.
positional arguments:
recipe Path to a recipe to validate, or to a folder, to recursively
test all contained recipes.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Display results of all tests.
"""
from __future__ import absolute_import, print_function
import argparse
import os
import subprocess
import sys
# pylint: disable=no-name-in-module
from Foundation import (
NSData,
NSPropertyListMutableContainersAndLeaves,
NSPropertyListSerialization,
NSPropertyListXMLFormat_v1_0,
)
# pylint: enable=no-name-in-module
__version__ = "1.0.0"
REQUIRED_ARGUMENTS = (
"self_service_description",
"category",
"policy_template",
"self_service_icon",
"policy_category")
OPTIONAL_ARGUMENTS = (
"jss_inventory_name",
"os_requirements")
PROHIBITED_ARGUMENTS = (
"site_name",
"site_id")
VALID_CATEGORIES = (
"Browsers",
"Media",
"Office",
"Plugins and Frameworks",
"Services",
"Utilities")
class Error(Exception):
"""Module base exception."""
pass
class PlistParseError(Error):
"""Error parsing a plist file."""
pass
class Plist(dict):
"""Abbreviated plist representation (as a dict)."""
def __init__(self, filename=None):
"""Init a Plist, optionally from parsing an existing file.
Args:
filename: String path to a plist file.
"""
if filename:
dict.__init__(self, self.read_file(filename))
else:
dict.__init__(self)
self.new_plist()
self.filename = os.path.abspath(filename)
def read_file(self, path):
"""Replace internal XML dict with data from plist at path.
Args:
path: String path to a plist file.
Raises:
PlistParseError: Error in reading plist file.
"""
# pylint: disable=unused-variable
info, pformat, error = (
NSPropertyListSerialization.propertyListWithData_options_format_error_(
NSData.dataWithContentsOfFile_(os.path.expanduser(path)),
NSPropertyListMutableContainersAndLeaves,
None,
None
))
# pylint: enable=unused-variable
if info is None:
if error is None:
error = "Invalid plist file."
raise PlistParseError("Can't read %s: %s" % (path, error))
return info
class Results(object):
"""Collects test results and manages their output."""
def __init__(self):
self.results = []
def add_result(self, result):
self.results.append(result)
def report(self, verbose=False):
if verbose or not all((result[0] for result in self.results)):
for result in self.results:
if verbose or not result[0]:
self._print_result(result)
else:
print("Ok.")
def report_all(self):
self.report(verbose=True)
def _print_result(self, line):
print("Test: %s Result: %s" % (line[1], line[0]))
def get_argument_parser():
"""Build and return argparser for this app."""
parser = argparse.ArgumentParser(description="Test recipes for compliance "
"with the jss-recipe style guide.")
parser.add_argument("recipe", nargs="+", help="Path to a recipe to "
"validate, or to a folder, to recursively test all "
"contained recipes.")
parser.add_argument("-v", "--verbose", help="Display results of all "
"tests.", action="store_true")
return parser
def get_recipes(recipes):
"""Build a list of recipes from filename or dirname.
Args:
recipes: A string filename or path to a directory. Directories
will be recursively searched for files ending with
'.jss.recipe'.
Returns:
List of recipe files.
"""
result = []
if os.path.isfile(recipes):
result.append(recipes)
elif os.path.isdir(recipes):
for root, dirs, files in os.walk(recipes):
for filename in files:
if filename.endswith(".jss.recipe"):
result.append(os.path.join(root, filename))
return result
def validate_recipe(recipe_path, verbose=False):
"""Test a recipe for compliance, printing progress.
Args:
recipe_path: String path to recipe file.
"""
tests = (
test_filename_prefix,
test_filename_suffix,
test_recipe_parsing,
test_is_in_subfolder,
test_folder_contents_have_common_prefix,
test_no_restricted_files_in_folder,
test_parent_recipe,
test_identifier,
test_single_processor,
test_name_prod_name,
test_argument_values,
test_no_prohibited_arguments,
test_input_section,
test_category_value,
test_policy_category_value,
test_policy_template_value,
test_icon_name,
test_group_name,
test_group_template,
test_groups_argument,
test_extension_attributes,
test_scripts,
test_icon,
test_lint)
header = "Testing recipe: %s" % recipe_path
print_bar(len(header))
print(header)
print_bar(len(header))
if os.path.exists(recipe_path):
recipe = get_recipe(recipe_path)
else:
print("File not found.")
sys.exit(1)
results = Results()
for test in tests:
try:
result = test(recipe)
# Handle missing plist keys rather than try to test for each
# bit of a recipe.
except KeyError as err:
result = (False, "'%s' failed with missing Key: '%s'" %
(test.__name__, err.message))
except AttributeError as err:
result = (False, "'%s' failed with missing attribute" %
test.__name__)
results.add_result(result)
if verbose:
results.report_all()
else:
results.report()
def get_recipe(recipe_path):
"""Open a recipe file as an ElementTree.
Args:
recipe_path: String path to recipe file.
Returns:
ElementTree of the recipe, exception message if the recipe has parsing
errors, or None if that file does not exist.
"""
try:
recipe = Plist(recipe_path)
except IOError:
recipe = None
except PlistParseError as err:
recipe = err.message
except ValueError:
recipe = u"File does not exist."
return recipe
def test_filename_prefix(recipe):
"""Tests filename for correct prefix.
Args:
recipe_path: String path to a recipe file.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
name = recipe["Input"].get("NAME")
result = os.path.basename(recipe.filename).startswith(name)
description = "Recipe has correct prefix (NAME: '%s')" % name
return (result, description)
def test_filename_suffix(recipe):
"""Tests filename for correct ending.
Args:
recipe_path: String path to a recipe file.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = os.path.basename(recipe.filename).endswith(".jss.recipe")
description = "Recipe has correct ending ('.jss.recipe')"
return (result, description)
def test_recipe_parsing(recipe):
"""Determine whether recipe file exists and parses.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "Recipe parses correctly."
if not recipe:
description += " (Recipe file not found!)"
elif isinstance(recipe, unicode):
# There was a parsing error. Print the message and finish.
description += " (%s)" % recipe
else:
result = True
return (result, description)
def test_is_in_subfolder(recipe):
"""Determine whether recipe file is in a product subfolder.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = None
name = recipe["Input"].get("NAME")
description = "Recipe is in a subfolder named (NAME: '%s')." % name
dirname = os.path.dirname(recipe.filename).rsplit("/", 1)[1]
result = dirname == name
return (result, description)
def test_folder_contents_have_common_prefix(recipe):
"""Determine whether folder contents have a common prefix of NAME.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = None
name = recipe["Input"].get("NAME")
description = "All files have prefix of product (NAME: '%s')." % name
files = os.listdir(os.path.dirname(recipe.filename))
result = all((filename.startswith(name) for filename in files))
return (result, description)
def test_no_restricted_files_in_folder(recipe):
"""Determine whether folder contents have a common prefix of NAME.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = None
restricted_files = ["PolicyTemplate.xml", "SmartGroupTemplate.xml"]
description = ("None of the restricted templates %s are in recipe's "
"folder." % restricted_files)
files = os.listdir(os.path.dirname(recipe.filename))
result = all(restricted_file not in files for restricted_file in
restricted_files)
return (result, description)
def test_parent_recipe(recipe):
"""Determine whether parent recipe is in AutoPkg org and not None.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
parent = recipe.get("ParentRecipe")
result = False
description = "Parent Recipe is in AutoPkg org."
if parent:
search_results = subprocess.check_output(["autopkg", "search", parent])
if ".pkg.recipe" in search_results:
result = True
else:
description += " (ParentRecipe not set)"
return (result, description)
def test_identifier(recipe):
"""Test recipe identifier for proper construction.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
name = recipe["Input"].get("NAME")
if name:
# The identifier may not have spaces.
name = name.replace(" ", "")
description = ("Recipe identifier follows convention. "
"('com.github.novaksam.jss.%s')" % name)
result = False
identifier = recipe.get("Identifier")
if identifier and name:
if (str(identifier).startswith("com.github.novaksam.jss.") and
str(identifier).rsplit(".", 1)[1].startswith(name)):
result = True
return (result, description)
def test_single_processor(recipe):
"""Test for recipe having a single processor.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
description = "Recipe has only a single processor, of type 'JSSImporter'."
result = False
processors = recipe.get("Process")
if len(processors) == 1:
processor = processors[0].get("Processor")
if processor and processor == "JSSImporter":
result = True
else:
description += " (Processor is not 'JSSImporter')"
else:
description += " (Too many processors: %s > 1)" % len(processors)
return (result, description)
def get_jssimporter(recipe):
"""Return the JSSImporter processor section or None."""
processors = [processor for processor in recipe["Process"] if
processor.get("Processor") == "JSSImporter"]
if len(processors) == 1:
result = processors.pop()
else:
result = None
return result
def test_argument_values(recipe):
"""Test for all arguments to JSSImporter being replacement vars.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = ("All required and optional arguments to JSSImporter are "
"%ALL_CAPS% replacement variables, and are present.")
required_argument_values = (get_jssimporter(recipe)["Arguments"].get(
argument) for argument in REQUIRED_ARGUMENTS)
optional_argument_values = (get_jssimporter(recipe)["Arguments"].get(
argument) for argument in OPTIONAL_ARGUMENTS)
valid_required_values = all((val and val.isupper() and val.startswith("%")
and val.endswith("%") for val in
required_argument_values))
valid_optional_values = all((val.isupper() and val.startswith("%") and
val.endswith("%") for val in
required_argument_values if val))
if valid_required_values and valid_optional_values:
result = True
return (result, description)
def test_name_prod_name(recipe):
"""Test for name Input and prod_name arg.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "NAME is set, and prod_name is %NAME%."
if ("NAME" in recipe["Input"] and
get_jssimporter(recipe)["Arguments"].get("prod_name") == "%NAME%"):
result = True
return (result, description)
def test_no_prohibited_arguments(recipe):
"""Tests for prohibited arguments.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "No prohibited arguments."
arguments = get_jssimporter(recipe)["Arguments"]
if all((not prohibited_arg in arguments for prohibited_arg in
PROHIBITED_ARGUMENTS)):
result = True
return (result, description)
def test_input_section(recipe):
"""Test for all required and optional args in input section.
All args should have actual values set in input section. Also,
names must follow the convention of being ALL_CAPS equivalent of
JSSImporter argument.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = ("All required and optional arguments to JSSImporter are "
"set in 'Input' section with ALL_CAPS keys.")
required_input_keys = (recipe["Input"].get(argument.upper()) for argument
in REQUIRED_ARGUMENTS)
# Optional key must be present in JSSImporter args also!
optional_input_keys = (recipe["Input"].get(argument.upper()) for argument
in OPTIONAL_ARGUMENTS if
get_jssimporter(recipe)["Arguments"].get(argument))
valid_required_keys = all((key is not None for key in required_input_keys))
valid_optional_keys = all((key is not None for key in optional_input_keys))
if valid_required_keys and valid_optional_keys:
result = True
return (result, description)
def test_category_value(recipe):
"""Test for valid category.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "CATEGORY is in approved list."
result = recipe["Input"].get("CATEGORY") in VALID_CATEGORIES
return (result, description)
def test_policy_category_value(recipe):
"""Test that policy category is Testing.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "POLICY_CATEGORY is 'Testing'."
result = (recipe["Input"].get("POLICY_CATEGORY") == "Testing")
return (result, description)
def test_policy_template_value(recipe):
"""Test that policy template is valid.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "POLICY_TEMPLATE is 'PolicyTemplate.xml'."
result = recipe["Input"].get("POLICY_TEMPLATE") == "PolicyTemplate.xml"
return (result, description)
def test_icon_name(recipe):
"""Test that icon name is valid.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "SELF_SERVICE_ICON name is NAME.png"
result = (recipe["Input"].get("SELF_SERVICE_ICON") ==
recipe["Input"].get("NAME") + ".png")
return (result, description)
def test_group_name(recipe):
"""Test that group name is valid.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "GROUP_NAME is '%NAME%-update-smart'."
result = recipe["Input"].get("GROUP_NAME") == "%NAME%-update-smart"
return (result, description)
def test_group_template(recipe):
"""Test that group template is valid.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
required_template = "SmartGroupTemplate.xml"
description = "GROUP_TEMPLATE is '%s'." % required_template
name = recipe["Input"].get("NAME")
group_template = recipe["Input"].get("GROUP_TEMPLATE")
if group_template == required_template:
result = True
else:
# Check to see if there is an extension attribute, requiring a
# custom group template.
has_ext_attrs = get_jssimporter(recipe)["Arguments"].get(
"extension_attributes")
if has_ext_attrs and group_template == name + required_template:
result = True
description = ("GROUP_TEMPLATE is '%s' (Properly formed "
"extension-attribute-supporting smart group "
"template provided." % (name + required_template))
return (result, description)
def test_groups_argument(recipe):
"""Test that groups argument is as specified in style-guide.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "'groups' argument to JSSImporter is correct."
groups_args = get_jssimporter(recipe)["Arguments"]["groups"]
groups_len_compliant = len(groups_args) == 1
if groups_len_compliant:
group = groups_args[0]
group_name_compliant = group["name"] == "%GROUP_NAME%"
group_smart_compliant = group["smart"] == True
group_template_compliant = group["template_path"] == "%GROUP_TEMPLATE%"
if all((group_name_compliant, group_smart_compliant,
group_template_compliant)):
result = True
return (result, description)
def test_extension_attributes(recipe):
"""Determine whether extension attributes are configured.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "Recipe has no extension attributes."
extension_attributes = get_jssimporter(
recipe)["Arguments"].get("extension_attributes")
if not extension_attributes:
result = True
else:
description += (" (WARNING: Extension attributes only allowed when "
"absolutely necessary.")
result, description = test_extension_attribute_arguments(recipe)
return (result, description)
def test_extension_attribute_arguments(recipe):
"""Determine whether extension attributes are configured correctly.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
name = recipe["Input"].get("NAME")
description = ("WARNING: Recipe has extension attributes. Extension "
"attributes meet style guidelines.")
extension_attributes = get_jssimporter(
recipe)["Arguments"].get("extension_attributes")
ext_attr_templates = [ext_attr.get("ext_attribute_path") for ext_attr in
extension_attributes]
template_names_compliant = all((filename.startswith(name) and
filename.endswith("ExtensionAttribute.xml")
for filename in ext_attr_templates))
directory = os.path.dirname(recipe.filename)
templates_exist = all((os.path.isfile(os.path.join(directory, filename))
for filename in ext_attr_templates))
result = template_names_compliant and templates_exist
return (result, description)
def test_scripts(recipe):
"""Determine whether scripts are configured.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "Recipe has no scripts."
scripts = get_jssimporter(
recipe)["Arguments"].get("scripts")
if not scripts:
result = True
else:
description += (" (WARNING: Scripts only allowed when absolutely "
"necessary.")
result, description = test_scripts_arguments(recipe)
return (result, description)
def test_scripts_arguments(recipe):
"""Determine whether scripts are configured correctly.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
name = recipe["Input"].get("NAME")
description = ("WARNING: Recipe has scripts. Scripts arguments meet "
"style guidelines.")
scripts = get_jssimporter(recipe)["Arguments"].get("scripts")
script_templates = [script.get("template_path") for script in scripts]
template_names_compliant = all((filename.startswith(name) and
filename.endswith("ScriptTemplate.xml") for
filename in script_templates))
directory = os.path.dirname(recipe.filename)
templates_exist = all((os.path.isfile(os.path.join(directory, filename))
for filename in script_templates))
script_names = [script.get("name") for script in scripts]
script_names_compliant = all((filename.startswith(name) for filename in
script_names))
result = (template_names_compliant and templates_exist and
script_names_compliant)
return (result, description)
def test_icon(recipe):
"""Determine whether recipe file exists and parses.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "Icon is a 128x128px PNG file."
directory = os.path.dirname(recipe.filename)
icon_path = os.path.join(directory,
recipe["Input"].get("SELF_SERVICE_ICON"))
if os.path.exists(icon_path):
width, height, format = get_image_properties(icon_path)
if width == 128 and height == 128 and format.upper() == "PNG":
result = True
else:
description += " (Image is %ix%i of type %s)" % (width, height,
format)
else:
description += " (Icon not found)"
return (result, description)
def get_image_properties(path):
"""Get the width, height, and format of an image using sips.
Args:
path: String path to image file.
Returns:
Tuple of (int: width, int: height, and string: image format)
"""
args = ["/usr/bin/sips", "-g", "pixelWidth", "-g", "pixelHeight", "-g",
"format", path]
output = subprocess.check_output(args).splitlines()
width = int(output[1].rsplit()[-1])
height = int(output[2].rsplit()[-1])
format = output[3].rsplit()[-1]
return width, height, format
def test_lint(recipe):
"""Determine whether recipe file lints.
Args:
recipe: Recipe object.
Returns:
Tuple of Bool: Failure or success, and a string describing the
test and result.
"""
result = False
description = "Recipe file passes plutil -lint test."
args = ["/usr/bin/plutil", "-lint", recipe.filename]
output = subprocess.check_output(args)
if output.rsplit()[-1] == "OK":
result = True
return (result, description)
def print_bar(length=79):
"""Print a line of '-'s."""
print(length * "-")
def main():
parser = get_argument_parser()
args = parser.parse_args()
for recipes_arg in args.recipe:
recipes = get_recipes(recipes_arg)
for recipe in recipes:
validate_recipe(recipe, args.verbose)
if __name__ == "__main__":
main()