pyuserconfig/userconfig/checks.py

36 lines
809 B
Python
Raw Normal View History

import platform
2024-03-31 22:20:47 +02:00
def get_hostname():
2024-05-03 15:17:40 +02:00
node_name = platform.node()
if node_name.count("."):
return node_name.split(".")[0]
else:
return node_name
2024-03-31 22:20:47 +02:00
def get_arch():
return platform.system()
2024-05-03 15:17:40 +02:00
def get_domain():
node_name = platform.node()
if node_name.count("."):
return '.'.join(node_name.split('.')[1:])
else:
return ''
2024-03-31 22:20:47 +02:00
def check_class(class_tuple):
(prio, category, value, path) = class_tuple
if category == 'Arch':
return get_arch() == value
elif category == 'Host':
return get_hostname() == value
2024-05-03 15:17:40 +02:00
elif category == 'Domain':
return get_domain() == value
2024-03-31 22:20:47 +02:00
elif value == '': # if value is empty, we cannot filter anything, so it matches always
return True
else:
return False