@@ -381,8 +381,9 @@ def __new__(cls, *a, **kw):
381
381
" instead"
382
382
)
383
383
return None
384
- end = f"{ end } 0"
385
- out = {s1 : swag .post_template (cls .plural_class , name )}
384
+ else :
385
+ end = f"{ end } 0"
386
+ out = {s1 : swag .post_template (cls .plural_class , name )}
386
387
_data = api .post (end , out )
387
388
jamf_id = int (_data [s2 ]["id" ])
388
389
if jamf_id not in cls ._instances :
@@ -637,9 +638,9 @@ def refresh(self):
637
638
else :
638
639
records = self .data [p3 ]
639
640
for d in records :
640
- c = self .singular_class (d [id1 ], d ["name" ]) # e.g. id
641
+ c = self .singular_class (d [id1 ], d ["name" ]) # e.g. id1 = "id"
641
642
c .plural_class = self .cls
642
- self ._records .setdefault (int (d [id1 ]), c ) # e.g. id
643
+ self ._records .setdefault (int (d [id1 ]), c ) # e.g. id1 = "id"
643
644
self ._names .setdefault (c .name , c )
644
645
self ._jamf_ids .setdefault (c .id , c )
645
646
else :
@@ -1010,31 +1011,35 @@ class OSXConfigurationProfiles(Records, metaclass=Singleton):
1010
1011
singular_class = OSXConfigurationProfile
1011
1012
1012
1013
1014
+ def parse_package_name (name ):
1015
+ m = re .match ("([^-]*)-(.*)\.([^\.]*)$" , name )
1016
+ if m :
1017
+ return m [1 ], m [2 ], m [3 ]
1018
+ else :
1019
+ m = re .match ("([^-]*)\.([^\.]*)$" , name )
1020
+ if m :
1021
+ return m [1 ], "" , m [2 ]
1022
+ else :
1023
+ return name , "" , ""
1024
+
1025
+
1013
1026
class Package (Record ):
1014
1027
plural_class = "Packages"
1015
1028
1016
1029
@property
1017
1030
def metadata (self ):
1018
1031
if not hasattr (self , "meta" ):
1019
- self ._metadata = {}
1020
- m = re .match ("([^-]*)-(.*)\.([^\.]*)$" , self .name )
1021
- if m :
1022
- self ._metadata ["basename" ] = m [1 ]
1023
- self ._metadata ["version" ] = m [2 ]
1024
- self ._metadata ["filetype" ] = m [3 ]
1025
- else :
1026
- m = re .match ("([^-]*)\.([^\.]*)$" , self .name )
1027
- if m :
1028
- self ._metadata ["basename" ] = m [1 ]
1029
- self ._metadata ["version" ] = ""
1030
- self ._metadata ["filetype" ] = m [2 ]
1031
- else :
1032
- self ._metadata ["basename" ] = self .name
1033
- self ._metadata ["version" ] = ""
1034
- self ._metadata ["filetype" ] = ""
1032
+ basename , version , filetype = parse_package_name (self .name )
1033
+ self ._metadata = {
1034
+ "basename" : basename ,
1035
+ "version" : version ,
1036
+ "filetype" : filetype ,
1037
+ }
1035
1038
if not self ._metadata ["basename" ] in self .plural .groups :
1036
1039
self .plural .groups [self ._metadata ["basename" ]] = []
1037
- self .plural .groups [self ._metadata ["basename" ]].append (self )
1040
+ if not self in self .plural .groups [self ._metadata ["basename" ]]:
1041
+ self .plural .groups [self ._metadata ["basename" ]].append (self )
1042
+
1038
1043
return self ._metadata
1039
1044
1040
1045
def refresh_related (self ):
@@ -1052,11 +1057,11 @@ def refresh_related(self):
1052
1057
patchsoftwaretitles_ids [str (title .id )] = {}
1053
1058
patchsoftwaretitles_ids [str (title .id )][versions [ii ]] = pkg
1054
1059
if not pkg in related :
1055
- related [pkg ] = {"patchsoftwaretitles " : []}
1056
- if not "patchsoftwaretitles " in related [pkg ]:
1057
- related [pkg ]["patchsoftwaretitles " ] = []
1060
+ related [pkg ] = {"PatchSoftwareTitles " : []}
1061
+ if not "PatchSoftwareTitles " in related [pkg ]:
1062
+ related [pkg ]["PatchSoftwareTitles " ] = []
1058
1063
temp = title .name + " - " + versions [ii ]
1059
- related [pkg ]["patchsoftwaretitles " ].append (temp )
1064
+ related [pkg ]["PatchSoftwareTitles " ].append (temp )
1060
1065
patchpolicies = jamf_records (PatchPolicies )
1061
1066
for policy in patchpolicies :
1062
1067
parent_id = policy .get_path ("software_title_configuration_id" )[0 ]
@@ -1066,31 +1071,31 @@ def refresh_related(self):
1066
1071
if parent_version in ppp :
1067
1072
pkg = ppp [parent_version ]
1068
1073
if not pkg in related :
1069
- related [pkg ] = {"patchpolicies " : []}
1070
- if not "patchpolicies " in related [pkg ]:
1071
- related [pkg ]["patchpolicies " ] = []
1072
- related [pkg ]["patchpolicies " ].append (policy .name )
1074
+ related [pkg ] = {"PatchPolicies " : []}
1075
+ if not "PatchPolicies " in related [pkg ]:
1076
+ related [pkg ]["PatchPolicies " ] = []
1077
+ related [pkg ]["PatchPolicies " ].append (policy .name )
1073
1078
policies = jamf_records (Policies )
1074
1079
for policy in policies :
1075
1080
pkgs = policy .get_path ("package_configuration/packages/package/name" )
1076
1081
if pkgs :
1077
1082
for pkg in pkgs :
1078
1083
if not pkg in related :
1079
- related [pkg ] = {"policies " : []}
1080
- if not "policies " in related [pkg ]:
1081
- related [pkg ]["policies " ] = []
1082
- related [pkg ]["policies " ].append (policy .name )
1084
+ related [pkg ] = {"Policies " : []}
1085
+ if not "Policies " in related [pkg ]:
1086
+ related [pkg ]["Policies " ] = []
1087
+ related [pkg ]["Policies " ].append (policy .name )
1083
1088
groups = jamf_records (ComputerGroups )
1084
1089
for group in groups :
1085
1090
criterions = group .get_path ("criteria/criterion/value" )
1086
1091
if criterions :
1087
1092
for pkg in criterions :
1088
1093
if pkg and re .search (".pkg|.zip|.dmg" , pkg [- 4 :]):
1089
1094
if not pkg in related :
1090
- related [pkg ] = {"groups " : []}
1091
- if not "groups " in related [pkg ]:
1092
- related [pkg ]["groups " ] = []
1093
- related [pkg ]["groups " ].append (group .name )
1095
+ related [pkg ] = {"ComputerGroups " : []}
1096
+ if not "ComputerGroups " in related [pkg ]:
1097
+ related [pkg ]["ComputerGroups " ] = []
1098
+ related [pkg ]["ComputerGroups " ].append (group .name )
1094
1099
self .__class__ ._related = related
1095
1100
1096
1101
@property
@@ -1104,21 +1109,21 @@ def related(self):
1104
1109
1105
1110
def usage_print_during (self ):
1106
1111
related = self .related
1107
- if "patchsoftwaretitles " in related :
1112
+ if "PatchSoftwareTitles " in related :
1108
1113
print (self .name )
1109
1114
else :
1110
1115
print (f"{ self .name } [no patch defined]" )
1111
- if "policies " in related :
1116
+ if "Policies " in related :
1112
1117
print (" Policies" )
1113
- for x in related ["policies " ]:
1118
+ for x in related ["Policies " ]:
1114
1119
print (" " + x )
1115
- if "groups " in related :
1120
+ if "ComputerGroups " in related :
1116
1121
print (" ComputerGroups" )
1117
- for x in related ["groups " ]:
1122
+ for x in related ["ComputerGroups " ]:
1118
1123
print (" " + x )
1119
- if "patchpolicies " in related :
1124
+ if "PatchPolicies " in related :
1120
1125
print (" PatchPolicies" )
1121
- for x in related ["patchpolicies " ]:
1126
+ for x in related ["PatchPolicies " ]:
1122
1127
print (" " + x )
1123
1128
print ()
1124
1129
@@ -1197,7 +1202,7 @@ def patchpolicies_print_during(self):
1197
1202
parent_id = policy .get_path ("software_title_configuration_id" )[0 ]
1198
1203
if str (parent_id ) != str (self .id ):
1199
1204
continue
1200
- print (" " + str (policy ))
1205
+ print (f" { policy . data [ 'general' ][ 'target_version' ] } : { str (policy )} " )
1201
1206
1202
1207
def set_all_packages_update_during (self ):
1203
1208
policy_regex = {
0 commit comments