Exemple #1
0
    def cli_note_dump(self, key):

        note = self.ndb.get_note(key)
        if not note:
            self.log(u'ERROR: Key does not exist')
            return

        w = 60
        sep = u'+' + u'-'*(w+2) + u'+'
        t = time.localtime(float(note['modifydate']))
        mod_time = time.strftime('%a, %d %b %Y %H:%M:%S', t)
        title = utils.get_note_title(note)
        flags = utils.get_note_flags(note)
        tags  = utils.get_note_tags(note)

        print sep
        print (u'| {:<' + str(w) + u'} |').format((u'    Title: ' + title)[:w])
        print (u'| {:<' + str(w) + u'} |').format((u'      Key: ' + note['key'])[:w])
        print (u'| {:<' + str(w) + u'} |').format((u'     Date: ' + mod_time)[:w])
        print (u'| {:<' + str(w) + u'} |').format((u'     Tags: ' + tags)[:w])
        print (u'| {:<' + str(w) + u'} |').format((u'  Version: v' + str(note['version']))[:w])
        print (u'| {:<' + str(w) + u'} |').format((u'    Flags: [' + flags + u']')[:w])
        if utils.note_published(note) and 'publishkey' in note:
            print (u'| {:<' + str(w) + u'} |').format((u'Published: http://simp.ly/publish/' + note['publishkey'])[:w])
        else:
            print (u'| {:<' + str(w) + u'} |').format((u'Published: n/a')[:w])
        print sep
        print note['content']
Exemple #2
0
    def cli_note_dump(self, key):

        note = self.ndb.get_note(key)
        if not note:
            self.log(u'ERROR: Key does not exist')
            return

        w = 60
        sep = u'+' + u'-' * (w + 2) + u'+'
        t = time.localtime(float(note['modifydate']))
        mod_time = time.strftime('%a, %d %b %Y %H:%M:%S', t)
        title = utils.get_note_title(note)
        flags = utils.get_note_flags(note)
        tags = utils.get_note_tags(note)

        print sep
        print(u'| {:<' + str(w) + u'} |').format((u'    Title: ' + title)[:w])
        print(u'| {:<' + str(w) + u'} |').format(
            (u'      Key: ' + note['key'])[:w])
        print(u'| {:<' + str(w) + u'} |').format(
            (u'     Date: ' + mod_time)[:w])
        print(u'| {:<' + str(w) + u'} |').format((u'     Tags: ' + tags)[:w])
        print(u'| {:<' + str(w) + u'} |').format(
            (u'  Version: v' + str(note['version']))[:w])
        print(u'| {:<' + str(w) + u'} |').format(
            (u'    Flags: [' + flags + u']')[:w])
        if utils.note_published(note) and 'publishkey' in note:
            print(u'| {:<' + str(w) + u'} |').format(
                (u'Published: http://simp.ly/publish/' +
                 note['publishkey'])[:w])
        else:
            print(u'| {:<' + str(w) + u'} |').format((u'Published: n/a')[:w])
        print sep
        print note['content']
Exemple #3
0
    def cli_list_notes(self, regex, search_string):

        note_list, match_regex, all_notes_cnt = \
            self.ndb.filter_notes(
                    search_string,
                    search_mode='regex' if regex else 'gstyle')
        for n in note_list:
            flags = utils.get_note_flags(n.note)
            print n.key + \
                  u' [' + flags + u'] ' + \
                  utils.get_note_title(n.note)
Exemple #4
0
    def cli_list_notes(self, regex, search_string):

        note_list, match_regex, all_notes_cnt = \
            self.ndb.filter_notes(
                    search_string,
                    search_mode='regex' if regex else 'gstyle')
        for n in note_list:
            flags = utils.get_note_flags(n.note)
            print n.key + \
                  u' [' + flags + u'] ' + \
                  utils.get_note_title(n.note)
