当前位置: 首页>>代码示例>>Python>>正文


Python timezone.is_valid_timezone函数代码示例

本文整理汇总了Python中pyanaconda.timezone.is_valid_timezone函数的典型用法代码示例。如果您正苦于以下问题:Python is_valid_timezone函数的具体用法?Python is_valid_timezone怎么用?Python is_valid_timezone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_valid_timezone函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: refresh

    def refresh(self):
        self._shown = True

        #update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
                                                    self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()

        has_active_network = nm.nm_is_connected()
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if flags.can_touch_runtime_system("get NTP service state"):
            ntp_working = has_active_network and iutil.service_running(NTP_SERVICE)
        else:
            ntp_working = not self.data.timezone.nontp

        self._ntpSwitch.set_active(ntp_working)
开发者ID:cyclefusion,项目名称:anaconda,代码行数:26,代码来源:datetime_spoke.py

示例2: _refresh

    def _refresh(self):
        try:
            reply = requests.get(self.API_URL, timeout=constants.NETWORK_CONNECTION_TIMEOUT, verify=True)
            if reply.status_code == requests.codes.ok:
                json_reply = reply.json()
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                if timezone_code is not None:
                    # the timezone code is returned as Unicode,
                    # it needs to be converted to UTF-8 encoded string,
                    # otherwise some string processing in Anaconda might fail
                    timezone_code = timezone_code.encode("utf8")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(LocationResult(
                        territory_code=territory,
                        timezone=timezone_code,
                        timezone_source=timezone_source))
            else:
                log.error("Geoloc: Fedora GeoIP API lookup failed with status code: %s", reply.status_code)
        except requests.exceptions.RequestException as e:
            log.debug("Geoloc: RequestException for Fedora GeoIP API lookup:\n%s", e)
        except ValueError as e:
            log.debug("Geoloc: Unable to decode GeoIP JSON:\n%s", e)
开发者ID:jktjkt,项目名称:anaconda,代码行数:31,代码来源:geoloc.py

示例3: _refresh

    def _refresh(self):
        try:
            reply = urllib2.urlopen(self.API_URL, timeout=
                                    constants.NETWORK_CONNECTION_TIMEOUT)
            if reply:
                json_reply = json.load(reply)
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                if timezone_code is not None:
                    # the timezone code is returned as Unicode,
                    # it needs to be converted to UTF-8 encoded string,
                    # otherwise some string processing in Anaconda might fail
                    timezone_code = timezone_code.encode("utf8")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(LocationResult(
                        territory_code=territory,
                        timezone=timezone_code,
                        timezone_source=timezone_source))
        except urllib2.HTTPError as e:
            log.debug("Geoloc: HTTPError for Fedora GeoIP API lookup:\n%s (%s)",
                      e, self.API_URL)
        except urllib2.URLError as e:
            log.debug("Geoloc: URLError for Fedora GeoIP API lookup:\n%s (%s)",
                      e, self.API_URL)
开发者ID:Sabayon,项目名称:anaconda,代码行数:32,代码来源:geoloc.py

示例4: refresh

    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer = Timer()
        self._update_datetime_timer.timeout_sec(1, self._update_datetime)
        self._start_updating_timer = None

        kickstart_timezone = self._timezone_module.proxy.Timezone

        if is_valid_timezone(kickstart_timezone):
            self._tzmap.set_timezone(kickstart_timezone)
            time.tzset()

        self._update_datetime()

        has_active_network = self._network_module.proxy.Connected
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if conf.system.can_set_time_synchronization:
            ntp_working = has_active_network and util.service_running(NTP_SERVICE)
        else:
            ntp_working = self._timezone_module.proxy.NTPEnabled

        self._ntpSwitch.set_active(ntp_working)
开发者ID:zhangsju,项目名称:anaconda,代码行数:29,代码来源:datetime_spoke.py

示例5: status

 def status(self):
     if self.data.timezone.timezone:
         if timezone.is_valid_timezone(self.data.timezone.timezone):
             return _("%s timezone") % self.data.timezone.timezone
         else:
             return _("Invalid timezone")
     elif self._tzmap.get_timezone():
         return _("%s timezone") % self._tzmap.get_timezone()
     else:
         return _("Nothing selected")
开发者ID:cs2c-zhangchao,项目名称:nkwin1.0-anaconda,代码行数:10,代码来源:datetime_spoke.py

示例6: refresh

    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(1, self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()
开发者ID:marmarek,项目名称:qubes-installer-qubes-os,代码行数:11,代码来源:datetime_spoke.py

示例7: status

 def status(self):
     if self.data.timezone.timezone:
         if is_valid_timezone(self.data.timezone.timezone):
             return _("%s timezone") % get_xlated_timezone(self.data.timezone.timezone)
         else:
             return _("Invalid timezone")
     else:
         location = self._tzmap.get_location()
         if location and location.get_property("zone"):
             return _("%s timezone") % get_xlated_timezone(location.get_property("zone"))
         else:
             return _("Nothing selected")
开发者ID:akozumpl,项目名称:anaconda,代码行数:12,代码来源:datetime_spoke.py

示例8: _initialize

    def _initialize(self):
        for day in xrange(1, 32):
            self.add_to_store(self._daysStore, day)

        for i in xrange(1, 13):
            #a bit hacky way, but should return the translated string
            #TODO: how to handle language change? Clear and populate again?
            month = datetime.date(2000, i, 1).strftime('%B')
            self.add_to_store(self._monthsStore, month)
            self._months_nums[month] = i

        for year in xrange(1990, 2051):
            self.add_to_store(self._yearsStore, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.iterkeys())
        for region, xlated in sorted(xlated_regions, cmp=_compare_regions):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities, cmp=_compare_cities):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        if self._radioButton24h.get_active():
            self._set_amPm_part_sensitive(False)

        self._update_datetime_timer_id = None
        if is_valid_timezone(self.data.timezone.timezone):
            self._set_timezone(self.data.timezone.timezone)
        elif not flags.flags.automatedInstall:
            log.warning("%s is not a valid timezone, falling back to default (%s)",
                        self.data.timezone.timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self.data.timezone.timezone = DEFAULT_TZ

        if not flags.can_touch_runtime_system("modify system time and date"):
            self._set_date_time_setting_sensitive(False)

        self._config_dialog = NTPconfigDialog(self.data)
        self._config_dialog.initialize()

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                             _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)
开发者ID:joesaland,项目名称:qubes-installer-qubes-os,代码行数:50,代码来源:datetime_spoke.py

