Exemplo n.º 1
0
    def _get_mtaskfile_ast(self, filepath):
        if not os.path.isfile(filepath):
            return asttree.AbstractSyntaxTree()

        with open(filepath, 'r') as fd_src:
            fd = iostream.FileDescriptor(fd_src)
            AST = parsers.parse(fd, 'mtask')
        return AST
Exemplo n.º 2
0
        def tasklist_data(self, filecontents):
            with mock.patch('{}.uuid.uuid4'.format(ns), side_effect=uid):
                # initialize TaskList()
                fd = six.StringIO()
                fd.write(filecontents)
                iofd = iostream.FileDescriptor(fd)
                lexer = lexers.TaskList(iofd)

                # read until end of TaskList
                lexer.read()
                return lexer.data
Exemplo n.º 3
0
    def ex_tasklist():
        print('========')
        print('Tasklist')
        print('========')
        print()

        with open('{}/examples/example.tasklist'.format(dirname), 'rb') as fd:
            lexer = lexers.TaskList(iostream.FileDescriptor(fd))
            parser_ = parser.Parser(lexer)
            renderer = TaskList(parser_)
            for line in renderer.render():
                print(line)
Exemplo n.º 4
0
def handle_open_mtask():
    """ converts buffer from Mtask(JSON) to TaskList(rst)
    """
    # reading directly off disk is MUCH faster
    with open(vim.current.buffer.name, 'r') as fd_py:
        fd = iostream.FileDescriptor(fd_py)
        ast = parsers.parse(fd, 'mtask')
        render = ast.render(renderers.TaskList)

    vim.current.buffer[:] = render
    vim.command('call taskmage#searchbuffer#pop_and_run_postcmds()')
    vim.command('set filetype=taskmage')
    return render
Exemplo n.º 5
0
def get_filedescriptor(contents):
    """

    Args:
        contents (str):
            A string representing a file in it's entirety.

            .. code-block:: python

                'line_1\nline_2\n'
    """
    fd = six.moves.StringIO(contents)
    return iostream.FileDescriptor(fd)
Exemplo n.º 6
0
 def ex_tasklist():
     print('========')
     print('Tasklist')
     print('========')
     print()
     with open('{}/examples/sample_tasks.tasklist'.format(dirname),
               'rb') as fd:
         lexer = lexers.TaskList(iostream.FileDescriptor(fd))
         parser = Parser(lexer)
         ast = parser.parse()
         print(ast.data)
         print()
         print(ast.render(renderers.TaskList))
Exemplo n.º 7
0
    def ex_tasklist():
        print('\n' '========\n' 'TaskList\n' '========\n')

        _scriptdir = os.path.abspath(os.path.dirname(__file__))
        path = os.path.abspath(
            '{}/../../../examples/sample_tasks.tasklist'.format(_scriptdir))
        with open(path, 'rb') as fd:
            lexer = TaskList(iostream.FileDescriptor(fd))

            token = ''
            while token is not None:
                token = lexer.read_next()
                print(token)
Exemplo n.º 8
0
        def tasklist(self, filecontents):
            """ Initializes a TaskList(), returns the lexed contents as a list.
            """
            with mock.patch('{}.uuid.uuid4'.format(ns), side_effect=uid):
                # initialize TaskList()
                fd = six.StringIO()
                fd.write(filecontents)
                iofd = iostream.FileDescriptor(fd)
                lexer = lexers.TaskList(iofd)

                # read until end of TaskList
                _lexertokens = []
                token = ''
                while token is not None:
                    token = lexer.read_next()
                    if token is not None:
                        _lexertokens.append(token)

                return _lexertokens
Exemplo n.º 9
0
def archive_completed_tasks():
    """ saves current buffer, then archives all entirely-complete task-branches
    within the tree.
    """
    # save file, so saved copy is up to date
    vimfile = os.path.abspath(vim.current.buffer.name)
    if not os.path.isfile(vimfile):
        raise RuntimeError('cannot archive completed tasks in unsaved file')
    vim.command('w')

    # archive completed tasks on disk
    project = projects.Project.from_path(vimfile)
    project.archive_completed(vimfile)

    # reload from disk
    with open(vimfile, 'r') as fd_py:
        fd = iostream.FileDescriptor(fd_py)
        ast = parsers.parse(fd, 'mtask')
        render = ast.render(renderers.TaskList)

    vim.current.buffer[:] = render
    return render
Exemplo n.º 10
0
def handle_presave_mtask():
    """ converts buffer to Mtask(JSON) before writing to disk.
    Also updates modified time, finished time, etc.
    """

    # convert vim-buffer to Mtask
    fd = iostream.VimBuffer(vim.current.buffer)
    buffer_ast = parsers.parse(fd, 'tasklist')

    # merge overtop of savedfile if exists
    if not os.path.isfile(vim.current.buffer.name):
        buffer_ast.finalize()
        render = buffer_ast.render(renderers.Mtask)
    else:
        with open(vim.current.buffer.name, 'r') as fd_py:
            fd = iostream.FileDescriptor(fd_py)
            saved_ast = parsers.parse(fd, 'mtask')
        saved_ast.update(buffer_ast)
        saved_ast.finalize()
        render = saved_ast.render(renderers.Mtask)

    # replace vim-buffer with updated Mtask render
    vim.current.buffer[:] = render
    return render
Exemplo n.º 11
0
def get_lexer_tasklist(text):
    fd = six.StringIO()
    fd.write(text)
    iofd = iostream.FileDescriptor(fd)
    lexer = lexers.TaskList(iofd)
    return lexer