Exemple #5
0
    def format_title(self, note):
        """
        Various formatting tags are supported for dynamically building
        the title string. Each of these formatting tags supports a width
        specifier (decimal) and a left justification (-) like that
        supported by printf.

        %F -- flags
        %T -- tags
        %D -- date
        %N -- note title
        """

        t = time.localtime(float(note['modifydate']))
        mod_time = time.strftime(self.config.get_config('format_strftime'), t)
        title = utils.get_note_title(note)
        flags = utils.get_note_flags(note)
        tags = utils.get_note_tags(note)

        # get the age of the note
        dt = datetime.datetime.fromtimestamp(time.mktime(t))
        if dt > datetime.datetime.now() - datetime.timedelta(days=1):
            note_age = 'd'  # less than a day old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=1):
            note_age = 'w'  # less than a week old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=4):
            note_age = 'm'  # less than a month old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=52):
            note_age = 'y'  # less than a year old
        else:
            note_age = 'a'  # ancient

        def recursive_format(title_format):
            if not title_format:
                return None
            fmt = re.search("^(.*)%([-]*)([0-9]*)([FDTN])(.*)$", title_format)
            if not fmt:
                m = ('pack', urwid.AttrMap(urwid.Text(title_format),
                                           'default'))
                l_fmt = None
                r_fmt = None
            else:
                l = fmt.group(1) if fmt.group(1) else None
                m = None
                r = fmt.group(5) if fmt.group(5) else None
                align = 'left' if fmt.group(2) == '-' else 'right'
                width = int(fmt.group(3)) if fmt.group(3) else 'pack'
                if fmt.group(4) == 'F':
                    m = (width,
                         urwid.AttrMap(
                             urwid.Text(flags, align=align, wrap='clip'),
                             'note_flags'))
                elif fmt.group(4) == 'D':
                    m = (width,
                         urwid.AttrMap(
                             urwid.Text(mod_time, align=align, wrap='clip'),
                             'note_date'))
                elif fmt.group(4) == 'T':
                    m = (width,
                         urwid.AttrMap(
                             urwid.Text(tags, align=align, wrap='clip'),
                             'note_tags'))
                elif fmt.group(4) == 'N':
                    if note_age == 'd': attr = 'note_title_day'
                    elif note_age == 'w': attr = 'note_title_week'
                    elif note_age == 'm': attr = 'note_title_month'
                    elif note_age == 'y': attr = 'note_title_year'
                    elif note_age == 'a': attr = 'note_title_ancient'
                    if width != 'pack':
                        m = (width,
                             urwid.AttrMap(
                                 urwid.Text(title, align=align, wrap='clip'),
                                 attr))
                    else:
                        m = urwid.AttrMap(
                            urwid.Text(title, align=align, wrap='clip'), attr)
                l_fmt = recursive_format(l)
                r_fmt = recursive_format(r)

            tmp = []
            if l_fmt: tmp.extend(l_fmt)
            tmp.append(m)
            if r_fmt: tmp.extend(r_fmt)
            return tmp

        # convert the format string into the actual note title line
        title_line = recursive_format(
            self.config.get_config('format_note_title'))
        return urwid.Columns(title_line)
Exemple #6
0
    def format_title(self, note):
        """
        Various formatting tags are supported for dynamically building
        the title string. Each of these formatting tags supports a width
        specifier (decimal) and a left justification (-) like that
        supported by printf.

        %F -- flags
        %T -- tags
        %D -- date
        %N -- note title
        """

        t = time.localtime(float(note['modifydate']))
        mod_time = time.strftime(self.config.get_config('format_strftime'), t)
        title = utils.get_note_title(note)
        flags = utils.get_note_flags(note)
        tags  = utils.get_note_tags(note)

        # get the age of the note
        dt = datetime.datetime.fromtimestamp(time.mktime(t))
        if dt > datetime.datetime.now() - datetime.timedelta(days=1):
            note_age = 'd' # less than a day old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=1):
            note_age = 'w' # less than a week old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=4):
            note_age = 'm' # less than a month old
        elif dt > datetime.datetime.now() - datetime.timedelta(weeks=52):
            note_age = 'y' # less than a year old
        else:
            note_age = 'a' # ancient

        def recursive_format(title_format):
            if not title_format:
                return None
            fmt = re.search("^(.*)%([-]*)([0-9]*)([FDTN])(.*)$", title_format)
            if not fmt:
                m = ('pack', urwid.AttrMap(urwid.Text(title_format),
                                           'default'))
                l_fmt = None
                r_fmt = None
            else:
                l = fmt.group(1) if fmt.group(1) else None
                m = None
                r = fmt.group(5) if fmt.group(5) else None
                align = 'left' if fmt.group(2) == '-' else 'right'
                width = int(fmt.group(3)) if fmt.group(3) else 'pack'
                if fmt.group(4) == 'F':
                    m = (width, urwid.AttrMap(urwid.Text(flags,
                                                         align=align,
                                                         wrap='clip'),
                                              'note_flags'))
                elif fmt.group(4) == 'D':
                    m = (width, urwid.AttrMap(urwid.Text(mod_time,
                                                         align=align,
                                                         wrap='clip'),
                                              'note_date'))
                elif fmt.group(4) == 'T':
                    m = (width, urwid.AttrMap(urwid.Text(tags,
                                                         align=align,
                                                         wrap='clip'),
                                              'note_tags'))
                elif fmt.group(4) == 'N':
                    if   note_age == 'd': attr = 'note_title_day'
                    elif note_age == 'w': attr = 'note_title_week'
                    elif note_age == 'm': attr = 'note_title_month'
                    elif note_age == 'y': attr = 'note_title_year'
                    elif note_age == 'a': attr = 'note_title_ancient'
                    if width != 'pack':
                        m = (width, urwid.AttrMap(urwid.Text(title,
                                                             align=align,
                                                             wrap='clip'),
                                                  attr))
                    else:
                        m = urwid.AttrMap(urwid.Text(title,
                                                     align=align,
                                                     wrap='clip'),
                                          attr)
                l_fmt = recursive_format(l)
                r_fmt = recursive_format(r)

            tmp = []
            if l_fmt: tmp.extend(l_fmt)
            tmp.append(m)
            if r_fmt: tmp.extend(r_fmt)
            return tmp

        # convert the format string into the actual note title line
        title_line = recursive_format(self.config.get_config('format_note_title'))
        return urwid.Columns(title_line)
