コード例 #1
0
    def execute(self):
        if not super().execute():
            return False

        self._backup = ChangeSet()
        archive_path = config().archive()
        if archive_path:
            self._archive_file = TodoFile.TodoFile(config().archive())
            self._archive = TodoList.TodoList(self._archive_file.read())

        if len(self.args) > 1:
            self.error(self.usage())
        else:
            try:
                arg = self.argument(0)
                self._handle_args(arg)
            except InvalidCommandArgument:
                try:
                    self._revert_last()
                except (ValueError, KeyError):
                    self.error(
                        'No backup was found for the current state of ' +
                        config().todotxt())

        self._backup.close()
コード例 #2
0
ファイル: todo_export.py プロジェクト: fossabot/prjct
def project_list(todo_cfg=None):
    """
    Provide a full (Python) list of all projects.

    Takes our todo list and our done list, and returns a (Python) list of all
    projects found.
    """
    todofile = TodoFile.TodoFile(topydo_config(todo_cfg).todotxt())
    # print('Loaded todo file from {}'.format(todofile.path))
    todotodos = TodoList.TodoList(todofile.read())
    todo_projects = todotodos.projects()

    donefile = TodoFile.TodoFile(topydo_config(todo_cfg).archive())
    # print('Loaded done file from {}'.format(donefile.path))
    donetodos = TodoList.TodoList(donefile.read())
    done_projects = donetodos.projects()

    # operator called 'join' and gives the union of the two sets
    all_projects_list = list(todo_projects | done_projects)
    return sort_project_list(all_projects_list)
コード例 #3
0
ファイル: CLI.py プロジェクト: netimen/topydo
    def run(self):
        """ Main entry function. """
        args = self._process_flags()

        self.todofile = TodoFile.TodoFile(config().todotxt())
        self.todolist = TodoList.TodoList(self.todofile.read())

        (subcommand, args) = get_subcommand(args)

        if subcommand == None:
            self._usage()

        if self._execute(subcommand, args) == False:
            sys.exit(1)
        else:
            self._post_execute()
コード例 #4
0
    def _load_file(self):
        """
        Reads the configured todo.txt file and loads it into the todo list
        instance.

        If the modification time of the todo.txt file is equal to the last time
        it was checked, nothing will be done.
        """

        current_mtime = _todotxt_mtime()

        if not self.todofile or self.mtime != current_mtime:
            self.todofile = TodoFile.TodoFile(config().todotxt())
            self.todolist = TodoList.TodoList(self.todofile.read())
            self.mtime = current_mtime

            # suppress upstream issue with Python 2.7
            # pylint: disable=no-value-for-parameter
            self.completer = TopydoCompleter(self.todolist)
コード例 #5
0
ファイル: CLI.py プロジェクト: kevinheader/topydo
    def run(self):
        """ Main entry function. """
        args = self._process_flags()

        self.todofile = TodoFile.TodoFile(config().todotxt())
        self.todolist = TodoList.TodoList(self.todofile.read())

        try:
            (subcommand, args) = get_subcommand(args)
        except ConfigError as ce:
            error('Error: ' + str(ce) + '. Check your aliases configuration')
            sys.exit(1)

        if subcommand is None:
            self._usage()

        if self._execute(subcommand, args) == False:
            sys.exit(1)
        else:
            self._post_execute()
コード例 #6
0
ファイル: RevertCommand.py プロジェクト: kevinheader/topydo
    def execute(self):
        if not super().execute():
            return False

        archive_file = TodoFile.TodoFile(config().archive())
        archive = TodoList.TodoList(archive_file.read())

        last_change = ChangeSet()

        try:
            last_change.get_backup(self.todolist)
            last_change.apply(self.todolist, archive)
            archive_file.write(archive.print_todos())
            last_change.delete()

            self.out("Successfully reverted: " + last_change.label)
        except (ValueError, KeyError):
            self.error('No backup was found for the current state of ' +
                       config().todotxt())

        last_change.close()
コード例 #7
0
 def __init__(self):
     self.todolist = TodoList.TodoList([])
     self.todofile = None
     self.do_archive = True
     self._post_archive_action = None
     self.backup = None
