python类time()的实例源码

InfoBarGenerics.py 文件源码 项目:enigma2-openpli-fulan 作者: Taapat 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def activateTimeshiftEnd(self, back = True):
        self.back = back
        self.showTimeshiftState = True
        ts = self.getTimeshift()
        print "activateTimeshiftEnd"

        if ts is None:
            return

        if ts.isTimeshiftActive():
            print "!! activate timeshift called - but shouldn't this be a normal pause?"
            self.pauseService()
        else:
            print "play, ..."
            self.session.open(MessageBox, _("Timeshift"), MessageBox.TYPE_INFO, timeout = 3)
            ts.activateTimeshift() # activate timeshift will automatically pause
            self.ts_init_delay_timer.start(2000, True) # hack for spark

    #spark needs some time to initialize
htb.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, parentBucket=None):
        self.content = 0
        self.parentBucket=parentBucket
        self.lastDrip = time()
htb.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, parentFilter=None):
        self.buckets = {}
        self.parentFilter = parentFilter
        self.lastSweep = time()
htb.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def sweep(self):
        """I throw away references to empty buckets."""
        for key, bucket in self.buckets.items():
            if (bucket._refcount == 0) and bucket.drip():
                del self.buckets[key]

        self.lastSweep = time()
oath.py 文件源码 项目:SpongeAuth 作者: lukegb 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def t(self):
        """ The computed time step. """
        return ((int(self.time) - self.t0) // self.step) + self.drift
oath.py 文件源码 项目:SpongeAuth 作者: lukegb 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def time(self):
        """
        The current time.

        By default, this returns time.time() each time it is accessed. If you
        want to generate a token at a specific time, you can set this property
        to a fixed value instead. Deleting the value returns it to its 'live'
        state.

        """
        return self._time if (self._time is not None) else time()
oath.py 文件源码 项目:SpongeAuth 作者: lukegb 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def time(self, value):
        self._time = value
oath.py 文件源码 项目:SpongeAuth 作者: lukegb 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def time(self):
        self._time = None
simdht_worker.py 文件源码 项目:zsky 作者: wenguonideshou 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def fetch_torrent(session, ih, timeout):
        name = ih.upper()
        url = 'magnet:?xt=urn:btih:%s' % (name,)
        data = ''
        params = {
            'save_path': '/tmp/downloads/',
            'storage_mode': lt.storage_mode_t(2),
            'paused': False,
            'auto_managed': False,
            'duplicate_is_error': True}
        try:
            handle = lt.add_magnet_uri(session, url, params)
        except:
            return None
        status = session.status()
        #print 'downloading metadata:', url
        handle.set_sequential_download(1)
        meta = None
        down_time = time.time()
        down_path = None
        for i in xrange(0, timeout):
            if handle.has_metadata():
                info = handle.get_torrent_info()
                down_path = '/tmp/downloads/%s' % info.name()
                #print 'status', 'p', status.num_peers, 'g', status.dht_global_nodes, 'ts', status.dht_torrents, 'u', status.total_upload, 'd', status.total_download
                meta = info.metadata()
                break
            time.sleep(1)
        if down_path and os.path.exists(down_path):
            os.system('rm -rf "%s"' % down_path)
        session.remove_torrent(handle)
        return meta
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setResumePoint(session):
    global resumePointCache, resumePointCacheLast
    service = session.nav.getCurrentService()
    ref = session.nav.getCurrentlyPlayingServiceOrGroup()
    if (service is not None) and (ref is not None): # and (ref.type != 1):
        # ref type 1 has its own memory...
        seek = service.seek()
        if seek:
            pos = seek.getPlayPosition()
            if not pos[0]:
                key = ref.toString()
                lru = int(time())
                l = seek.getLength()
                if l:
                    l = l[1]
                else:
                    l = None
                resumePointCache[key] = [lru, pos[1], l]
                if len(resumePointCache) > 50:
                    candidate = key
                    for k,v in resumePointCache.items():
                        if v[0] < lru:
                            candidate = k
                    del resumePointCache[candidate]
                if lru - resumePointCacheLast > 3600:
                    saveResumePoints()
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def delResumePoint(ref):
    global resumePointCache, resumePointCacheLast
    try:
        del resumePointCache[ref.toString()]
    except KeyError:
        pass
    if int(time()) - resumePointCacheLast > 3600:
        saveResumePoints()
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def getResumePoint(session):
    global resumePointCache
    ref = session.nav.getCurrentlyPlayingServiceOrGroup()
    if (ref is not None) and (ref.type != 1):
        try:
            entry = resumePointCache[ref.toString()]
            entry[0] = int(time()) # update LRU timestamp
            return entry[1]
        except KeyError:
            return None
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def saveResumePoints():
    global resumePointCache, resumePointCacheLast
    import cPickle
    try:
        f = open('/home/root/resumepoints.pkl', 'wb')
        cPickle.dump(resumePointCache, f, cPickle.HIGHEST_PROTOCOL)
    except Exception, ex:
        print "[InfoBar] Failed to write resumepoints:", ex
    resumePointCacheLast = int(time())
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def ScreenSaverTimerStart(self):
        time = int(config.usage.screen_saver.value)
        flag = self.seekstate[0]
        if not flag:
            ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
            if ref and not (hasattr(self.session, "pipshown") and self.session.pipshown):
                ref = ref.toString().split(":")
                flag = ref[2] == "2" or os.path.splitext(ref[10])[1].lower() in AUDIO_EXTENSIONS
        if time and flag:
            self.screenSaverTimer.startLongTimer(time)
        else:
            self.screenSaverTimer.stop()
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __init__(self):
        self["MovieListActions"] = HelpableActionMap(self, "InfobarMovieListActions",
            {
                "movieList": (self.showMovies, _("Open the movie list")),
                "up": (self.up, _("Open the movie list")),
                "down": (self.down, _("Open the movie list"))
            }, prio=2)

# InfoBarTimeshift requires InfoBarSeek, instantiated BEFORE!

# Hrmf.
#
# Timeshift works the following way:
#                                         demux0   demux1                    "TimeshiftActions" "TimeshiftActivateActions" "SeekActions"
# - normal playback                       TUNER    unused      PLAY               enable                disable              disable
# - user presses "yellow" button.         FILE     record      PAUSE              enable                disable              enable
# - user presess pause again              FILE     record      PLAY               enable                disable              enable
# - user fast forwards                    FILE     record      FF                 enable                disable              enable
# - end of timeshift buffer reached       TUNER    record      PLAY               enable                enable               disable
# - user backwards                        FILE     record      BACK  # !!         enable                disable              enable
#

# in other words:
# - when a service is playing, pressing the "timeshiftStart" button ("yellow") enables recording ("enables timeshift"),
# freezes the picture (to indicate timeshift), sets timeshiftMode ("activates timeshift")
# now, the service becomes seekable, so "SeekActions" are enabled, "TimeshiftEnableActions" are disabled.
# - the user can now PVR around
# - if it hits the end, the service goes into live mode ("deactivates timeshift", it's of course still "enabled")
# the service looses it's "seekable" state. It can still be paused, but just to activate timeshift right
# after!
# the seek actions will be disabled, but the timeshiftActivateActions will be enabled
# - if the user rewinds, or press pause, timeshift will be activated again

# note that a timeshift can be enabled ("recording") and
# activated (currently time-shifting).
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def startTimeshift(self, pauseService = True):
        print "enable timeshift"
        ts = self.getTimeshift()
        if ts is None:
            if not pauseService and not int(config.usage.timeshift_start_delay.value):
                self.session.open(MessageBox, _("Timeshift not possible!"), MessageBox.TYPE_ERROR, simple = True)
            print "no ts interface"
            return 0

        if ts.isTimeshiftEnabled():
            print "hu, timeshift already enabled?"
        else:
            if not ts.startTimeshift():
                # we remove the "relative time" for now.
                #self.pvrStateDialog["timeshift"].setRelative(time.time())

                if pauseService:
                    # PAUSE.
                    #self.setSeekState(self.SEEK_STATE_PAUSE)
                    self.activateTimeshiftEnd(False)
                    self.showTimeshiftState = True
                else:
                    self.showTimeshiftState = False

                # enable the "TimeshiftEnableActions", which will override
                # the startTimeshift actions
                self.__seekableStatusChanged()

                # get current timeshift filename and calculate new
                self.save_timeshift_file = False
                self.save_timeshift_in_movie_dir = False
                self.setCurrentEventTimer()
                self.current_timeshift_filename = ts.getTimeshiftFilename()
                self.new_timeshift_filename = self.generateNewTimeshiftFileName()
            else:
                print "timeshift failed"
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def generateNewTimeshiftFileName(self):
        name = "timeshift record"
        info = { }
        self.getProgramInfoAndEvent(info, name)

        serviceref = info["serviceref"]

        service_name = ""
        if isinstance(serviceref, eServiceReference):
            service_name = ServiceReference(serviceref).getServiceName()
        begin_date = strftime("%Y%m%d %H%M", localtime(time()))
        filename = begin_date + " - " + service_name

        if config.recording.filename_composition.value == "short":
            filename = strftime("%Y%m%d", localtime(time())) + " - " + info["name"]
        elif config.recording.filename_composition.value == "long":
            filename += " - " + info["name"] + " - " + info["description"]
        else:
            filename += " - " + info["name"] # standard

        if config.recording.ascii_filenames.value:
            filename = ASCIItranslit.legacyEncode(filename)

        print "New timeshift filename: ", filename
        return filename

    # same as activateTimeshiftEnd, but pauses afterwards.
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def currentEventTime(self):
        remaining = 0
        ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
        if ref:
            epg = eEPGCache.getInstance()
            event = epg.lookupEventTime(ref, -1, 0)
            if event:
                now = int(time())
                start = event.getBeginTime()
                duration = event.getDuration()
                end = start + duration
                remaining = end - now
        return remaining
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def inputCallback(self, value):
        if value:
            print "stopping recording after", int(value), "minutes."
            entry = self.recording[self.selectedEntry]
            if int(value) != 0:
                entry.autoincrease = False
            entry.end = int(time()) + 60 * int(value)
            self.session.nav.RecordTimer.timeChanged(entry)
InfoBarGenerics.py 文件源码 项目:enigma2 作者: Openeight 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def restartInactiveTimer(self):
        time = abs(int(config.usage.inactivity_timer.value))
        if time:
            self.inactivityTimer.startLongTimer(time)
        else:
            self.inactivityTimer.stop()


问题


面经


文章

微信
公众号

扫码关注公众号