home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / textw / timezone.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  2.7 KB  |  113 lines

  1. import string
  2. import iutil
  3. import os
  4. from time import *
  5. from snack import *
  6. from textw.constants import *
  7. from translate import _
  8.  
  9. class TimezoneWindow:
  10.  
  11.     def getTimezoneList(self, test):
  12.     if not os.access("/usr/lib/timezones.gz", os.R_OK):
  13.             if test:
  14.                 cmd = "./gettzlist"
  15.                 stdin = None
  16.             else:
  17.                 zoneList = iutil.findtz('/usr/share/zoneinfo', '')
  18.                 cmd = ""
  19.                 stdin = None
  20.     else:
  21.         cmd = "/usr/bin/gunzip"
  22.         stdin = os.open("/usr/lib/timezones.gz", 0)
  23.  
  24.         if cmd != "":
  25.             zones = iutil.execWithCapture(cmd, [ cmd ], stdin = stdin)
  26.             zoneList = string.split(zones)
  27.  
  28.     if (stdin != None):
  29.             os.close(stdin)
  30.  
  31.     return zoneList
  32.  
  33.     def updateSysClock(self):
  34.     if os.access("/sbin/hwclock", os.X_OK):
  35.         args = [ "/sbin/hwclock" ]
  36.     else:
  37.         args = [ "/usr/sbin/hwclock" ]
  38.  
  39.     args.append("--hctosys")
  40.     if self.c.selected():
  41.         args.append("--utc")
  42.  
  43.     iutil.execWithRedirect(args[0], args)
  44.     self.g.setTimer(500)
  45.     self.updateClock()
  46.  
  47.     def updateClock(self):
  48.     if os.access("/usr/share/zoneinfo/" + self.l.current(), os.R_OK):
  49.         os.environ['TZ'] = self.l.current()
  50.         self.label.setText(self.currentTime())
  51.     else:
  52.         self.label.setText("")
  53.  
  54.     def currentTime(self):
  55.     return "Current time: " + strftime("%X %Z", localtime(time()))
  56.  
  57.     def __call__(self, screen, todo, test):
  58.     timezones = self.getTimezoneList(test)
  59.     rc = todo.getTimezoneInfo()
  60.     if rc:
  61.         (default, asUtc, asArc) = rc
  62.     else:
  63.         default = "US/Eastern"
  64.         asUtc = 0
  65.  
  66.     bb = ButtonBar(screen, [(_("OK"), "ok"), (_("Back"), "back")])
  67.     t = TextboxReflowed(30, 
  68.             _("What time zone are you located in?"))
  69.  
  70.     self.label = Label(self.currentTime())
  71.         
  72.     self.l = Listbox(5, scroll = 1, returnExit = 0)
  73.  
  74.         for tz in timezones:
  75.         self.l.append(tz, tz)
  76.  
  77.     self.l.setCurrent(default)
  78.     self.l.setCallback(self.updateClock)
  79.  
  80.     self.c = Checkbox(_("Hardware clock set to GMT?"), isOn = asUtc)
  81.     self.c.setCallback(self.updateSysClock)
  82.  
  83.     self.g = GridForm(screen, _("Time Zone Selection"), 1, 5)
  84.     self.g.add(t, 0, 0)
  85.     self.g.add(self.label, 0, 1, padding = (0, 1, 0, 0), anchorLeft = 1)
  86.     self.g.add(self.c, 0, 2, padding = (0, 1, 0, 1), anchorLeft = 1)
  87.     self.g.add(self.l, 0, 3, padding = (0, 0, 0, 1))
  88.     self.g.add(bb, 0, 4, growx = 1)
  89.  
  90.     self.updateClock()
  91.     self.updateSysClock()
  92.  
  93.     self.g.setTimer(500)
  94.  
  95.     result = "TIMER"
  96.     while result == "TIMER":
  97.         result = self.g.run()
  98.         if result == "TIMER":
  99.         self.updateClock()
  100.  
  101.     screen.popWindow()
  102.  
  103.         button = bb.buttonPressed(result)
  104.  
  105.         if button == "back":
  106.             return INSTALL_BACK
  107.  
  108.     todo.setTimezoneInfo(self.l.current(), asUtc = self.c.selected())
  109.  
  110.     return INSTALL_OK
  111.  
  112.  
  113.