コード例 #8
0
 def setUp(self):
     super(AddCommandTest, self).setUp()
     self.todolist = TodoList.TodoList([])
     self.today = date.today().isoformat()
コード例 #9
0
 def setUp(self):
     super().setUp()
     self.todolist = TodoList.TodoList([])
     self.today = date.today().isoformat()
コード例 #10
0
    def __init__(self):
        super().__init__()

        args = self._process_flags()

        try:
            opts, args = getopt.getopt(args[1:], 'l:')
        except getopt.GetoptError as e:
            error(str(e))
            sys.exit(1)

        self.alt_layout_path = None

        for opt, value in opts:
            if opt == "-l":
                self.alt_layout_path = value

        def callback():
            self.todolist.erase()
            self.todolist.add_list(self.todofile.read())
            self._update_all_columns()
            self._redraw()

        self.column_width = config().column_width()
        self.todofile = TodoFileWatched(config().todotxt(), callback)
        self.todolist = TodoList.TodoList(self.todofile.read())

        self.marked_todos = set()

        self.columns = urwid.Columns([],
                                     dividechars=0,
                                     min_width=config().column_width())
        self.columns.contents.set_focus_changed_callback(self._move_highlight)
        completer = ColumnCompleter(self.todolist)
        self.commandline = CommandLineWidget(completer, 'topydo> ')
        self.keystate_widget = KeystateWidget()
        self.status_line = urwid.Columns([
            ('weight', 1, urwid.Filler(self.commandline)),
        ])
        self.cli_wrapper = CliWrapper([(1, self.status_line)])

        self.keymap = config().column_keymap()
        self._alarm = None

        self._last_cmd = None

        # console widget
        self.console = ConsoleWidget()
        get_terminal_size(self._console_width)

        urwid.connect_signal(self.commandline, 'blur', self._blur_commandline)
        urwid.connect_signal(self.commandline, 'execute_command',
                             self._execute_handler)
        urwid.connect_signal(self.commandline, 'show_completions',
                             self._show_completion_box)
        urwid.connect_signal(self.commandline, 'hide_completions',
                             self._hide_completion_box)

        def hide_console(p_focus_commandline=False):
            if p_focus_commandline:
                self._focus_commandline()
            else:
                self._console_visible = False

        urwid.connect_signal(self.console, 'close', hide_console)

        # view widget
        self.viewwidget = ViewWidget(self.todolist)

        urwid.connect_signal(self.viewwidget, 'save',
                             lambda: self._update_view(self.viewwidget.data))

        def hide_viewwidget():
            # prevent the view widget to be hidden when the last column was
            # deleted
            if self.columns.contents:
                self._viewwidget_visible = False
                self._blur_commandline()

        urwid.connect_signal(self.viewwidget, 'close', hide_viewwidget)

        self.mainwindow = MainPile([
            ('weight', 1, self.columns),
            ('pack', self.cli_wrapper),
        ])

        urwid.connect_signal(self.mainwindow, 'blur_console', hide_console)

        # the columns should have keyboard focus
        self._blur_commandline()

        self._screen = urwid.raw_display.Screen()

        def create_color_palette():
            project_color = to_urwid_color(config().project_color())
            context_color = to_urwid_color(config().context_color())
            metadata_color = to_urwid_color(config().metadata_color())
            link_color = to_urwid_color(config().link_color())
            focus_background_color = to_urwid_color(
                config().focus_background_color())
            marked_background_color = to_urwid_color(
                config().marked_background_color())

            palette = [
                (PaletteItem.PROJECT, '', '', '', project_color, ''),
                (PaletteItem.PROJECT_FOCUS, '', 'light gray', '',
                 project_color, focus_background_color),
                (PaletteItem.CONTEXT, '', '', '', context_color, ''),
                (PaletteItem.CONTEXT_FOCUS, '', 'light gray', '',
                 context_color, focus_background_color),
                (PaletteItem.METADATA, '', '', '', metadata_color, ''),
                (PaletteItem.METADATA_FOCUS, '', 'light gray', '',
                 metadata_color, focus_background_color),
                (PaletteItem.LINK, '', '', '', link_color, ''),
                (PaletteItem.LINK_FOCUS, '', 'light gray', '', link_color,
                 focus_background_color),
                (PaletteItem.DEFAULT_FOCUS, '', 'light gray', '', '',
                 focus_background_color),
                (PaletteItem.MARKED, '', 'light blue', '', '',
                 marked_background_color),
            ]

            for C in ascii_uppercase:
                pri_color_cfg = config().priority_color(C)

                pri_color = to_urwid_color(pri_color_cfg)
                pri_color_focus = pri_color if not pri_color_cfg.is_neutral(
                ) else 'black'

                palette.append(('pri_' + C, '', '', '', pri_color, ''))
                palette.append(('pri_' + C + '_focus', '', 'light gray', '',
                                pri_color_focus, focus_background_color))

            return palette

        def create_mono_palette():
            palette = [
                (PaletteItem.DEFAULT_FOCUS, 'black', 'light gray'),
                (PaletteItem.PROJECT_FOCUS, PaletteItem.DEFAULT_FOCUS),
                (PaletteItem.CONTEXT_FOCUS, PaletteItem.DEFAULT_FOCUS),
                (PaletteItem.METADATA_FOCUS, PaletteItem.DEFAULT_FOCUS),
                (PaletteItem.LINK_FOCUS, PaletteItem.DEFAULT_FOCUS),
                (PaletteItem.MARKED, 'default,underline,bold', 'default'),
            ]

            for C in ascii_uppercase:
                palette.append(
                    ('pri_' + C + '_focus', PaletteItem.DEFAULT_FOCUS))

            return palette

        if config().colors():
            self._screen.register_palette(create_color_palette())
        else:
            self._screen.register_palette(create_mono_palette())

        self._screen.set_terminal_properties(256)

        self.mainloop = urwid.MainLoop(self.mainwindow,
                                       screen=self._screen,
                                       unhandled_input=self._handle_input,
                                       pop_ups=True)

        self.column_mode = _APPEND_COLUMN
        self._set_alarm_for_next_midnight_update()
