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
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
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)
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
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)
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))
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)
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
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
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
def get_lexer_tasklist(text): fd = six.StringIO() fd.write(text) iofd = iostream.FileDescriptor(fd) lexer = lexers.TaskList(iofd) return lexer