How to use the todoman.formatters.DefaultFormatter function in todoman

To help you get started, we’ve selected a few todoman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / todoman / todoman / cli.py View on Github external
def callback(click_ctx, color, porcelain, humanize):
        ctx = click_ctx.ensure_object(AppContext)

        if porcelain and humanize:
            raise click.ClickException('--porcelain and --humanize cannot be used'
                                       ' at the same time.')

        if humanize is None:  # False means explicitly disabled
            humanize = ctx.config['main']['humanize']

        if humanize:
            ctx.formatter_class = formatters.HumanizedFormatter
        elif porcelain:
            ctx.formatter_class = formatters.PorcelainFormatter
        else:
            ctx.formatter_class = formatters.DefaultFormatter

        color = color or ctx.config['main']['color']
        if color == 'always':
            click_ctx.color = True
        elif color == 'never':
            click_ctx.color = False

        paths = [
            path for path in glob.iglob(expanduser(ctx.config["main"]["path"]))
            if isdir(path)
        ]
        if len(paths) == 0:
            raise exceptions.NoListsFound(ctx.config["main"]["path"])

        ctx.db = Database(paths, ctx.config['main']['cache_path'])
github pimutils / todoman / todoman / formatters.py View on Github external
class HumanizedFormatter(DefaultFormatter):

    def format_datetime(self, dt):
        if not dt:
            return ''

        rv = humanize.naturaltime(self.now - dt)
        if ' from now' in rv:
            rv = 'in {}'.format(rv[:-9])

        return rv


class PorcelainFormatter(DefaultFormatter):

    def _todo_as_dict(self, todo):
        return {
            'completed': todo.is_completed,
            'due': self.format_datetime(todo.due),
            'id': todo.id,
            'list': todo.list.name,
            'percent': todo.percent_complete,
            'summary': todo.summary,
            'priority': todo.priority,
        }

    def compact(self, todo):
        return json.dumps(self._todo_as_dict(todo), indent=4, sort_keys=True)

    def compact_multiple(self, todos):
github pimutils / todoman / todoman / cli.py View on Github external
def ui_formatter(self):
        return formatters.DefaultFormatter(
            self.config['main']['date_format'],
            self.config['main']['time_format'],
            self.config['main']['dt_separator']
        )
github pimutils / todoman / todoman / formatters.py View on Github external
datetime.datetime.strptime(dt, self.time_format).time()
            )
        except ValueError:
            pass

        rv, pd_ctx = self._parsedatetime_calendar.parse(dt)
        if not pd_ctx.hasDateOrTime:
            raise ValueError('Time description not recognized: {}' .format(dt))
        return datetime.datetime.fromtimestamp(mktime(rv))

    def format_database(self, database):
        return '{}@{}'.format(database.color_ansi or '',
                              click.style(database.name))


class HumanizedFormatter(DefaultFormatter):

    def format_datetime(self, dt):
        if not dt:
            return ''

        rv = humanize.naturaltime(self.now - dt)
        if ' from now' in rv:
            rv = 'in {}'.format(rv[:-9])

        return rv


class PorcelainFormatter(DefaultFormatter):

    def _todo_as_dict(self, todo):
        return {