Example #1
0
File: done.py Project: Zilbuz/yat
    def execute(self, cmd, args):
        if len(args) == 0:
            cli.output(st = u"[ERR] You must provide some informations to the command. See 'yat help done'", 
                    f = sys.stderr,
                    foreground = cli.colors.errf, background = cli.colors.errb,
                    bold = cli.colors.errbold)

        id = None
        regexp = []
        for a in args:
            res = self.re_id.match(a)
            if res != None:
                id = res.group(1)
                break
            regexp.append(a)

        regexp = " ".join(regexp)

        cli.Yat.Task.class_lib = cli.lib
        if id != None:
            tasks = cli.lib.get_tasks(ids=[int(id)])
        else:
            tasks = cli.lib.get_tasks(regexp=regexp)

        done = cmd == u"done"
        for task in tasks:
            task.completed = done
            task.save()
Example #2
0
File: show.py Project: Zilbuz/yat
 def group_print(group):
     tasks = cli.lib.get_tasks(group=group)
     n_tasks = len(tasks)
     n_completed = 0
     for t in tasks:
         n_completed += t.completed
     cli.output(u"\t- " + group.content + u" (id: " +
                 str(group.id) + u") - " +
                 str( n_completed) + u"/" + str(n_tasks))
Example #3
0
File: show.py Project: Zilbuz/yat
    def execute(self, cmd, args):

        # Parse the options of the command
        for a in args:
            res = re.match("^(--show-completed|-a)$", a)
            if res != None:
                self.show_completed = True
        self.check_contextual = True    # Until an option is implemented

        # Testing the alias used to call ListCommand
        if cmd in [u'show', u'ls', u'tasks']:
            # Width of the done column
            done_width = 0
            if self.show_completed:
                done_width = 2

            # 38 is an arbitrary value that seems to work well...
            if self.width < (38 + self.datewidth + done_width) :
                cli.output("The terminal is too small to print the list correctly")
                return
            else:
                allowable = self.width - (20 + self.datewidth + done_width)
                self.tagswidth = allowable/4
                self.textwidth = allowable - self.tagswidth

            tasks = cli.lib.get_tasks()
            if cli.lib.config["cli.display_group"] ==  u'list':
                to_display = [cli.Yat.Tree(li) for li in cli.lib.get_loaded_lists()]
            else:
                to_display = [cli.Yat.Tree(li) for li in cli.lib.get_loaded_tags()]
            criteria = []
            for o in cli.lib.config['cli.task_ordering']:
                tmp = o.split(':')
                if len(tmp) == 2:
                    criteria.append((tmp[1], True))
                else:
                    criteria.append((tmp[0], False))
            cli.Yat.Tree.sort_trees(to_display, criteria)

        elif cmd in [u'lists', u'tags'] :
            c = cli.lib.config["cli.color_group_name"]
            cli.output(u"<" + cmd[0:-1] + u" name> (id: <id>) - <tasks completed>/<tasks>:", 
                    foreground = c[0], background = c[1], bold = c[2])
            
            if cmd == u'lists':
                groups = set(cli.lib.get_lists())
            else:
                groups = set(cli.lib.get_tags())

            to_display = groups

        self.__load_display(cmd in [u'lists', u'tags'])
        for item in to_display:
            item.display()
Example #4
0
File: show.py Project: Zilbuz/yat
        def task_tree_display(task, rec_arguments, contextual):
            if (not self.show_completed) and task.completed == 1:
                raise InterruptDisplay()

            if rec_arguments == None:
                arguments = {
                        'prefix':'',
                        'print_sep': True,
                        }
            else:
                arguments = rec_arguments.copy()
                arguments['print_sep'] = False

            # Split task text
            st = self.__split_text(task.content, self.textwidth -
                                   len(arguments['prefix']))

            # Prepare and split tags
            tags = ", ".join([t.content for t in task.tags])
            tags = self.__split_text(tags, self.tagswidth)

            # Print the first line of the current task
            done_column = ""
            if self.show_completed:
                if task.completed == 1:
                    done_column = "|X"
                else:
                    done_column = "| "

            # Format the date column
            date_column = cli.parse_output_date(task.due_date)

            # Select color
            color_name = "cli.color_default"
            if self.check_contextual and contextual:
                color_name = "cli.color_contextual" 
            elif task.due_date < cli.lib.get_time():
                color_name = "cli.color_tasks_late"
            else:
                color_name = "cli.color_priority" + str(task.priority)
            c = cli.lib.config[color_name]

            cli.output(u"{done}|{p:^9}|{date:^{datewidth}}|{id:^3}| {pref:^{pref_width}}{task:<{textwidth}}|{tags:{tagswidth}}|".format(
                done = done_column, p = task.priority, date = date_column, id = task.id, 
                pref = arguments['prefix'], pref_width = len(arguments['prefix']),
                task = st.pop(0), textwidth = self.textwidth - len(arguments['prefix']), 
                tags = tags.pop(0), tagswidth = self.tagswidth, 
                datewidth = self.datewidth),
                foreground = c[0], background = c[1], bold = c[2])

            # Blanking the prefix
            blank_prefix = ""
            for i in range(len(arguments['prefix'])):
                blank_prefix = blank_prefix + " "

            # Print the rest of the current task
            for i in range(max(len(st),len(tags))):
                if i < len(st):
                    te = st[i]
                else:
                    te = u""
                if i < len(tags):
                    ta = tags[i]
                else:
                    ta = u""
                cli.output(u"{done}|         |{t: <{datewidth}}|   | {pref:^{pref_width}}{task:<{textwidth}}|{tags:{tagswidth}}|".format(
                    done = done_column_middle, task = te, textwidth = self.textwidth - len(blank_prefix),
                    tags=ta, pref = blank_prefix, pref_width = len(blank_prefix),
                    tagswidth = self.tagswidth, t = " ", 
                    datewidth = self.datewidth),
                    foreground = c[0], background = c[1], bold = c[2])

            # Print the nodes of the root
            arguments['prefix'] = blank_prefix + "* "
            return arguments