コード例 #11
0
ファイル: Main.py プロジェクト: kevinheader/topydo
    def __init__(self):
        super().__init__()

        args = self._process_flags()

        try:
            opts, args = getopt.getopt(args[1:], 'l:')
        except getopt.GetoptError as e:
            error(str(e))
            sys.exit(1)

        self.alt_layout_path = None

        for opt, value in opts:
            if opt == "-l":
                self.alt_layout_path = value

        def callback():
            self.todolist.erase()
            self.todolist.add_list(self.todofile.read())
            self._update_all_columns()
            self._redraw()

        self.column_width = config().column_width()
        self.todofile = TodoFileWatched(config().todotxt(), callback)
        self.todolist = TodoList.TodoList(self.todofile.read())

        self.marked_todos = set()

        self.columns = urwid.Columns([],
                                     dividechars=0,
                                     min_width=config().column_width())
        completer = ColumnCompleter(self.todolist)
        self.commandline = CommandLineWidget(completer, 'topydo> ')
        self.keystate_widget = KeystateWidget()
        self.status_line = urwid.Columns([
            ('weight', 1, urwid.Filler(self.commandline)),
        ])
        self.cli_wrapper = CliWrapper([(1, self.status_line)])

        self.keymap = config().column_keymap()
        self._alarm = None

        self._last_cmd = None

        # console widget
        self.console = ConsoleWidget()
        get_terminal_size(self._console_width)

        urwid.connect_signal(self.commandline, 'blur', self._blur_commandline)
        urwid.connect_signal(self.commandline, 'execute_command',
                             self._execute_handler)
        urwid.connect_signal(self.commandline, 'show_completions',
                             self._show_completion_box)
        urwid.connect_signal(self.commandline, 'hide_completions',
                             self._hide_completion_box)

        def hide_console(p_focus_commandline=False):
            if p_focus_commandline:
                self._focus_commandline()
            else:
                self._console_visible = False

        urwid.connect_signal(self.console, 'close', hide_console)

        # view widget
        self.viewwidget = ViewWidget(self.todolist)

        urwid.connect_signal(self.viewwidget, 'save',
                             lambda: self._update_view(self.viewwidget.data))

        def hide_viewwidget():
            # prevent the view widget to be hidden when the last column was
            # deleted
            if self.columns.contents:
                self._viewwidget_visible = False
                self._blur_commandline()

        urwid.connect_signal(self.viewwidget, 'close', hide_viewwidget)

        self.mainwindow = MainPile([
            ('weight', 1, self.columns),
            ('pack', self.cli_wrapper),
        ])

        urwid.connect_signal(self.mainwindow, 'blur_console', hide_console)

        # the columns should have keyboard focus
        self._blur_commandline()

        self._screen = urwid.raw_display.Screen()

        if config().colors():
            self._screen.register_palette(self._create_color_palette())
        else:
            self._screen.register_palette(self._create_mono_palette())

        self._screen.set_terminal_properties(256)

        self.mainloop = urwid.MainLoop(self.mainwindow,
                                       screen=self._screen,
                                       unhandled_input=self._handle_input,
                                       pop_ups=True)

        self.column_mode = _APPEND_COLUMN
        self._set_alarm_for_next_midnight_update()
