--- pyanaconda/iw/timezone_gui.py | 10 ++++++++++ pyanaconda/timezone.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/pyanaconda/iw/timezone_gui.py b/pyanaconda/iw/timezone_gui.py index 6bad1a4..292476d 100644 --- a/pyanaconda/iw/timezone_gui.py +++ b/pyanaconda/iw/timezone_gui.py @@ -25,6 +25,7 @@ from scdate.core import zonetab from timezone_map_gui import TimezoneMap from iw_gui import * +from pyanaconda import gui from pyanaconda.constants import * import gettext @@ -80,6 +81,13 @@ class TimezoneWindow(InstallWindow): self.timezone = anaconda.timezone (self.default, asUTC) = self.timezone.getTimezoneInfo() + wait_window = gui.WaitWindow(_("Getting GeoIP information"), _("Trying to get GeoIP information.")) + timezone_guess = self.timezone.getGeoIPtimezone() + if timezone_guess: + self.timezone.setTimezoneInfo(timezone_guess, asUTC) + self.default = timezone_guess + wait_window.pop() + if not self.default: self.default = anaconda.instLanguage.getDefaultTimeZone() asUTC = 0 @@ -89,6 +97,8 @@ class TimezoneWindow(InstallWindow): self.default = self.default.replace("_", " ") + + self.utcCheckbox.set_active(asUTC) if not anaconda.ksdata: diff --git a/pyanaconda/timezone.py b/pyanaconda/timezone.py index 9da44ee..6d40717 100644 --- a/pyanaconda/timezone.py +++ b/pyanaconda/timezone.py @@ -23,9 +23,17 @@ import os from flags import flags from pyanaconda.constants import ROOT_PATH +import httplib +import re +from scdate.core import zonetab +import pyanaconda.network + import logging log = logging.getLogger("anaconda") +MIRROR_MANAGER_URL = "mirrors.fedoraproject.org" +MIRROR_LIST_REQUEST = "/mirrorlist?repo=fedora-15&arch=i386" + class Timezone: def writeKS(self, f): f.write("timezone") @@ -76,3 +84,26 @@ class Timezone: def __init__(self): self.tz = "America/New_York" self.utc = 0 + + def getGeoIPtimezone(self): + if not pyanaconda.network.hasActiveNetDev(): + log.info("Cannot get GeoIP information: network down") + return None + conn = httplib.HTTPSConnection(MIRROR_MANAGER_URL) + conn.request("GET", MIRROR_LIST_REQUEST) + res = conn.getresponse() + + data = res.read() + lines = data.split("\n") + del(data) + + m = re.search(r'country\s+=\s+([A-Z]+)', lines[0]) + + zonetab_ = zonetab.ZoneTab() + country = m.group(1) + + geoip_timezone = zonetab_.findEntryByCountryCode(country) + if geoip_timezone: + return geoip_timezone.tz + + return None -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list