Exemplo n.º 1
0
def should_show_time(tstamp1, tstamp2):
    '''
    Given two datetime objects, returns True if a "date status" should be
    shown between them.
    '''
    # show on date boundaries, but
    # convert to local before comparing the dates
    return fromutc(tstamp1).date() != fromutc(tstamp2).date()
Exemplo n.º 2
0
    def write_output(self, output, messageobj):
        '''
        Given output text and a message object, chooses a path for writing
        the log message and appends the output to that file.
        '''

        convo = messageobj.conversation
        proto = convo.protocol

        # Convert THIS timestamp to the local timezone so filenames are chosen based
        # on the local date.

        if convo.ischat:
            p = self.get_path_for_chat(convo)
        else:
            datefilename = fromutc(
                messageobj.timestamp).date().isoformat()  # 2007-17-5
            pathelems = (buddy_path(proto, convo.buddy), datefilename)
            p = path(
                path(self.OutputDir).joinpath(*pathelems) + '.' +
                self.OutputType)

        # assure path exists ( aim/digsby01/dotsyntax1337.html )
        if not p.parent.isdir():
            try:
                p.parent.makedirs()
            except WindowsError, e:  # for race condition between exists check and makedirs
                if e.winerror == 183:
                    pass
                else:
                    raise
Exemplo n.º 3
0
    def write_output(self, output,  messageobj):
        '''
        Given output text and a message object, chooses a path for writing
        the log message and appends the output to that file.
        '''

        convo = messageobj.conversation
        proto = convo.protocol

        # Convert THIS timestamp to the local timezone so filenames are chosen based
        # on the local date.

        if convo.ischat:
            p = self.get_path_for_chat(convo)
        else:
            datefilename = fromutc(messageobj.timestamp).date().isoformat() # 2007-17-5
            pathelems    = (buddy_path(proto, convo.buddy), datefilename)
            p = path(path(self.OutputDir).joinpath(*pathelems) + '.' + self.OutputType)

        # assure path exists ( aim/digsby01/dotsyntax1337.html )
        if not p.parent.isdir():
            try:
                p.parent.makedirs()
            except WindowsError, e: # for race condition between exists check and makedirs
                if e.winerror == 183:
                    pass
                else:
                    raise
Exemplo n.º 4
0
        def strf(t, fmt=None):
            if not self.show_tstamp and not self.should_always_show_timestamp:
                return '     '

            fmt = self.tstamp_fmt if fmt is None else fmt

            for s, repl in strftime_replacements:
                fmt = fmt.replace(s, repl)

            return strftime_u(fromutc(t), fmt)
Exemplo n.º 5
0
        def strf(t, fmt = None):
            if not self.show_tstamp and not self.should_always_show_timestamp:
                return '     '

            fmt = self.tstamp_fmt if fmt is None else fmt

            for s, repl in strftime_replacements:
                fmt = fmt.replace(s, repl)

            return strftime_u(fromutc(t), fmt)
Exemplo n.º 6
0
    def date_status(self, dt):
        # "Status" messages are reused as a form of date context for displaying
        # old messages in the history, and for when an IM window is open for
        # more than a day.

        # displayed timestamps need to be converted from UTC->local
        format_dt = fromutc(dt)

        return S(message   = format_dt.strftime(self.date_context_format),
                 timestamp = dt,
                 buddy     = None,
                 type      = None)
Exemplo n.º 7
0
def convo_time_filename(convo):
    '''
    Given a Conversation object, returns a date string which can be used to
    identify its logfile.
    '''

    # remove microseconds; we don't need THAT much precision.
    time_part = fromutc(convo.start_time_utc).replace(microsecond=0).strftime(chat_time_format)

    room_name = convo.chat_room_name
    if room_name:
        return '%s - %s' % (time_part, room_name)
    else:
        return time_part
Exemplo n.º 8
0
def convo_time_filename(convo):
    '''
    Given a Conversation object, returns a date string which can be used to
    identify its logfile.
    '''

    # remove microseconds; we don't need THAT much precision.
    time_part = fromutc(
        convo.start_time_utc).replace(microsecond=0).strftime(chat_time_format)

    room_name = convo.chat_room_name
    if room_name:
        return '%s - %s' % (time_part, room_name)
    else:
        return time_part
Exemplo n.º 9
0
    def get_path_for_chat(self, chat):
        pathdir = path(self.OutputDir) / chat_path(chat.protocol, chat)

        # log chats with the same name into the same file if it happened today
        if chat.chat_room_name:
            for f in pathdir.files('*.html'):
                name = f.namebase
                if 'T' in name:
                    day_part = name.split('T')[0]
                    try:
                        dt = datetime.strptime(day_part, chat_time_category)
                    except ValueError:
                        pass
                    else:
                        if fromutc(chat.start_time_utc).date() == dt.date():
                            try:
                                time_part, roomname = name.split(' - ', 1)
                            except ValueError:
                                pass
                            else:
                                if roomname == chat.chat_room_name:
                                    return f

        return pathdir / (convo_time_filename(chat) + '.' + self.OutputType)
Exemplo n.º 10
0
    def get_path_for_chat(self, chat):
        pathdir = path(self.OutputDir) / chat_path(chat.protocol, chat)

        # log chats with the same name into the same file if it happened today
        if chat.chat_room_name:
            for f in pathdir.files('*.html'):
                name = f.namebase
                if 'T' in name:
                    day_part = name.split('T')[0]
                    try:
                        dt = datetime.strptime(day_part, chat_time_category)
                    except ValueError:
                        pass
                    else:
                        if fromutc(chat.start_time_utc).date() == dt.date():
                            try:
                                time_part, roomname = name.split(' - ', 1)
                            except ValueError:
                                pass
                            else:
                                if roomname == chat.chat_room_name:
                                    return f

        return pathdir / (convo_time_filename(chat) + '.' + self.OutputType)