datetime: Use privileged decorator for actions

Tests:

- Setting timezone shows:
  - In the interface and
  - timedatectl

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-10-08 18:51:45 -04:00
1 parent 013caa28bc
commit f9fd1b142a
3 files changed
+19 -43

No files matched your search

-37
View File
@@ -1,37 +0,0 @@
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Set time zones with timedatectl (requires root permission).
"""
import argparse
import subprocess
import sys
def parse_arguments():
"""Return parsed command line arguments as dictionary."""
parser = argparse.ArgumentParser()
parser.add_argument(
'timezone', help='Time zone to set; see "timedatectl list-timezones".')
return parser.parse_args()
def _set_timezone(arguments):
"""Set time zone with timedatectl."""
try:
command = ['timedatectl', 'set-timezone', arguments.timezone]
subprocess.run(command, stdout=subprocess.DEVNULL, check=True)
except subprocess.CalledProcessError as exception:
print('Error setting timezone:', exception, file=sys.stderr)
sys.exit(1)
def main():
"""Parse arguments and perform all duties."""
arguments = parse_arguments()
_set_timezone(arguments)
if __name__ == '__main__':
main()