Systemd Utilities
This example shows how to use the systemd_py.core.models.Section
to load a systemd section
load_from_string.py |
---|
| from systemd_py.core.models import Section
def main():
text = """
[Service]
Type='simple'
ExecStart='adsas'
User='root'
"""
section = Section.load_from_string(text)
print(section)
print(type(section))
if __name__ == "__main__":
main()
|
load_from_string_with_model.py |
---|
| from systemd_py.core.models import Section
from systemd_py.core.models import Service
def main():
text = """
[Service]
Type='simple'
ExecStart='adsas'
User='root'
"""
section = Section.load_from_string(text, model=Service)
print(section)
print(type(section))
if __name__ == "__main__":
main()
|
load_from_string_with_section_name.py |
---|
| from systemd_py.core.models import Section
def main():
text = """
[Service]
Type='simple'
ExecStart='adsas'
User='root'
"""
section = Section.load_from_string(text, model="Service")
print(section)
print(type(section))
if __name__ == "__main__":
main()
|
output |
---|
| [Service]
Type='simple'
ExecStart='adsas'
User='root'
<class 'systemd_py.core.models.service.Service'>
|