def on_task_info_closed(self, updates): """Updates the task when the task info window is closed. Updates is a dictionary with 'uuid' and modified fields.""" if "uuid" in updates: uuid = updates["uuid"] del updates["uuid"] else: uuid = None if uuid: command = ["task", uuid, "mod"] else: command = ["task", "add"] if updates: for k, v in updates.items(): if k == "tags": for tag in v: if tag.strip(): command.append(tag) elif k == "description": command.append(v) else: command.append("%s:%s" % (k, v)) util.run_command(command) self.update_status()
def stop(self, widget): """Stops running tasks""" for task in self.database.get_tasks(): if "start" in task: util.run_command(["task", task["uuid"], "stop"]) self.stop_item.hide() self.update_status()
def update_task(self, task_id, properties): command = ["task", task_id, "mod"] for k, v in properties.items(): if k in ("project", "priority"): command.append("%s:%s" % (k, v)) elif k == "summary": command.append(v) elif k == "description": save_note(task_id, v) util.run_command(command)
def add_task(self, properties): command = ["task", "add"] for k, v in properties.items(): if k == "summary": command.append(v) elif k in ("project", "priority"): command.append("%s:%s" % (k, v)) output = util.run_command(command) for _taskno in re.findall("Created task (\d+)", output): uuid = util.run_command(["task", _taskno, "uuid"]).strip() util.log("New task uuid: {0}", uuid) save_note(uuid, properties.get("description", "")) return uuid
def get_database_folder(): out = util.run_command(["task", "_show"]) for line in out.split("\n"): if line.startswith("data.location="): return line.split("=", 1)[1] raise RuntimeException("Could not find database location.")
def update_task(self, task_id, properties): command = ["task", task_id, "mod"] for k, v in properties.items(): if k == "uuid": continue if k == "tags": for tag in v: if tag.strip(): command.append(tag) elif k == "description": command.append(v) elif k == "note": save_note(task_id, v) else: command.append("{0}:{1}".format(k, v)) util.run_command(command)
def merge_exported(self, tasks): """Merges data reported by task. This is primarily used to get real urgency, maybe something else in the future.""" out = util.run_command(["task", "rc.json.array=1", "export"]) _tasks = {} for em in json.loads(out): _tasks[em["uuid"]] = em for idx, task in enumerate(tasks): if task["uuid"] not in _tasks: util.log("Warning: task {0} not exported by TaskWarrior.", task["uuid"]) continue _task = _tasks[task["uuid"]] if "urgency" in _task: tasks[idx]["urgency"] = float(_task["urgency"]) return tasks
def get_filename(self): for line in util.run_command(["task", "_show"]).split("\n"): if line.startswith("data.location="): folder = line.split("=", 1)[1].strip() return os.path.join(folder, "pending.data")
def on_stop_task(self, task): util.run_command(["task", task["uuid"], "stop"]) self.update_status()
def open_task_webpage(self, task): for word in task["description"].split(" "): if "://" in word: util.run_command(["xdg-open", word])
def start_task(self, task_id): util.log("Starting task {0}.", task_id) util.run_command(["task", task_id, "start"])
def on_start_task(self, task): util.run_command(["task", task["uuid"], "start"]) self.update_status() self.open_task_webpage(task)
def stop_task(self, task_id): util.log("Stopping task {0}.", task_id) util.run_command(["task", task_id, "stop"], fail=False)
def on_pull_tasks(self, widget): util.run_command(["bugwarrior-pull"])
def finish_task(self, task_id): util.log("Finishing task {0}.", task_id) util.run_command(["task", task_id, "stop"], fail=False) util.run_command(["task", task_id, "done"])
def get_filename(self): for line in util.run_command(["task", "_show"]).split("\n"): if line.startswith("data.location="): folder = line.split("=", 1)[1].strip() return os.path.expanduser(os.path.join(folder, "pending.data")) raise RuntimeError("Could not find task database location.")
def restart_task(self, task_id): util.log("Restarting task {0}.", task_id) util.run_command(["task", task_id, "mod", "status:pending"]) util.run_command(["task", task_id, "start"])