Package pyanaconda :: Module timezone
[hide private]
[frames] | no frames]

Source Code for Module pyanaconda.timezone

 1  # 
 2  # timezone.py - timezone install data 
 3  # 
 4  # Copyright (C) 2001  Red Hat, Inc.  All rights reserved. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
18  # 
19   
20  import shutil 
21  import iutil 
22  import os 
23  from flags import flags 
24  from pyanaconda.constants import ROOT_PATH 
25   
26  import logging 
27  log = logging.getLogger("anaconda") 
28   
29 -class Timezone:
30 - def writeKS(self, f):
31 f.write("timezone") 32 if self.utc: 33 f.write(" --utc") 34 f.write(" %s\n" % self.tz)
35
36 - def write(self):
37 fromFile = ROOT_PATH + "/usr/share/zoneinfo/" + self.tz 38 39 if not os.access(fromFile, os.R_OK): 40 log.error("Timezone to be copied (%s) doesn't exist" % fromFile) 41 else: 42 try: 43 shutil.copyfile(fromFile, ROOT_PATH + "/etc/localtime") 44 except EnvironmentError as e: 45 log.error("Error copying timezone (from %s): %s" % (fromFile, e.strerror)) 46 47 f = open(ROOT_PATH + "/etc/sysconfig/clock", "w") 48 49 f.write('ZONE="%s"\n' % self.tz) 50 f.close() 51 52 try: 53 f = open(ROOT_PATH + "/etc/adjtime", "r") 54 lines = f.readlines() 55 f.close() 56 except: 57 lines = [ "0.0 0 0.0\n", "0\n" ] 58 59 f = open(ROOT_PATH + "/etc/adjtime", "w") 60 f.write(lines[0]) 61 f.write(lines[1]) 62 if self.utc: 63 f.write("UTC\n") 64 else: 65 f.write("LOCAL\n") 66 f.close()
67
68 - def getTimezoneInfo(self):
69 return (self.tz, self.utc)
70
71 - def setTimezoneInfo(self, timezone, asUtc = 0):
72 log.info("set timezone: %s, utc: %d" % (timezone, asUtc)) 73 self.tz = timezone 74 self.utc = asUtc
75
76 - def __init__(self):
77 self.tz = "America/New_York" 78 self.utc = 0
79