コード例 #1
0
ファイル: disker.py プロジェクト: ylatuya/Flumotion
    def changeFilename(self, filenameTemplate=None, timeTuple=None):
        """
        @param filenameTemplate: strftime format string to decide filename
        @param timeTuple:        a valid time tuple to pass to strftime,
                                 defaulting to time.localtime().
        """
        mime = self.getMime()
        ext = mimeTypeToExtention(mime)

        self.stopRecording()

        sink = self.get_element('fdsink')
        if sink.get_state() == gst.STATE_NULL:
            sink.set_state(gst.STATE_READY)

        filename = ""
        if not filenameTemplate:
            filenameTemplate = self._defaultFilenameTemplate
        filename = "%s.%s" % (format.strftime(filenameTemplate,
            timeTuple or time.localtime()), ext)
        self.location = os.path.join(self.directory, filename)

        # only overwrite existing files if it was last changed before the
        # start of this event; ie. if it is a recording of a previous event
        location = self.location
        i = 1
        while os.path.exists(location):
            mtimeTuple = time.gmtime(os.stat(location).st_mtime)
            if mtimeTuple <= timeTuple:
                self.info(
                    "Existing recording %s from previous event, overwriting",
                    location)
                break

            self.info(
                "Existing recording %s from current event, changing name",
                location)
            location = self.location + '.' + str(i)
            i += 1
        self.location = location

        self.info("Changing filename to %s", self.location)
        try:
            self.file = open(self.location, 'wb')
        except IOError, e:
            self.warning("Failed to open output file %s: %s",
                       self.location, log.getExceptionMessage(e))
            m = messages.Error(T_(N_(
                "Failed to open output file '%s' for writing. "
                "Check permissions on the file."), self.location))
            self.addMessage(m)
            return
コード例 #2
0
ファイル: disker.py プロジェクト: faroncoder/flumotion
    def changeFilename(self, filenameTemplate=None, datetime=None):
        """
        @param filenameTemplate: strftime format string to decide filename
        @param time:             an aware datetime used for the filename and
                                 to compare if an existing file needs to be
                                 overwritten. defaulting to datetime.now().
        """
        mime = self.getMime()
        ext = mimeTypeToExtention(mime)

        # if the events comes from the calendar, datetime is aware and we can
        # deduce from it both the local and utc time.
        # in case datetime is None datetime.now() doesn't return an aware
        # datetime, so we need to get both the local time and the utc time.
        tm = datetime or dt.datetime.now()
        tmutc = datetime or dt.datetime.utcnow()

        # delay the stop of the current recording to ensure there are no gaps
        # in the recorded files. We could think that emitting first the signal
        # to add a new client before the one to remove the client and syncing
        # with the latest keyframe should be enough, but it doesn't ensure the
        # stream continuity if it's done close to a keyframe because when
        # multifdsink looks internally for the latest keyframe it's already to
        # late and a gap is introduced.
        reactor.callLater(self.timeOverlap, self._stopRecordingFull, self.file,
                          self.location, self.last_tstamp, True)

        sink = self.get_element('fdsink')
        if sink.get_state() == gst.STATE_NULL:
            sink.set_state(gst.STATE_READY)

        filename = ""
        if not filenameTemplate:
            filenameTemplate = self._defaultFilenameTemplate
        filename = "%s.%s" % (
            formatting.strftime(
                filenameTemplate,
                # for the filename we want to use the local time
                tm.timetuple()),
            ext)
        self.location = os.path.join(self.directory, filename)

        # only overwrite existing files if it was last changed before the
        # start of this event; ie. if it is a recording of a previous event
        location = self.location
        i = 1
        while os.path.exists(location):
            mtimeTuple = time.gmtime(os.stat(location).st_mtime)
            # time.gmtime returns a time tuple in utc, so we compare against
            # the utc timetuple of the datetime
            if mtimeTuple <= tmutc.utctimetuple():
                self.info(
                    "Existing recording %s from previous event, overwriting",
                    location)
                break

            self.info(
                "Existing recording %s from current event, changing name",
                location)
            location = self.location + '.' + str(i)
            i += 1
        self.location = location

        self.info("Changing filename to %s", self.location)
        self.file = _openFile(self, self, self.location, 'wb')
        if self.file is None:
            return
        self._recordingStarted(self.file, self.location)
        sink.emit('add', self.file.fileno())
        self.last_tstamp = time.time()
        self.uiState.set('filename', self.location)
        self.uiState.set('recording', True)

        if self._symlinkToCurrentRecording:
            self._updateSymlink(self.location, self._symlinkToCurrentRecording)
コード例 #3
0
ファイル: disker.py プロジェクト: offlinehacker/flumotion
    def changeFilename(self, filenameTemplate=None, datetime=None):
        """
        @param filenameTemplate: strftime format string to decide filename
        @param time:             an aware datetime used for the filename and
                                 to compare if an existing file needs to be
                                 overwritten. defaulting to datetime.now().
        """
        mime = self.getMime()
        ext = mimeTypeToExtention(mime)

        # if the events comes from the calendar, datetime is aware and we can
        # deduce from it both the local and utc time.
        # in case datetime is None datetime.now() doesn't return an aware
        # datetime, so we need to get both the local time and the utc time.
        tm = datetime or dt.datetime.now()
        tmutc = datetime or dt.datetime.utcnow()

        # delay the stop of the current recording to ensure there are no gaps
        # in the recorded files. We could think that emitting first the signal
        # to add a new client before the one to remove the client and syncing
        # with the latest keyframe should be enough, but it doesn't ensure the
        # stream continuity if it's done close to a keyframe because when
        # multifdsink looks internally for the latest keyframe it's already to
        # late and a gap is introduced.
        reactor.callLater(self.timeOverlap, self._stopRecordingFull, self.file,
                          self.location, self.last_tstamp, True)

        sink = self.get_element('fdsink')
        if sink.get_state() == gst.STATE_NULL:
            sink.set_state(gst.STATE_READY)

        filename = ""
        if not filenameTemplate:
            filenameTemplate = self._defaultFilenameTemplate
        filename = "%s.%s" % (formatting.strftime(filenameTemplate,
            # for the filename we want to use the local time
            tm.timetuple()), ext)
        self.location = os.path.join(self.directory, filename)

        # only overwrite existing files if it was last changed before the
        # start of this event; ie. if it is a recording of a previous event
        location = self.location
        i = 1
        while os.path.exists(location):
            mtimeTuple = time.gmtime(os.stat(location).st_mtime)
            # time.gmtime returns a time tuple in utc, so we compare against
            # the utc timetuple of the datetime
            if mtimeTuple <= tmutc.utctimetuple():
                self.info(
                    "Existing recording %s from previous event, overwriting",
                    location)
                break

            self.info(
                "Existing recording %s from current event, changing name",
                location)
            location = self.location + '.' + str(i)
            i += 1
        self.location = location

        self.info("Changing filename to %s", self.location)
        self.file = _openFile(self, self, self.location, 'wb')
        if self.file is None:
            return
        self._recordingStarted(self.file, self.location)
        sink.emit('add', self.file.fileno())
        self.last_tstamp = time.time()
        self.uiState.set('filename', self.location)
        self.uiState.set('recording', True)

        if self._symlinkToCurrentRecording:
            self._updateSymlink(self.location,
                                self._symlinkToCurrentRecording)