Example #5
0
File: show.py Project: Zilbuz/yat
 def task_display_callback(task, rec_arguments = None):
     if rec_arguments == None or rec_arguments["print_sep"]:
         # Print the separator
         cli.output(u" {done}----------{t:-<{datewidth}}------{t:-<{textwidth}}-{t:-<{tagswidth}} ".format( 
             done = done_column_bottom, t="-", textwidth=self.textwidth,
             tagswidth=self.tagswidth, datewidth = self.datewidth))
Example #6
0
File: show.py Project: Zilbuz/yat
        def group_tree_display(group, recursion_arguments, contextual):
            u"""Print the tasks. The parameter tasks have to be complete rows of
            the tasks table."""
            cli.output()
            text_group = group.group_header()
            c = cli.lib.config["cli.color_group_name"]
            cli.output(text_group, foreground = c[0], background = c[1], bold =
                    c[2])
            length = len(text_group)
            cli.output(u"{s:*<{lgth}}".format(s = "*", 
                lgth = length))

            # Print header, depending on show_completed
            c = cli.lib.config["cli.color_header"]
            cli.output(u" {done}__________{t:_<{datewidth}}______{t:_<{textwidth}}_{t:_<{tagswidth}} ".format( 
                done=done_column_top, t="_", textwidth=self.textwidth,
                tagswidth=self.tagswidth, datewidth=self.datewidth), 
                foreground = c[0], background = c[1], bold = c[2])
            cli.output(u"{done}|Priority |{date:^{datewidth}}| Id| {task:<{textwidth}}|{tags:<{tagswidth}}|".format(
                done=done_column_middle, date = "Due date", datewidth = self.datewidth, 
                task = "Task", textwidth = self.textwidth, tags = " Tags",
                tagswidth = self.tagswidth),
                foreground = c[0], background = c[1], bold = c[2])
            cli.output(u" {done}----------{t:-<{datewidth}}------{t:-<{textwidth}}-{t:-<{tagswidth}} ".format( 
                done=done_column_bottom, t="-", textwidth=self.textwidth,
                tagswidth=self.tagswidth, datewidth=self.datewidth),
                foreground = c[0], background = c[1], bold = c[2])
Example #7
0
File: add.py Project: Zilbuz/yat
    def execute(self, cmd, args):
        cmd = ""
        if args[0] in ["task", "list", "tag"]:
            cmd = args[0]
            args = args[1:]

        # If there is no more arguments, return immediately
        if len(args) == 0:
            return

        # Process command
        if cmd in ["tag", "list"]:
            if cmd == "tag":
                group = cli.Yat.Tag(cli.lib)
            elif cmd == "list":
                group = cli.Yat.List(cli.lib)
            group.content = args[0]
            if len(args) > 1:
                # The second argument is the priority
                group.priority = int(args[1])
            else:
                group.priority = 0

            group.save(cli.lib)

            pass
        else: # Adding a task
            # Init params
            new_task = cli.Yat.Task(cli.lib)
            tag_names = []
            text = []

            # Look for symbols
            for a in args:
                # Priority
                res = self.re_priority.match(a)
                if res != None:
                    new_task.priority = int(res.group(1))
                    continue
                # Tags
                res = self.re_tag.match(a)
                if res != None:
                    tag_names.append(res.group(1))
                    continue
                # List
                res = self.re_list.match(a)
                if res != None:
                    try:
                        new_task.list = cli.lib.get_list(res.group(1))
                    except:
                        new_task.list = cli.Yat.List(cli.lib)
                        new_task.list.content = res.group(1)
                    continue
                # Parent task
                res = self.re_parent.match(a)
                if res != None:
                    new_task.parent = cli.lib.get_task(int(res.group(1)))
                    continue
                # Date
                res = self.re_date.match(a)
                if res != None:
                    try:
                        new_task.due_date = cli.parse_input_date(res)
                    except ValueError:
                        cli.output("[ERR] The due date isn't well formed. See 'yat help add'.", 
                                f = sys.stderr,
                                foreground = cli.colors.errf, background = 
                                cli.colors.errb, bold = cli.colors.errbold)
                        return
                    continue
                # Regular text
                text.append(a)

            new_task.content = " ".join(text)
            new_task.tags = set()
            for n in tag_names:
                try:
                    new_task.tags.add(cli.lib.get_tag(n, False))
                except:
                    new_tag = cli.Yat.Tag(cli.lib)
                    new_tag.content = n
                    new_task.tags.add(new_tag)
            new_task.save(cli.lib)
