def onResponse(self, dialog, responseId): if responseId == gtk.ResponseType.OK: timeZone = self.timeZoneInput.get_text() try: natz.timezone(timeZone) except Exception as e: self.errorLabel.set_text( _('Time zone is invalid') + '\n' + str(e) ) else: try: for event in ui.iterAllEvents(): event.timeZone = timeZone event.afterModify() event.save() except Exception as e: self.errorLabel.set_text( str(e) ) else: self.hide() else: self.hide() while gtk.events_pending(): gtk.main_iteration_do(False)
def doAction(self): container = self._container if self.iconRadio.get_active(): chType = self.iconChangeCombo.get_active() if chType != 0: icon = self.iconSelect.get_filename() for event in container: if not (chType == 2 and event.icon): event.icon = icon event.afterModify() event.save() elif self.timeZoneRadio.get_active(): chType = self.timeZoneChangeCombo.get_active() timeZone = self.timeZoneInput.get_text() if chType != 0: try: natz.timezone(timeZone) except: myRaise('Invalid Time Zone "%s"' % timeZone) else: for event in container: if not (chType == 2 and event.timeZone): event.timeZone = timeZone event.afterModify() event.save() else: chType = self.textChangeCombo.get_active() if chType != 0: text1 = self.textInput1.get_text() text2 = self.textInput2.get_text() if self.summaryRadio.get_active(): for event in container: if chType == 1: event.summary = text1 + event.summary elif chType == 2: event.summary = event.summary + text1 elif chType == 3: event.summary = event.summary.replace(text1, text2) event.afterModify() event.save() elif self.descriptionRadio.get_active(): for event in container: if chType == 1: event.description = text1 + event.description elif chType == 2: event.description = event.description + text1 elif chType == 3: event.description = event.description.replace( text1, text2) event.afterModify() event.save()
def doAction(self): container = self._container if self.iconRadio.get_active(): chType = self.iconChangeCombo.get_active() if chType!=0: icon = self.iconSelect.get_filename() for event in container: if not (chType==2 and event.icon): event.icon = icon event.afterModify() event.save() elif self.timeZoneRadio.get_active(): chType = self.timeZoneChangeCombo.get_active() timeZone = self.timeZoneInput.get_text() if chType!=0: try: natz.timezone(timeZone) except: myRaise('Invalid Time Zone "%s"'%timeZone) else: for event in container: if not (chType==2 and event.timeZone): event.timeZone = timeZone event.afterModify() event.save() else: chType = self.textChangeCombo.get_active() if chType!=0: text1 = self.textInput1.get_text() text2 = self.textInput2.get_text() if self.summaryRadio.get_active(): for event in container: if chType==1: event.summary = text1 + event.summary elif chType==2: event.summary = event.summary + text1 elif chType==3: event.summary = event.summary.replace(text1, text2) event.afterModify() event.save() elif self.descriptionRadio.get_active(): for event in container: if chType==1: event.description = text1 + event.description elif chType==2: event.description = event.description + text1 elif chType==3: event.description = event.description.replace(text1, text2) event.afterModify() event.save()
def onResponse(self, dialog, responseId): if responseId == gtk.ResponseType.OK: timeZone = self.timeZoneInput.get_text() try: natz.timezone(timeZone) except Exception as e: self.errorLabel.set_text( _('Time zone is invalid') + '\n' + str(e)) else: try: for event in ui.iterAllEvents(): event.timeZone = timeZone event.afterModify() event.save() except Exception as e: self.errorLabel.set_text(str(e)) else: self.hide() else: self.hide() while gtk.events_pending(): gtk.main_iteration_do(False)
def unpickler(zone, utcoffset=None, dstoffset=None, tzname=None): """Factory function for unpickling natz tzinfo instances. This is shared for both StaticTzInfo and DstTzInfo instances, because database changes could cause a zones implementation to switch between these two base classes and we can't break pickles on a natz version upgrade. """ import natz # Raises a KeyError if zone no longer exists, which should never happen # and would be a bug. tz = natz.timezone(zone) # A StaticTzInfo - just return it if utcoffset is None: return tz # This pickle was created from a DstTzInfo. We need to # determine which of the list of tzinfo instances for this zone # to use in order to restore the state of any datetime instances using # it correctly. utcoffset = memorized_timedelta(utcoffset) dstoffset = memorized_timedelta(dstoffset) try: return tz._tzinfos[(utcoffset, dstoffset, tzname)] except KeyError: # The particular state requested in this timezone no longer exists. # This indicates a corrupt pickle, or the timezone database has been # corrected violently enough to make this particular # (utcoffset,dstoffset) no longer exist in the zone, or the # abbreviation has been changed. pass # See if we can find an entry differing only by tzname. Abbreviations # get changed from the initial guess by the database maintainers to # match reality when this information is discovered. for localized_tz in tz._tzinfos.values(): if (localized_tz._utcoffset == utcoffset and localized_tz._dst == dstoffset): return localized_tz # This (utcoffset, dstoffset) information has been removed from the # zone. Add it back. This might occur when the database maintainers have # corrected incorrect information. datetime instances using this # incorrect information will continue to do so, exactly as they were # before being pickled. This is purely an overly paranoid safety net - I # doubt this will ever been needed in real life. inf = (utcoffset, dstoffset, tzname) tz._tzinfos[inf] = tz.__class__(inf, tz._tzinfos) return tz._tzinfos[inf]
def _tz_from_env(tzenv): if tzenv[0] == ':': tzenv = tzenv[1:] # TZ specifies a file if os.path.exists(tzenv): with open(tzenv, 'rb') as tzFp: return build_tzinfo('local', tzFp) # TZ specifies a zoneinfo zone. try: tz = natz.timezone(tzenv) # That worked, so we return this: return tz except UnknownTimeZoneError: raise UnknownTimeZoneError( "We don't support non-zoneinfo timezones like %s. \n" "Please use a timezone in the form of Continent/City")
def get_localzone(_root='/'): """Tries to find the local timezone configuration. This method prefers finding the timezone name and passing that to natz, over passing in the localtime file, as in the later case the zoneinfo name is unknown. The parameter _root makes the function look for files like /etc/localtime beneath the _root directory. This is primarily used by the tests. In normal usage you call the function without parameters.""" tzenv = os.environ.get('TZ') if tzenv: return _tz_from_env(tzenv) # Now look for distribution specific configuration files # that contain the timezone name. tzpath = os.path.join(_root, 'etc/timezone') if os.path.exists(tzpath): with open(tzpath, 'rb') as tzFp: data = tzFp.read() # Issue #3 was that /etc/timezone was a zoneinfo file. # That's a misconfiguration, but we need to handle it gracefully: if data[:5] != 'TZif2': etctz = data.strip().decode() # Get rid of host definitions and comments: if ' ' in etctz: etctz, dummy = etctz.split(' ', 1) if '#' in etctz: etctz, dummy = etctz.split('#', 1) return natz.timezone(etctz.replace(' ', '_')) # CentOS has a ZONE setting in /etc/sysconfig/clock, # OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and # Gentoo has a TIMEZONE setting in /etc/conf.d/clock # We look through these files for a timezone: zone_re = re.compile('\s*ZONE\s*=\s*\"') timezone_re = re.compile('\s*TIMEZONE\s*=\s*\"') end_re = re.compile('\"') for filename in ('etc/sysconfig/clock', 'etc/conf.d/clock'): tzpath = os.path.join(_root, filename) if not os.path.exists(tzpath): continue with open(tzpath, 'rt') as tzFp: data = tzFp.readlines() for line in data: # Look for the ZONE= setting. match = zone_re.match(line) if match is None: # No ZONE= setting. Look for the TIMEZONE= setting. match = timezone_re.match(line) if match is not None: # Some setting existed line = line[match.end():] etctz = line[:end_re.search(line).start()] # We found a timezone return natz.timezone(etctz.replace(' ', '_')) # No explicit setting existed. Use localtime for filename in ('etc/localtime', 'usr/local/etc/localtime'): tzpath = os.path.join(_root, filename) if not os.path.exists(tzpath): continue with open(tzpath, 'rb') as tzFp: return build_tzinfo('local', tzFp) raise UnknownTimeZoneError('Can not find any timezone configuration')