def do_t_filter(self, line): """Define permanent keyword filter used by t_list Ex.: - t_filter @work (filter all task that have the "work" keyword) - t_filter none (remove filter)""" # TODO: add completion if not line: raise YokadiException( "You must give keyword as argument or 'none' to reset filter") if parseutils.simplifySpaces(line).lower() == "none": self.kFilters = [] self.pFilter = "" self.prompt = "yokadi> " else: projectName, keywordFilters = parseutils.extractKeywords(line) self.kFilters = keywordFilters self.pFilter = projectName prompt = "y" if self.pFilter: prompt += " %s" % projectName if self.kFilters: parseutils.warnIfKeywordDoesNotExist(self.kFilters) prompt += " %s" % (" ".join([str(k) for k in keywordFilters])) self.prompt = "%s> " % prompt
def do_t_filter(self, line): """Define permanent keyword filter used by t_list Ex.: - t_filter @work (filter all task that have the "work" keyword) - t_filter none (remove filter)""" # TODO: add completion if not line: raise YokadiException("You must give keyword as argument or 'none' to reset filter") if parseutils.simplifySpaces(line).lower() == "none": self.kFilters = [] self.pFilter = "" self.prompt = "yokadi> " else: projectName, keywordFilters = parseutils.extractKeywords(line) self.kFilters = keywordFilters self.pFilter = projectName prompt = "y" if self.pFilter: prompt += " %s" % projectName if self.kFilters: parseutils.warnIfKeywordDoesNotExist(self.kFilters) prompt += " %s" % (" ".join([str(k) for k in keywordFilters])) self.prompt = "%s> " % prompt
def __init__(self, name, filter_string): self.name = name project_name, keyword_filters = parseutils.extractKeywords( filter_string) q_filters = [x.filter() for x in keyword_filters] project_list = Project.select(LIKE(Project.q.name, project_name)) q_filters.append(IN(Task.q.project, project_list)) # Skip notes q_filters.append( parseutils.KeywordFilter("!@" + NOTE_KEYWORD).filter()) # Only list done tasks if they were done after min_date min_date = compute_min_date() q_filters.append( OR(Task.q.status != 'done', Task.q.doneDate >= min_date)) self.tasks = Task.select(AND(*q_filters), orderBy=Task.q.id, distinct=True, join=LEFTJOINOn( Task, TaskKeyword, Task.q.id == TaskKeyword.q.taskID))
def do_t_add_keywords(self, line): """Add keywords to an existing task t_add_keywords <id> <@keyword1> <@keyword2>[=<value>]... """ tokens = parseutils.simplifySpaces(line).split(" ", 1) if len(tokens) < 2: raise YokadiException( "You should give at least two arguments: <task id> <keyword>") task = dbutils.getTaskFromId(tokens[0]) garbage, keywordFilters = parseutils.extractKeywords(tokens[1]) newKwDict = parseutils.keywordFiltersToDict(keywordFilters) if garbage: raise YokadiException( "Cannot parse line, got garbage (%s). Maybe you forgot to add @ before keyword ?" % garbage) if not dbutils.createMissingKeywords(list(newKwDict.keys())): # User cancel keyword creation return kwDict = task.getKeywordDict() kwDict.update(newKwDict) task.setKeywordDict(kwDict) self.session.merge(task) self.session.commit()
def _parseListLine(self, parser, line): """ Parse line with parser, returns a tuple of the form (options, projectList, filters) """ args = parser.parse_args(line) if len(args.filter) > 0: projectName, keywordFilters = parseutils.extractKeywords(u" ".join( args.filter)) else: projectName = "" keywordFilters = [] if self.kFilters: # Add keyword filter keywordFilters.extend(self.kFilters) if not projectName: if self.pFilter: # If a project filter is defined, use it as none was provided projectName = self.pFilter else: # Take all project if none provided projectName = "%" if projectName.startswith("!"): projectName = self._realProjectName(projectName[1:]) projectList = Project.select(NOT(LIKE(Project.q.name, projectName))) else: projectName = self._realProjectName(projectName) projectList = Project.select(LIKE(Project.q.name, projectName)) if projectList.count() == 0: raise YokadiException("Found no project matching '%s'" % projectName) # Check keywords exist parseutils.warnIfKeywordDoesNotExist(keywordFilters) # Filtering and sorting according to parameters filters = [] # Filter on keywords for keywordFilter in keywordFilters: filters.append(keywordFilter.filter()) # Search if args.search: for word in args.search: if word.startswith("@"): tui.warning( "Maybe you want keyword search (without -s option) " "instead of plain text search?") filters.append( OR(LIKE(Task.q.title, "%" + word + "%"), LIKE(Task.q.description, "%" + word + "%"))) return args, projectList, filters
def _parseListLine(self, parser, line): """ Parse line with parser, returns a tuple of the form (options, projectList, filters) """ args = parser.parse_args(line) if len(args.filter) > 0: projectName, keywordFilters = parseutils.extractKeywords(" ".join(args.filter)) else: projectName = "" keywordFilters = [] if self.kFilters: # Add keyword filter keywordFilters.extend(self.kFilters) if not projectName: if self.pFilter: # If a project filter is defined, use it as none was provided projectName = self.pFilter else: # Take all project if none provided projectName = "%" if projectName.startswith("!"): projectName = self._realProjectName(projectName[1:]) projectList = self.session.query(Project).filter(Project.name.notlike(projectName)).all() else: projectName = self._realProjectName(projectName) projectList = self.session.query(Project).filter(Project.name.like(projectName)).all() if len(projectList) == 0: raise YokadiException("Found no project matching '%s'" % projectName) # Check keywords exist parseutils.warnIfKeywordDoesNotExist(keywordFilters) # Filtering and sorting according to parameters filters = [] # Filter on keywords for keywordFilter in keywordFilters: filters.append(keywordFilter.filter()) # Search if args.search: for word in args.search: if word.startswith("@"): tui.warning("Maybe you want keyword search (without -s option) " "instead of plain text search?") filters.append(or_(Task.title.like("%" + word + "%"), Task.description.like("%" + word + "%"))) return args, projectList, filters
def _parseListLine(self, parser, line): """ Parse line with parser, returns a tuple of the form (options, projectList, filters) """ args = parser.parse_args(line) if len(args.filter) > 0: projectName, filters = parseutils.extractKeywords(" ".join( args.filter)) else: projectName = "" filters = [] if self.kFilters: # Add keyword filter filters.extend(self.kFilters) if not projectName: if self.pFilter: # If a project filter is defined, use it as none was provided projectName = self.pFilter else: # Take all project if none provided projectName = "%" if projectName.startswith("!"): projectName = self._realProjectName(projectName[1:]) projectList = self.session.query(Project).filter( Project.name.notlike(projectName)).all() else: projectName = self._realProjectName(projectName) projectList = self.session.query(Project).filter( Project.name.like(projectName)).all() if len(projectList) == 0: raise YokadiException("Found no project matching '%s'" % projectName) # Check keywords exist parseutils.warnIfKeywordDoesNotExist(filters) # Search if args.search: for word in args.search: if word.startswith("@"): tui.warning( "Maybe you want keyword search (without -s option) " "instead of plain text search?") condition = or_(Task.title.like("%" + word + "%"), Task.description.like("%" + word + "%")) filters.append(DbFilter(condition)) return args, projectList, filters
def updateTaskFromVTodo(task, vTodo): """Update a yokadi task with an ical VTODO object @param task: yokadi task (db.Task object) @param vTodo: ical VTODO (icalendar.Calendar.Todo object)""" for yokadiAttribute, icalAttribute in list( YOKADI_ICAL_ATT_MAPPING.items()): attr = vTodo.get(icalAttribute) if attr: # Convert ical type (vDates, vInt..) to sql alchemy understandable type (datetime, int...) attr = icalutils.convertIcalType(attr) if yokadiAttribute == "title": # Remove (id) attr = re.sub("\s?\(%s\)" % task.id, "", attr) if yokadiAttribute == "doneDate": # A done date defined indicate that task is done task.status = "done" # BUG: Done date is UTC, we must compute local time for yokadi if yokadiAttribute == "urgency": if attr == icalutils.yokadiUrgencyToIcalPriority(task.urgency): # Priority does not change - don't update it continue else: # Priority has changed, we need to update urgency attr = icalutils.icalPriorityToYokadiUrgency(int(attr)) # Update attribute setattr(task, yokadiAttribute, attr) # Update keywords from categories if vTodo.get("categories"): if isinstance(vTodo.get("categories"), (list)): categories = vTodo.get("categories") else: categories = vTodo.get("categories").split(",") keywords = ["@%s" % k for k in categories] garbage, keywordFilters = parseutils.extractKeywords( " ".join(keywords)) newKwDict = parseutils.keywordFiltersToDict(keywordFilters) if garbage: print("Got garbage while parsing categories: %s" % garbage) dbutils.createMissingKeywords(list(newKwDict.keys()), interactive=False) task.setKeywordDict(newKwDict)
def updateTaskFromVTodo(task, vTodo): """Update a yokadi task with an ical VTODO object @param task: yokadi task (db.Task object) @param vTodo: ical VTODO (icalendar.Calendar.Todo object)""" for yokadiAttribute, icalAttribute in YOKADI_ICAL_ATT_MAPPING.items(): attr = vTodo.get(icalAttribute) if attr: # Convert ical type (vDates, vInt..) to sqlobjectunderstandable type (datetime, int...) attr = icalutils.convertIcalType(attr) if yokadiAttribute == "title": # Remove (id) attr = re.sub("\s?\(%s\)" % task.id, "", attr) if yokadiAttribute == "doneDate": # A done date defined indicate that task is done task.status = "done" # BUG: Done date is UTC, we must compute local time for yokadi if yokadiAttribute == "urgency": if attr == icalutils.yokadiUrgencyToIcalPriority(task.urgency): # Priority does not change - don't update it continue else: # Priority has changed, we need to update urgency attr = icalutils.icalPriorityToYokadiUrgency(int(attr)) # Update attribute setattr(task, yokadiAttribute, attr) # Update keywords from categories if vTodo.get("categories"): if isinstance(vTodo.get("categories"), (list)): categories = vTodo.get("categories") else: categories = vTodo.get("categories").split(",") keywords = ["@%s" % k for k in categories] garbage, keywordFilters = parseutils.extractKeywords(" ".join(keywords)) newKwDict = parseutils.keywordFiltersToDict(keywordFilters) if garbage: print "Got garbage while parsing categories: %s" % garbage dbutils.createMissingKeywords(newKwDict.keys(), interactive=False) task.setKeywordDict(newKwDict)
def do_t_add_keywords(self, line): """Add keywords to an existing task t_add_keywords <id> <@keyword1> <@keyword2>[=<value>]... """ tokens = parseutils.simplifySpaces(line).split(" ", 1) if len(tokens) < 2: raise YokadiException("You should give at least two arguments: <task id> <keyword>") task = dbutils.getTaskFromId(tokens[0]) garbage, keywordFilters = parseutils.extractKeywords(tokens[1]) newKwDict = parseutils.keywordFiltersToDict(keywordFilters) if garbage: raise YokadiException("Cannot parse line, got garbage (%s). Maybe you forgot to add @ before keyword ?" % garbage) if not dbutils.createMissingKeywords(newKwDict.keys()): # User cancel keyword creation return kwDict = task.getKeywordDict() kwDict.update(newKwDict) task.setKeywordDict(kwDict)