Example #8
0
File: help.py Project: Zilbuz/yat
    def execute(self, cmd, args):
        detailed = False
        cmd = self

        if len(args) > 0:
            if args[0] in cli.aliases:
                cmd = cli.aliases[args[0]]()
                detailed = True

        helptxt = cmd.__doc__.split('\n\n', 1)

        if detailed:
            cli.output(helptxt[1].format(name = cli.name))

        if cmd.alias[0] == u"help":
            if not detailed:
                cli.output(
                u"""{name} (Yet Another Todolist) is a very simple commandline todolist manager.

usage: {name} [options] [command] [arguments]

options:
    --help, -h
        Print this help and exit.
    --config-file FILE, -c FILE
        Use FILE as a configuration file.
    --version, -v
        Print the current version of yat and exit.

The different commands are:""".format(name = cli.name))

            # Extract docstrings from command classes
            help_txts = []
            for name, cmd in cli.commands.iteritems():
                txt = u"\t" + cmd.alias[0]
                txt += u"\t" + cmd.__doc__.split('\n', 1)[0]
                if len(cmd.alias) > 1:
                    txt += u" (alias: "
                    for i in range(1, len(cmd.alias)):
                        txt += cmd.alias[i]
                        if i < len(cmd.alias) - 1:
                            txt += u", "
                    txt += u")"
                help_txts.append(txt)

            # Sort the docstrings
            help_txts.sort()

            # Print them
            for t in help_txts:
                cli.output(t)

            cli.output()
            cli.output(u"If no command are provided, the 'show' command is assumed.")
            cli.output(u"Please type \"%s help [command]\" to have" %
                    cli.name, linebreak = False)
            cli.output(u" detailed informations on a specific command.")

        cli.output()
        pass
Example #9
0
File: edit.py Project: Zilbuz/yat
    def execute(self, cmd, args):

        if len(args) == 0:
            cli.output(st = u"[ERR] You must provide some arguments to edit an element. See 'yat help edit'.", 
                    f = sys.stderr,
                    foreground = cli.colors.errf, background = cli.colors.errb,
                    bold = cli.colors.errbold)
            return

        if args[0] in [u"task", u"list", u"tag"]:
            element = args[0]
            args = args[1:]
        else:
            element = u"task"

        to_edit = None

        task = None
        cli.Yat.Task.class_lib = cli.lib
        for a in args:
            res = self.re_id.match(a)
            if to_edit == None and res != None:
                if element == u'task':
                    to_edit = cli.lib.get_task(res.group(1))
                elif element == u'tag':
                    to_edit = cli.lib.get_tag(res.group(1))
                elif element == u'list':
                    to_edit = cli.lib.get_list(res.group(1))
                continue

            if element in [u"list", u"tag"]:
                res = self.re_tol_priority.match(a)
            else:
                res = self.re_priority.match(a)
            if res != None:
                to_edit.priority = int(res.group(1))
                continue

            if element in [u"list", u"tag"]:
                res = self.re_tol_name.match(a)
                if res != None:
                    to_edit.content = res.group(1)
                    continue

            res = self.re_due_date.match(a)
            if res != None:
                try:
                    to_edit.due_date = cli.parse_input_date(res)
                except ValueError:
                    cli.output("[ERR] The due date isn't well formed. See 'yat help edit'.", 
                            f = sys.stderr,
                            foreground = cli.colors.errf, background =
                            cli.colors.errb, bold = cli.colors.errbold)
                    return
                continue

            res = self.re_parent.match(a)
            if res != None:
                to_edit.parent = cli.Yat.Task.get_task(res.group(1))
                continue

            res = self.re_list.match(a)
            if res != None:
                try:
                    to_edit.list = cli.lib.get_list(res.group(1), False) 
                except:
                    to_edit.list = cli.Yat.List(cli.lib)
                    to_edit.list.content = res.group(1)
                continue

            res = self.re_add_tags.match(a)
            if res != None:
                tag_names = res.group(1).split(',')
                for n in tag_names:
                    try:
                        to_edit.tags.add(cli.lib.get_tag(n, False))
                    except:
                        tag = cli.Yat.Tag(cli.lib)
                        tag.content = n
                        to_edit.tags.add(tag)
                continue

            res = self.re_remove_tags.match(a)
            if res != None:
                to_edit.tags -= set(cli.lib.get_tags(names=res.group(1).split(',')))
                continue

            res = self.re_name.match(a)
            if task == None and res != None:
                task = [res.group(1)]
                continue

            if task != None:
                task.append(a)

        if task != None:
            task = " ".join(task)
            if element == 'task': 
                to_edit.content = task
        to_edit.save()