mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
38 lines
975 B
Python
Executable File
38 lines
975 B
Python
Executable File
#!/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()
|