mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
datetime: Rewrote action timezone-change in Python
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
68a0ed48fa
commit
6b5698f673
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/python3
|
||||||
#
|
#
|
||||||
# This file is part of Plinth.
|
# This file is part of Plinth.
|
||||||
#
|
#
|
||||||
@ -16,15 +16,38 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
zonename="$1"
|
"""
|
||||||
|
Set time zones with timedatectl (requires root permission).
|
||||||
|
"""
|
||||||
|
|
||||||
tzpath="/usr/share/zoneinfo/$zonename"
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
if [ -e "$tzpath" ] ; then
|
|
||||||
cp "$tzpath" /etc/localtime
|
def parse_arguments():
|
||||||
echo "$zonename" > /etc/timezone
|
"""Return parsed command line arguments as dictionary."""
|
||||||
exit 0
|
parser = argparse.ArgumentParser()
|
||||||
else
|
parser.add_argument(
|
||||||
echo "Time zone not valid" 1>&2
|
'timezone', help='Time zone to set; see "timedatectl list-timezones".')
|
||||||
exit 1
|
return parser.parse_args()
|
||||||
fi
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user