Initial commit (fork from ManiMatter/mirrarr)

Carved out the queue cleaning bits from mirrarr, without taking over the instance synchronization items.
Not tested yet.
This commit is contained in:
Benjamin Harder
2023-09-30 15:04:15 +02:00
parent 836feb9bea
commit 36294d0f9c
15 changed files with 718 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
async def nested_set(dic, keys, value, matchConditions=None):
# Sets the value of a key in a dictionary to a certain value.
# If multiple items are present, it can filter for a matching item
for key in keys[:-1]:
dic = dic.setdefault(key, {})
if matchConditions:
i = 0
match = False
for item in dic:
for matchCondition in matchConditions:
if item[matchCondition] != matchConditions[matchCondition]:
match = False
break
else:
match = True
if match:
dic = dic[i]
break
i += 1
dic[keys[-1]] = value
async def add_keys_nested_dict(d, keys, defaultValue = None):
# Creates a nested value if key does not exist
for key in keys[:-1]:
if key not in d:
d[key] = {}
d = d[key]
d.setdefault(keys[-1], defaultValue)
async def nested_get(dic, return_attribute, matchConditions):
# Retrieves a list contained in return_attribute, found within dic based on matchConditions
i = 0
match = False
hits = []
for item in dic:
for matchCondition in matchConditions:
if item[matchCondition] != matchConditions[matchCondition]:
match = False
break
else:
match = True
if match:
hits.append(dic[i][return_attribute])
i += 1
return hits