# -*- coding: utf-8 -*- # 2017.09.25 04:09:02 +11 #Embedded file name: /usr/lib/enigma2/python/Components/Converter/ClockToText.py from Converter import Converter from time import localtime, strftime, mktime, time from Components.Element import cached from datetime import date, datetime class ClockToText(Converter, object): DEFAULT = 0 WITH_SECONDS = 1 IN_MINUTES = 2 DATE = 3 FORMAT = 4 AS_LENGTH = 5 TIMESTAMP = 6 FULL = 7 SHORT_DATE = 8 LONG_DATE = 9 VFD = 10 AS_LENGTHHOURS = 11 AS_LENGTHSECONDS = 12 FULL_DATE = 13 NEWYEAR = 14 PERMANENTCLOCK = 15 def __init__(self, type): Converter.__init__(self, type) self.fix = '' if ';' in type: type, self.fix = type.split(';') if type == 'WithSeconds': self.type = self.WITH_SECONDS elif type == 'InMinutes': self.type = self.IN_MINUTES elif type == 'Date': self.type = self.DATE elif type == 'AsLength': self.type = self.AS_LENGTH elif type == 'AsLengthHours': self.type = self.AS_LENGTHHOURS elif type == 'AsLengthSeconds': self.type = self.AS_LENGTHSECONDS elif type == 'Timestamp': self.type = self.TIMESTAMP elif type == 'Full': self.type = self.FULL elif type == 'ShortDate': self.type = self.SHORT_DATE elif type == 'LongDate': self.type = self.LONG_DATE elif type == 'FullDate': self.type = self.FULL_DATE elif type == 'VFD': self.type = self.VFD elif type == 'NewYear': self.type = self.NEWYEAR elif type == 'PermanentClock': self.type = self.PERMANENTCLOCK elif 'Format' in type: self.type = self.FORMAT self.fmt_string = type[7:] else: self.type = self.DEFAULT @cached def getText(self): time = self.source.time if time is None: return '' def fix_space(string): if 'Proportional' in self.fix and t.tm_hour < 10: return ' ' + string if 'NoSpace' in self.fix: return string.lstrip(' ') return string def get_variant(amount, variants): cases = [2, 0, 1, 1, 1, 2] return variants[2 if (amount % 100 > 4 and amount % 100 < 20) else cases[min(amount % 10, 5)]] if self.type == self.IN_MINUTES: return ngettext('%d Min', '%d Mins', time / 60) % (time / 60) if self.type == self.AS_LENGTH: if time < 0: return '' return '%d:%02d' % (time / 60, time % 60) if self.type == self.AS_LENGTHHOURS: if time < 0: return '' return '%d:%02d' % (time / 3600, time / 60 % 60) if self.type == self.AS_LENGTHSECONDS: if time < 0: return '' return '%d:%02d:%02d' % (time / 3600, time / 60 % 60, time % 60) if self.type == self.TIMESTAMP: return str(time) t = localtime(time) td = datetime(date.today().year + 1, 1, 1) - datetime.now() days, hours, minutes, seconds = td.days, td.seconds // 3600, td.seconds // 60 % 60, td.seconds % 60 if self.type == self.WITH_SECONDS: return fix_space(_('%02d:%02d:%02d') % (t.tm_hour, t.tm_min, t.tm_sec)) if self.type == self.NEWYEAR: text = "" text += '{:0>2} д{} ; ' . format(days, get_variant(days, ('ень', 'ня', 'ней'))) text += '{:0>2} час{} ; ' . format(hours, get_variant(hours, ('', 'а', 'ов'))) text += '{:0>2} минут{} ; ' . format(minutes, get_variant(minutes, ('а', 'ы', ''))) text += '{:0>2} секунд{}' . format(seconds, get_variant(seconds, ('а', 'ы', ''))) return text if self.type == self.DEFAULT: return fix_space(_('%02d:%02d') % (t.tm_hour, t.tm_min)) if self.type == self.DATE: d = _('%A') elif self.type == self.FULL: d = _('%d.%m.%Y') elif self.type == self.SHORT_DATE: d = _('%a %d/%m') elif self.type == self.LONG_DATE: d = _('%A %d %B') elif self.type == self.FULL_DATE: d = _('%a %d %B %Y') elif self.type == self.VFD: d = _('%H:%M %d/%m') elif self.type == self.FORMAT: d = self.fmt_string elif self.type == self.PERMANENTCLOCK: d = _('%H:%M:%S\n%d.%m.%Y\n%A') else: return '???' return strftime(d, t) text = property(getText) # okay decompyling /tmp/ClockToText.pyo # decompiled 1 files: 1 okay, 0 failed, 0 verify failed # 2017.09.25 04:09:06 +11 |