コード例 #12
0
ファイル: todo_export.py プロジェクト: fossabot/prjct
def sorted_todos_by_project(cfg, todo_cfg=None):
    """
    Takes our todo list, and returns two dictionaries of where the keys equal
    to the project name, and the value is a list of todo items under that
    project.

    - Note that a todo item may be appended to multiple second level HTML lists
        if the item is listed under multiple projects.
    - Note that todo items without a project are discarded.
    - Note that completed items beyond `completion_cutoff` (measured in days)
        are discarded.

    todo_cfg is called to topydo.config directs as the path of the test
        configuration. Setting this to None will use the normal configuration.
    """
    '''
    print(type(cfg))
    print(cfg)
    print(type(cfg['todo']), cfg['todo'])
    print(type(cfg['todo']['completion_cutoff']), cfg['todo']['completion_cutoff'])
    '''
    completion_range = timestring.Range('last {!s} days'.format(cfg['todo']['completion_cutoff']))

    my_sorter = Sorter(p_sortstring=cfg['todo']['sort_string'])

    todofile = TodoFile.TodoFile(topydo_config(todo_cfg).todotxt())
    # print('Loaded todo file from {}'.format(todofile.path))
    todotodos = TodoList.TodoList(todofile.read())
    # todolist = my_sorter.sort(todolist)            # in topydo v0.10
    # json_str = JsonPrinter().print_list(todolist)  # in topydo v0.10
    todolist = my_sorter.sort(todotodos.todos())    # sort before filters
    # filters return a list, so apply them all at once?
    todolist = HiddenTagFilter().filter(todolist)
    todo_json_str = JsonPrinter().print_list(todolist)
    todo_json = json.loads(todo_json_str)

    donefile = TodoFile.TodoFile(topydo_config(todo_cfg).archive())
    # print('Loaded done file from {}'.format(donefile.path))
    donetodos = TodoList.TodoList(donefile.read())
    donelist = my_sorter.sort(donetodos.todos())
    donelist = HiddenTagFilter().filter(donelist)
    done_json_str = JsonPrinter().print_list(donelist)
    done_json = json.loads(done_json_str)

    active_todos = {}
    completed_todos = {}

    for my_json in [todo_json, done_json]:
        for todo in my_json:
            if not todo['completed']:
                for project in todo['projects']:
                    try:
                        active_todos[project].append(todo['source'])
                    except KeyError:
                        active_todos[project] = [todo['source']]
            else:
                completion_date = timestring.Date(todo['completion_date'])
                if completion_date in completion_range:
                    for project in todo['projects']:
                        try:
                            completed_todos[project].append(todo['source'])
                        except KeyError:
                            completed_todos[project] = [todo['source']]

    return active_todos, completed_todos
コード例 #13
0
ファイル: CLIApplicationBase.py プロジェクト: netimen/topydo
 def __init__(self):
     self.todolist = TodoList.TodoList([])
     self.todofile = None
     self.do_archive = True