def add_todo(args): """Add a new item to the list of things todo.""" if str(args) == args: line = args elif len(args) >= 1: line = concat(args, " ") else: line = prompt("Add:") prepend = CONFIG["PRE_DATE"] l = len([1 for l in iter_todos()]) + 1 pri_re = re.compile('(\([A-X]\))') if pri_re.match(line) and prepend: line = pri_re.sub( concat(["\g<1>", datetime.now().strftime(" %Y-%m-%d ")]), line) elif prepend: line = concat([datetime.now().strftime("%Y-%m-%d "), line]) with open(CONFIG["TODO_FILE"], "a") as fd: fd.write(concat([line, "\n"])) s = "TODO: '{0}' added on line {1}.".format(line, l) print(s) if CONFIG["USE_GIT"]: _git_commit([CONFIG["TODO_FILE"]], s) return l
def add_todo(args): """Add a new item to the list of things todo.""" if str(args) == args: line = args elif len(args) >= 1: line = concat(args, " ") else: line = prompt("Add:") prepend = CONFIG["PRE_DATE"] l = len([1 for l in iter_todos()]) + 1 pri_re = re.compile("(\([A-X]\))") if pri_re.match(line) and prepend: line = pri_re.sub(concat(["\g<1>", datetime.now().strftime(" %Y-%m-%d ")]), line) elif prepend: line = concat([datetime.now().strftime("%Y-%m-%d "), line]) with open(CONFIG["TODO_FILE"], "a") as fd: fd.write(concat([line, "\n"])) s = "TODO: '{0}' added on line {1}.".format(line, l) print(s) if CONFIG["USE_GIT"]: _git_commit([CONFIG["TODO_FILE"]], s) return l
def assert_nopri(self, lines): # This should check to make sure the function removes the priorities # from the beginning of the lines (formatted or otherwise). self.assertIsInstance(lines, dict) keys = list(lines.keys()) keys.sort() self.assertEqual(todo.concat(keys), todo.PRIORITIES) color_dict = self._generate_re_dictionary(True) for k, v in lines.items(): for line in v: self.assertIsNotNone(color_dict[k].match(line), todo.concat([k, line], " "))
def _test_lines_context(self, num): projects = ["@foo", "@bar", "@bogus", "@github", "@school", "@work", "@inthemorning", "@agenda", "@noagenda"] n = len(projects) l = self._test_lines_pri(num) m = [] for i in range(0, num): m.append(todo.concat([l[i], projects[i % n]], " ")) return m
def _test_lines_project(self, num): projects = ["+foo", "+bar", "+bogus", "+github", "+school", "+work", "+inthemorning", "+agenda", "+noagenda"] n = len(projects) l = self._test_lines_pri(num) m = [] for i in range(0, num): m.append(todo.concat([l[i], projects[i % n]], " ")) return m
def _test_lines_date(self, num): l = self._test_lines_pri(num) m = [] start_date = datetime.date.today() for d, l in zip((start_date + datetime.timedelta(n) for n in range(num)), l): m.append(todo.concat([l, " #{%s}" % d.isoformat()])) return m
def assert_formatted(self, lines): # This needs to check that the string starts with the proper code (i.e. # todo.TERM_COLORS["red"] and terminates with # todo.TERM_COLORS["default"]\n for the proper colors based on priority # also checks that the return value is a dictionary. self.assertIsInstance(lines, dict) keys = list(lines.keys()) keys.sort() self.assertEqual(todo.concat(keys), todo.PRIORITIES) color_dict = self._generate_re_dictionary() for k, v in lines.items(): for line in v: self.assertIsNotNone(color_dict[k].match(line), todo.concat([k, line], " "))
def _test_lines_date(self, num): l = self._test_lines_pri(num) m = [] start_date = datetime.date.today() for d, l in zip( (start_date + datetime.timedelta(n) for n in range(num)), l): m.append(todo.concat([l, " #{%s}" % d.isoformat()])) return m
def _test_lines_context(self, num): projects = [ "@foo", "@bar", "@bogus", "@github", "@school", "@work", "@inthemorning", "@agenda", "@noagenda" ] n = len(projects) l = self._test_lines_pri(num) m = [] for i in range(0, num): m.append(todo.concat([l[i], projects[i % n]], " ")) return m
def _test_lines_project(self, num): projects = [ "+foo", "+bar", "+bogus", "+github", "+school", "+work", "+inthemorning", "+agenda", "+noagenda" ] n = len(projects) l = self._test_lines_pri(num) m = [] for i in range(0, num): m.append(todo.concat([l[i], projects[i % n]], " ")) return m
def rev_list(): """List items in reverse order so for long lists, the most important stuff won't scroll off the top of the screen.""" formatted = format_lines() lines = [] for p in PRIORITIES[::-1]: lines.extend(formatted[p]) if lines: print(concat(lines)[:-1]) print_x_of_y(lines, lines)
def assert_color_only(self, lines): # This needs to check that the return value is only a list of strings # colored by priority. self.assertIsInstance(lines, list) re_dict = self._generate_re_dictionary() priority = re.compile(".*\(([A-X])\).*") for line in lines: line = line.strip() p = priority.sub("\g<1>", line) self.assertIsNotNone(re_dict[p].match(line), todo.concat([p, line], " "))
import re, datetime from todo import usage, iter_todos, CONFIG, concat, _git_commit from todo import format_lines, PRIORITIES, prioritize_todo, print_x_of_y @usage('\tadd | a "Item to do +project @context #{yyyy-mm-dd}"', concat([ "\t\tAdds 'Item to do +project @context #{yyyy-mm-dd}'", "to your todo.txt" ], ' '), "\t\tfile.", "\t\t+project, @context, #{yyyy-mm-dd} are optional\n") def add_todo(args): """Add a new item to the list of things todo.""" if str(args) == args: line = args elif len(args) >= 1: line = concat(args, " ") else: line = prompt("Add:") prepend = CONFIG["PRE_DATE"] l = len([1 for l in iter_todos()]) + 1 pri_re = re.compile('(\([A-X]\))') if pri_re.match(line) and prepend: line = pri_re.sub( concat(["\g<1>", datetime.now().strftime(" %Y-%m-%d ")]), line) elif prepend: line = concat([datetime.now().strftime("%Y-%m-%d "), line]) with open(CONFIG["TODO_FILE"], "a") as fd:
import re, datetime from todo import usage, iter_todos, CONFIG, concat, _git_commit from todo import format_lines, PRIORITIES, prioritize_todo, print_x_of_y @usage( '\tadd | a "Item to do +project @context #{yyyy-mm-dd}"', concat(["\t\tAdds 'Item to do +project @context #{yyyy-mm-dd}'", "to your todo.txt"], " "), "\t\tfile.", "\t\t+project, @context, #{yyyy-mm-dd} are optional\n", ) def add_todo(args): """Add a new item to the list of things todo.""" if str(args) == args: line = args elif len(args) >= 1: line = concat(args, " ") else: line = prompt("Add:") prepend = CONFIG["PRE_DATE"] l = len([1 for l in iter_todos()]) + 1 pri_re = re.compile("(\([A-X]\))") if pri_re.match(line) and prepend: line = pri_re.sub(concat(["\g<1>", datetime.now().strftime(" %Y-%m-%d ")]), line) elif prepend: line = concat([datetime.now().strftime("%Y-%m-%d "), line]) with open(CONFIG["TODO_FILE"], "a") as fd: fd.write(concat([line, "\n"]))