Skip to content

Commit 045ddcf

Browse files
authored
Merge pull request #76 from univ-of-utah-marriott-library-apple/the_big_array_fix
The big array fix
2 parents 07378f0 + 7894a1f commit 045ddcf

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

jamf/convert.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ def etree_to_dict(elem):
3131
children = list(elem)
3232
if children:
3333
defd = defaultdict(list)
34-
for dct in map(etree_to_dict, children):
34+
has_size = False
35+
for child in children:
36+
if child.tag == "size":
37+
has_size = True
38+
dct = etree_to_dict(child)
3539
for key, val in dct.items():
3640
defd[key].append(val)
37-
result = {
38-
elem.tag: {
39-
key: val[0] if len(val) == 1 else val for key, val in defd.items()
40-
}
41-
}
41+
result = {}
42+
for key, val in defd.items():
43+
print(f"{key}, {val[0]}, {type(val[0])}, {has_size}")
44+
is_array = len(val) > 1 or ( has_size and type(val[0]) is dict )
45+
if not elem.tag in result:
46+
result[elem.tag] = {}
47+
if is_array:
48+
result[elem.tag][key] = val
49+
else:
50+
result[elem.tag][key] = val[0]
4251
elif elem.text:
4352
result[elem.tag] = elem.text.strip()
4453
return result
@@ -68,7 +77,6 @@ def dict_to_xml(data):
6877
else:
6978
# string, boolean, integers, floats, etc
7079
xml_str = xml.sax.saxutils.escape(f"{data}")
71-
7280
return xml_str
7381

7482

jamf/records.py

100755100644
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def get_path(self, path):
518518
def force_array(self, parent, child_name):
519519
_data = parent[child_name]
520520
if "size" in parent:
521-
if int(parent["size"]) > 1:
521+
if int(parent["size"]) > 0:
522522
return _data
523523
else:
524524
if type(_data) is list:
@@ -644,10 +644,7 @@ def refresh(self):
644644
self._names = {}
645645
self._jamf_ids = {}
646646
elif p3 in self.data: # e.g. category
647-
if self.data["size"] == "1":
648-
records = [self.data[p3]]
649-
else:
650-
records = self.data[p3]
647+
records = self.data[p3]
651648
for d in records:
652649
c = self.singular_class(d[id1], d["name"]) # e.g. id1 = "id"
653650
c.plural_class = self.cls
@@ -1434,10 +1431,7 @@ def promote_update_during(self):
14341431
if "package" not in self.data["package_configuration"]["packages"]:
14351432
print(f"{self.name} has no package to update.")
14361433
return True
1437-
if int(self.data["package_configuration"]["packages"]["size"]) > 1:
1438-
my_packages = self.data["package_configuration"]["packages"]["package"]
1439-
else:
1440-
my_packages = [self.data["package_configuration"]["packages"]["package"]]
1434+
my_packages = self.data["package_configuration"]["packages"]["package"]
14411435

14421436
all_packages = jamf_records(Packages)
14431437
print(self.name)

0 commit comments

Comments
 (0)