forked from xcp-ng/host-installer_old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeutil
More file actions
executable file
·69 lines (58 loc) · 1.77 KB
/
timeutil
File metadata and controls
executable file
·69 lines (58 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# Copyright (c) 2005-2006 XenSource, Inc. All use and distribution of this
# copyrighted material is governed by and subject to terms and conditions
# as licensed by XenSource, Inc. All other rights reserved.
# Xen, XenSource and XenEnterprise are either registered trademarks or
# trademarks of XenSource Inc. in the United States and/or other countries.
###
# TIME UTILITY
# For use by clean installer so that we can avoid uClibc's
# time functions.
#
# written by Andrew Peace
import sys
import os
import datetime
import time
def getLocalNow(timezone = None):
if timezone:
os.environ['TZ'] = timezone
time.tzset()
now = datetime.datetime.now()
second = now.second
minute = now.minute
hour = now.hour
day = now.day
month = now.month
year = now.year
timestring = "%04d-%02d-%02d %02d:%02d:%02d" % \
(year, month, day, hour, minute, second)
print timestring
def setLocal(timestring, timezone = None):
if timezone:
os.environ['TZ'] = timezone
time.tzset()
os.system("date --set='%s'" % timestring)
def usage():
print "Usage: timeutil getLocalTime [timezone]"
print " or timeutil setLocalTime <time> [timezone]"
print
print "<time> is YYYY-MM-DD HH:mm:SS"
def main():
if len(sys.argv) == 1:
usage()
else:
if sys.argv[1] == 'getLocalTime':
if len(sys.argv) == 3:
getLocalNow(sys.argv[2])
else:
getLocalNow()
elif sys.argv[1] == 'setLocalTime':
if len(sys.argv) == 4:
setLocal(sys.argv[2], sys.argv[3])
else:
setLocal(sys.argv[2])
else:
usage()
if __name__ == '__main__':
main()