Skip to content

Commit 0397a99

Browse files
committed
v5.11.x development
1 parent ca02054 commit 0397a99

File tree

3 files changed

+314
-278
lines changed

3 files changed

+314
-278
lines changed

mumc_modules/mumc_data_checks.py

Lines changed: 228 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,231 @@ def checkDict(self,*cfgLocationTuple,value=None,instanceType=None,minLength=None
238238
self.errorString+=self.setListErrorText(comparisonValues,*cfgLocationTuple)
239239
return None
240240
else:
241-
return value
241+
return value
242+
243+
244+
#Check blacklist and whitelist config variables are as expected
245+
def cfgCheckYAML_forLibraries(check_list, user_ids_check_list, user_names_check_list, config_var_name):
246+
247+
error_found_in_mumc_config_yaml=''
248+
249+
for check_irt in check_list:
250+
#Check if user_id exists
251+
if ('user_id' in check_irt):
252+
#Set user tracker to zero
253+
user_found=0
254+
#Check user from user_keys is also a user in this blacklist/whitelist
255+
for user_check in user_ids_check_list:
256+
if (user_check == check_irt['user_id']):
257+
user_found+=1
258+
if (user_found == 0):
259+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' user_id ' + check_irt['user_id'] + ' does not match any user from user_keys\n'
260+
if (user_found > 1):
261+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' user_id ' + check_irt['user_id'] + ' is seen more than once\n'
262+
#Check user_id is string
263+
if (not (isinstance(check_irt['user_id'], str))):
264+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' the user_id is not a string or is not a list for at least one user\n'
265+
else:
266+
#Check user_id is 32 character long alphanumeric
267+
if (not (
268+
(check_irt['user_id'].isalnum()) and
269+
(len(check_irt['user_id']) == 32)
270+
)):
271+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' + at least one user_id is not a 32-character alphanumeric string\n'
272+
else:
273+
error_found_in_mumc_config_yaml+='ConfigNameError: The ' + config_var_name + ' > user_id key is missing for at least one user\n'
274+
275+
276+
#Check if user_name exists
277+
if ('user_name' in check_irt):
278+
#Set user tracker to zero
279+
user_found=0
280+
#Check user from user_name is also a user in this blacklist/whitelist
281+
for user_check in user_names_check_list:
282+
if (user_check == check_irt['user_name']):
283+
user_found+=1
284+
if (user_found == 0):
285+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' user_name ' + check_irt['user_name'] + ' does not match any user from user_keys\n'
286+
if (user_found > 1):
287+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' user_name ' + check_irt['user_name'] + ' is seen more than once\n'
288+
#Check user_name is string
289+
if (not (isinstance(check_irt['user_name'], str))):
290+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' the user_name is not a string or is not a list for at least one user\n'
291+
else:
292+
error_found_in_mumc_config_yaml+='ConfigNameError: The ' + config_var_name + ' > user_name is missing for at least one user\n'
293+
294+
#Check if whitelist exists
295+
if ('whitelist' in check_irt):
296+
#Check whitelist is string
297+
if (not (isinstance(check_irt['whitelist'], list))):
298+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' the whitelist is not a string or is not a list for at least one user\n'
299+
else:
300+
error_found_in_mumc_config_yaml+='ConfigNameError: The ' + config_var_name + ' > whitelist is missing for at least one user\n'
301+
302+
#Check if blacklist exists
303+
if ('blacklist' in check_irt):
304+
#Check blacklist is string
305+
if (not (isinstance(check_irt['blacklist'], list))):
306+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' the blacklist is not a string or is not a list for at least one user\n'
307+
else:
308+
error_found_in_mumc_config_yaml+='ConfigNameError: The ' + config_var_name + ' > blacklist is missing for at least one user\n'
309+
310+
#Get number of elements
311+
for user_elements in check_irt:
312+
#Ignore user_id and user_name
313+
#Check whitelist and blacklist only if they are not empty lists
314+
if (((not (user_elements == 'user_id')) and (not (user_elements == 'user_name'))) and (((user_elements == 'whitelist') or (user_elements == 'blacklist')) and check_irt[user_elements])):
315+
#Set library key trackers to zero
316+
lib_id_found=0
317+
collection_type_found=0
318+
path_found=0
319+
network_path_found=0
320+
subfolder_id_found=0
321+
lib_enabled_found=0
322+
#Check if this num_element exists before proceeding
323+
if (user_elements in check_irt):
324+
for libinfo in check_irt[user_elements]:
325+
if ('lib_id' in libinfo):
326+
lib_id_found += 1
327+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['lib_id']
328+
#Check lib_id is alphanumeric string
329+
if (not (isinstance(check_item,str) and (check_item.isalpha() or check_item.isalnum() or check_item.isnumeric()))):
330+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > lib_id: ' + str(check_item) + ' is not an expected string value\n'
331+
332+
if ('collection_type' in libinfo):
333+
collection_type_found += 1
334+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['collection_type']
335+
#Check collection_type is string
336+
if (not (isinstance(check_item,str) or (check_item == ''))):
337+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > library_id: ' + str(libinfo['lib_id']) + ' > collection_type: ' + str(check_item) + ' is not an expected string value\n'
338+
339+
if ('path' in libinfo):
340+
path_found += 1
341+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['path']
342+
#Check path is string; checking for backslashes does not work for windows
343+
#if (not ((isinstance(check_item,str) and (check_item.find('\\') < 0)) or (check_item == '') or (check_item == None))):
344+
if (not (isinstance(check_item,str) or (check_item == '') or (check_item == None))):
345+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > library_id: ' + str(libinfo['lib_id']) + ' > path: ' + str(check_item) + ' is not an expected string value\n'
346+
347+
if ('network_path' in libinfo):
348+
network_path_found += 1
349+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['network_path']
350+
#Check network_path is string; checking for backslashes does not work for windows
351+
#if (not ((isinstance(check_item,str) and (check_item.find('\\') < 0)) or (check_item == '') or (check_item == None))):
352+
if (not (isinstance(check_item,str) or (check_item == '') or (check_item == None))):
353+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > library_id: ' + str(libinfo['lib_id']) + ' > network_path: ' + str(check_item) + ' is not an expected string value\n'
354+
355+
if ('subfolder_id' in libinfo):
356+
subfolder_id_found += 1
357+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['subfolder_id']
358+
#Check subfolder_id is alphanumeric string
359+
if (not ((check_item == None) or (isinstance(check_item,str) and (check_item.isalpha() or check_item.isalnum() or check_item.isnumeric())))):
360+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > subfolder_id: ' + str(check_item) + ' is not an expected string value. Try adding quotes: \'' + str(check_item) + '\' or null if Jellyfin\n'
361+
362+
if ('lib_enabled' in libinfo):
363+
lib_enabled_found += 1
364+
check_item=check_irt[user_elements][int(check_irt[user_elements].index(libinfo))]['lib_enabled']
365+
#Check lib_enabled is boolean
366+
if (not (isinstance(check_item,bool))):
367+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' > user_id: ' + str(check_irt['user_id']) + ' > ' + user_elements + ' > library_id: ' + str(libinfo['lib_id']) + ' > enabled: ' + str(check_item) + ' is not an expected boolean value\n'
368+
369+
if (lib_id_found == 0):
370+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key lib_id is missing\n'
371+
372+
if (collection_type_found == 0):
373+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key collection_type is missing\n'
374+
375+
if (network_path_found == 0):
376+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key network_path is missing\n'
377+
378+
if (path_found == 0):
379+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key path is missing\n'
380+
381+
if (subfolder_id_found == 0):
382+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key subfolder_id is missing\n'
383+
384+
if (lib_enabled_found == 0):
385+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' for user ' + check_irt['user_id'] + ' key lib_enabled is missing\n'
386+
387+
else:
388+
error_found_in_mumc_config_yaml+='ConfigValueError: ' + config_var_name + ' user ' + check_irt['user_id'] + ' key'+ str(user_elements) +' does not exist\n'
389+
return(error_found_in_mumc_config_yaml)
390+
391+
392+
#Check filter_tags are formatted as expected
393+
def cfgCheckYAML_isFilterTag(tag,tag_list):
394+
395+
no_error_found=True
396+
397+
if (
398+
not (isinstance(tag,str) and isinstance(tag_list,list) and
399+
(isinstance(tag_list[0],str) and ((tag_list[0] == 'played') or (tag_list[0] == 'created')) and
400+
isinstance(tag_list[1],int) and ((tag_list[1] >= -1) and (tag_list[1] <= 730500)) and
401+
isinstance(tag_list[2],str) and
402+
((tag_list[2] == '>') or (tag_list[2] == '<') or
403+
(tag_list[2] == '>=') or (tag_list[2] == '<=') or
404+
(tag_list[2] == '==') or (tag_list[2] == 'not ==') or
405+
(tag_list[2] == 'not >') or (tag_list[2] == 'not <') or
406+
(tag_list[2] == 'not >=') or (tag_list[2] == 'not <=')) and
407+
isinstance(tag_list[3],int) and ((tag_list[3] >= -1) and (tag_list[3] <= 730500)) and
408+
((tag_list[0] == 'played') or ((tag_list[0] == 'created') and isinstance(tag_list[4],bool) and ((tag_list[4] == True) or (tag_list[4] == False)))))
409+
)
410+
):
411+
no_error_found=False
412+
413+
return no_error_found
414+
415+
416+
#Check behavioral_tags config variables are as expected
417+
def cfgCheckYAML_isBehavioralTag(cfg,tag,media_type):
418+
419+
error_found_in_mumc_config_yaml=''
420+
421+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'action')) == None)):
422+
if (
423+
not (isinstance(check,str) and
424+
((check.casefold() == 'delete') or (check.casefold() == 'keep')))
425+
):
426+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > action must be a string\n\tValid values \'delete\' and \'keep\'\n'
427+
else:
428+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'user_conditional')) == None)):
429+
if (
430+
not (isinstance(check,str) and
431+
(check.casefold() == 'all'))
432+
):
433+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > user_conditional must be a string\n\tValid values \'any\' and \'all\'\n'
434+
else:
435+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'played_conditional')) == None)):
436+
if (
437+
not (isinstance(check,str) and
438+
((check.casefold() == 'all') or (check.casefold() == 'any') or #legacy values
439+
(check.casefold() == 'all_all') or (check.casefold() == 'any_any') or
440+
(check.casefold() == 'any_all') or (check.casefold() == 'all_any') or
441+
(check.casefold() == 'any_played') or (check.casefold() == 'all_played') or
442+
(check.casefold() == 'any_created') or (check.casefold() == 'all_created') or
443+
(check.casefold() == 'ignore')))
444+
):
445+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > played_conditional must be a string\n\tValid values \'any_any\', \'all_all\', \'any_all\', \'all_any\', \'any_played\', \'all_played\', \'any_created\', and \'all_created\'\n'
446+
else:
447+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'action_control')) == None)):
448+
if (
449+
not (isinstance(check,int) and
450+
((check >= 0) and (check <= 8)))
451+
):
452+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > action_control must be an integer\n\tValid range 0 thru 8\n'
453+
else:
454+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'dynamic_behavior')) == None)):
455+
if (
456+
not (isinstance(check,bool) and
457+
((check == True) or (check == False)))
458+
):
459+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > dynamic_behavior must be an boolean\n\tValid values True or False\n'
460+
else:
461+
if (not ((check:=keys_exist_return_value(cfg,'advanced_settings','behavioral_tags',media_type,tag,'high_priority')) == None)):
462+
if (
463+
not (isinstance(check,bool) and
464+
((check == True) or (check == False)))
465+
):
466+
error_found_in_mumc_config_yaml+='ConfigValueError: advanced_settings > behavioral_tags > ' + media_type + ' > ' + tag + ' > high_priority must be an boolean\n\tValid values True or False\n'
467+
468+
return error_found_in_mumc_config_yaml

mumc_modules/mumc_versions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,20 @@ def checkSemanticVersion(currentVersion,minVersion,maxVersion=None):
115115
version_ok=False
116116

117117
return version_ok
118+
119+
120+
def cfgCheckYAML_Version(cfg,init_dict):
121+
122+
if (cfg['version'] == ''):
123+
return 'ConfigVersionError: Config version is blank: \'\''\
124+
'\n Please use a config with a version greater than or equal to: '\
125+
+ init_dict['min_config_version'] + ' or create a new config \n'
126+
else:
127+
config_version_ok=checkSemanticVersion(cfg['version'],init_dict['min_config_version'])
128+
129+
if (not (config_version_ok)):
130+
return 'ConfigVersionError: Config version: ' + cfg['version'] + ' is not supported by script version: '\
131+
+ init_dict['script_version'] + '\n Please use a config with a version greater than or equal to: '\
132+
+ init_dict['min_config_version'] + ' or create a new config \n'
133+
else:
134+
return ''

0 commit comments

Comments
 (0)