Exemple #7
0
    def get_status_bar(self):
        if not self.key:
            return \
                urwid.AttrMap(urwid.Text(u'No note...'),
                              'status_bar')

        cur = -1
        total = 0
        if len(self.body.positions()) > 0:
            cur = self.focus_position
            total = len(self.body.positions())

        if self.old_note:
            t = time.localtime(float(self.old_note['versiondate']))
            title = utils.get_note_title(self.old_note)
            version = self.old_note['version']
        else:
            t = time.localtime(float(self.note['modifydate']))
            title = utils.get_note_title(self.note)
            flags = utils.get_note_flags(self.note)
            tags = utils.get_note_tags(self.note)
            version = self.note['version']

        mod_time = time.strftime(u'Date: %a, %d %b %Y %H:%M:%S', t)

        status_title = \
            urwid.AttrMap(urwid.Text(u'Title: ' +
                                     title,
                                     wrap='clip'),
                          'status_bar')

        status_key_index = \
            ('pack', urwid.AttrMap(urwid.Text(u' [' +
                                              self.key +
                                              u'] ' +
                                              str(cur + 1) +
                                              u'/' +
                                              str(total)),
                                   'status_bar'))

        status_date = \
            urwid.AttrMap(urwid.Text(mod_time,
                                     wrap='clip'),
                          'status_bar')

        if self.old_note:
            status_tags_flags = \
                ('pack', urwid.AttrMap(urwid.Text(u'[OLD:v' +
                                                  str(version) +
                                                  u']'),
                                       'status_bar'))
        else:
            status_tags_flags = \
                ('pack', urwid.AttrMap(urwid.Text(u'[' +
                                                  tags +
                                                  u'] [v' +
                                                  str(version) +
                                                  u'] [' +
                                                  flags +
                                                  u']'),
                                       'status_bar'))

        pile_top = urwid.Columns([status_title, status_key_index])
        pile_bottom = urwid.Columns([status_date, status_tags_flags])

        if self.old_note or \
           not (utils.note_published(self.note) and 'publishkey' in self.note):
            return urwid.AttrMap(urwid.Pile([pile_top, pile_bottom]),
                                 'status_bar')

        pile_publish = \
            urwid.AttrMap(urwid.Text(u'Published: http://simp.ly/publish/' +
                                     self.note['publishkey']),
                          'status_bar')
        return \
            urwid.AttrMap(urwid.Pile([ pile_top, pile_bottom, pile_publish ]),
                          'status_bar')
Exemple #8
0
    def get_status_bar(self):
        if not self.key:
            return \
                urwid.AttrMap(urwid.Text(u'No note...'),
                              'status_bar')

        cur   = -1
        total = 0
        if len(self.body.positions()) > 0:
            cur   = self.focus_position
            total = len(self.body.positions())

        if self.old_note:
            t = time.localtime(float(self.old_note['versiondate']))
            title    = utils.get_note_title(self.old_note)
            version  = self.old_note['version']
        else:
            t = time.localtime(float(self.note['modifydate']))
            title    = utils.get_note_title(self.note)
            flags    = utils.get_note_flags(self.note)
            tags     = utils.get_note_tags(self.note)
            version  = self.note['version']

        mod_time = time.strftime(u'Date: %a, %d %b %Y %H:%M:%S', t)

        status_title = \
            urwid.AttrMap(urwid.Text(u'Title: ' +
                                     title,
                                     wrap='clip'),
                          'status_bar')

        status_key_index = \
            ('pack', urwid.AttrMap(urwid.Text(u' [' + 
                                              self.key + 
                                              u'] ' +
                                              str(cur + 1) +
                                              u'/' +
                                              str(total)),
                                   'status_bar'))

        status_date = \
            urwid.AttrMap(urwid.Text(mod_time,
                                     wrap='clip'),
                          'status_bar')

        if self.old_note:
            status_tags_flags = \
                ('pack', urwid.AttrMap(urwid.Text(u'[OLD:v' + 
                                                  str(version) + 
                                                  u']'),
                                       'status_bar'))
        else:
            status_tags_flags = \
                ('pack', urwid.AttrMap(urwid.Text(u'[' + 
                                                  tags + 
                                                  u'] [v' + 
                                                  str(version) + 
                                                  u'] [' + 
                                                  flags + 
                                                  u']'),
                                       'status_bar'))

        pile_top = urwid.Columns([ status_title, status_key_index ])
        pile_bottom = urwid.Columns([ status_date, status_tags_flags ])

        if self.old_note or \
           not (utils.note_published(self.note) and 'publishkey' in self.note):
            return urwid.AttrMap(urwid.Pile([ pile_top, pile_bottom ]),
                                 'status_bar')

        pile_publish = \
            urwid.AttrMap(urwid.Text(u'Published: http://simp.ly/publish/' +
                                     self.note['publishkey']),
                          'status_bar')
        return \
            urwid.AttrMap(urwid.Pile([ pile_top, pile_bottom, pile_publish ]),
                          'status_bar')