示例9: status

    def status(self):
        kickstart_timezone = self._timezone_module.proxy.Timezone

        if kickstart_timezone:
            if is_valid_timezone(kickstart_timezone):
                return _("%s timezone") % get_xlated_timezone(kickstart_timezone)
            else:
                return _("Invalid timezone")
        else:
            location = self._tzmap.get_location()
            if location and location.get_property("zone"):
                return _("%s timezone") % get_xlated_timezone(location.get_property("zone"))
            else:
                return _("Nothing selected")
开发者ID:zhangsju,项目名称:anaconda,代码行数:14,代码来源:datetime_spoke.py

示例10: _initialize

    def _initialize(self):
        # a bit hacky way, but should return the translated strings
        for i in range(1, 32):
            day = datetime.date(2000, 1, i).strftime(self._day_format)
            self.add_to_store_idx(self._daysStore, i, day)

        for i in range(1, 13):
            month = datetime.date(2000, i, 1).strftime(self._month_format)
            self.add_to_store_idx(self._monthsStore, i, month)

        for i in range(1990, 2051):
            year = datetime.date(i, 1, 1).strftime(self._year_format)
            self.add_to_store_idx(self._yearsStore, i, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.keys())
        for region, xlated in sorted(xlated_regions, key=functools.cmp_to_key(_compare_regions)):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities, key=functools.cmp_to_key(_compare_cities)):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        self._update_datetime_timer = None
        kickstart_timezone = self._timezone_module.proxy.Timezone
        if is_valid_timezone(kickstart_timezone):
            self._set_timezone(kickstart_timezone)
        elif not flags.flags.automatedInstall:
            log.warning("%s is not a valid timezone, falling back to default (%s)",
                        kickstart_timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self._timezone_module.proxy.SetTimezone(DEFAULT_TZ)

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                             _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)

        # report that we are done
        self.initialize_done()
开发者ID:zhangsju,项目名称:anaconda,代码行数:45,代码来源:datetime_spoke.py

示例11: execute

    def execute(self):
        # get the DBus proxies
        timezone_proxy = TIMEZONE.get_proxy()

        # write out timezone configuration
        kickstart_timezone = timezone_proxy.Timezone

        if not timezone.is_valid_timezone(kickstart_timezone):
            # this should never happen, but for pity's sake
            timezone_log.warning("Timezone %s set in kickstart is not valid, falling "
                                 "back to default (America/New_York).", kickstart_timezone)
            timezone_proxy.SetTimezone("America/New_York")

        timezone.write_timezone_config(timezone_proxy, util.getSysroot())

        # write out NTP configuration (if set) and --nontp is not used
        kickstart_ntp_servers = timezone_proxy.NTPServers

        if timezone_proxy.NTPEnabled and kickstart_ntp_servers:
            chronyd_conf_path = os.path.normpath(util.getSysroot() + ntp.NTP_CONFIG_FILE)
            pools, servers = ntp.internal_to_pools_and_servers(kickstart_ntp_servers)
            if os.path.exists(chronyd_conf_path):
                timezone_log.debug("Modifying installed chrony configuration")
                try:
                    ntp.save_servers_to_config(pools, servers, conf_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning("Failed to save NTP configuration: %s", ntperr)
            # use chrony conf file from installation environment when
            # chrony is not installed (chrony conf file is missing)
            else:
                timezone_log.debug("Creating chrony configuration based on the "
                                   "configuration from installation environment")
                try:
                    ntp.save_servers_to_config(pools, servers,
                                               conf_file_path=ntp.NTP_CONFIG_FILE,
                                               out_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning("Failed to save NTP configuration without chrony package: %s", ntperr)
开发者ID:rvykydal,项目名称:anaconda,代码行数:38,代码来源:kickstart.py

示例12: completed

 def completed(self):
     if self._kickstarted and not self.data.timezone.seen:
         # taking values from kickstart, but not specified
         return False
     else:
         return timezone.is_valid_timezone(self.data.timezone.timezone)
开发者ID:cs2c-zhangchao,项目名称:nkwin1.0-anaconda,代码行数:6,代码来源:datetime_spoke.py

示例13: all_timezones_valid_test

    def all_timezones_valid_test(self):
        """Check if all returned timezones are considered valid timezones."""

        for (region, zones) in timezone.get_all_regions_and_timezones().iteritems():
            for zone in zones:
                self.assertTrue(timezone.is_valid_timezone(region + "/" + zone))
开发者ID:akozumpl,项目名称:anaconda,代码行数:6,代码来源:timezone_test.py

示例14: completed

 def completed(self):
     if self._kickstarted and not self._timezone_module.proxy.Kickstarted:
         # taking values from kickstart, but not specified
         return False
     else:
         return is_valid_timezone(self._timezone_module.proxy.Timezone)
开发者ID:zhangsju,项目名称:anaconda,代码行数:6,代码来源:datetime_spoke.py


注:本文中的pyanaconda.timezone.is_valid_timezone函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。