def AddTask(widget): # decode and trim the text to not allow only whitespaces/tabs desc = eDescription.get_text().decode('utf-8').strip() proj = eProject.get_text().decode('utf-8').strip() if desc: new_task = Task(self.tw) new_task['description'] = desc if proj and proj != 'None': new_task['project'] = proj # write it down new_task.save() # update the comboboxtext of pending tasks uuids[new_task['id']] = str(new_task['uuid']) desc = u''.join( new_task['description']).encode('utf-8').strip() proj = 'None' if new_task['project']: proj = u''.join( new_task['project']).encode('utf-8').strip() line = str(new_task['id']) + " [" + str(proj) + "]-" + desc cbChange.append_text(line) # select the new one cbChange.set_active(len(uuids) - 1) wAddTask.hide() else: # should write a custom css to change the color # https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-color eDescription.grab_focus()
def button_press(self, x, y, button): if button == 1: active_tasks = self.tw.tasks.filter('+ACTIVE') if active_tasks: task = active_tasks.get() task.stop() else: tasks = "\n".join("#{id}:[{project}] {desc} | +{tags}".format( id=t['id'], project=t['project'], desc=t['description'], tags=" +".join(t['tags']) or "(untagged)") for t in sorted(self.tw.tasks.pending(), key=lambda x: x['urgency'], reverse=True)) cmd = 'dmenu -p "Start task? >" -fn "Iosevka-10" -sb "#DDDDDD" -sf "#000000" -nb "#000000" -i -l 10 -b' try: result = subprocess.run(cmd, input=tasks, stdout=subprocess.PIPE, check=True, universal_newlines=True, shell=True) selection = result.stdout match = self.TASK_RE.match(selection) if match: task_id = match.group(1) task = self.tw.tasks.get(id=task_id) task.start() else: options = dict(self.OPTION_RE.findall(selection)) tags = self.TAG_RE.findall(selection) descr = self.OPTION_RE.sub('', selection).strip() descr = self.TAG_RE.sub('', descr).strip() task = Task(self.tw, description=descr) if options: for k, v in options.items(): task[k] = v if tags: task['tags'] = tags task.save() task.start() except subprocess.CalledProcessError: pass elif button == 2: active_tasks = self.tw.tasks.filter('+ACTIVE') if active_tasks: task = active_tasks.get() if 'ongoing' not in task['tags']: task.done() else: task.stop() elif button == 3: self.tw.execute_command(['sync']) super(TaskWarriorWidget, self).button_press(x, y, button)
def create_tasks(self, stories, inserted_tasks): """Create new tasks based on stories and insert them to TaskWarrior.""" # Tasks contain tasks which have been inserted (keyed by Story ID, not Task UUID) tasks = dict(inserted_tasks) # Story IDs contain Story IDs which have not yet been inserted as a Task story_ids = list(stories.keys()) while story_ids: # Tasks with dependencies (blockers) must have their dependencies inserted before them story = stories[story_ids[0]] blockers = [ x for x in story_ids if x in set(story['blocked_by'].values()) ] if blockers: for blocker in blockers: # Move blockers to the front of the queue story_ids.remove(blocker) story_ids.insert(0, blocker) continue # Remove story from queue to be inserted as a TaskWarrior task sid = story_ids.pop(0) task = Task(self.tw) task['description'] = story['name'] task['project'] = story['project'] if story['deadline']: task['due'] = datetime.strptime(story['deadline'], '%Y-%m-%dT%H:%M:%SZ') # Start task using Clubhouse start date if story['started_at'] and story[ 'workflow_state'] == self.DEV_STATE: task['start'] = datetime.strptime(story['started_at'], "%Y-%m-%dT%H:%M:%SZ") # Clubhouse priorities are High, Medium, Low but TaskWarrior is H, M, L if story['priority']: task['priority'] = story['priority'][0] task['tags'] = set(story['tags']) # We can assume at this stage all dependent tasks have been inserted to tasks already task['depends'] = set(tasks[k] for k in set(story['blocked_by'].values()) if k in tasks) # Save task (complete the insertion) task.save() # Save the UUID of the newly inserted task in the respective Story object story['task_uuid'] = task['uuid'] # Add saved task to tasks, keyed by Story ID tasks[sid] = task
def test_done_current(self): other_task = Task(self.tw, description="task to be done") other_task.save() uuid2 = other_task['uuid'] self.assertEquals( interface.do_start(dbus.Dictionary({ 'uuid': uuid2, 'resume': 'No' }))[0], "started:" + uuid2) prog = re.compile('started .* left.*') self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.done_current()[0], "ok") self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.done_current()[0], "no active task")
def test_resume(self): self.start() self.assertEquals(interface.do_fsm("stop")[0], "ok") self.assertEquals(interface.do_fsm("start")[0], "ok") prog = re.compile('started .* left.*') self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.do_fsm("pause")[0], "ok") prog = re.compile('paused .* left.*') self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.do_fsm("start")[0], "ok") self.assertEquals(interface.do_fsm("start")[0], "Already started") # test done and resume other_task = Task(self.tw, description="task 2 for the test") other_task.save() uuid2 = other_task['uuid'] self.assertEquals( interface.do_start(dbus.Dictionary({ 'uuid': uuid2, 'resume': 'No' }))[0], "started:" + uuid2) prog = re.compile('started .* left.*') self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.do_fsm("stop")[0], "ok") other_task.done() self.assertEquals(interface.do_fsm("start")[0], "ok") self.assertTrue(prog.match(interface.do_fsm("status")[0])) # test delete and resume other_task = Task(self.tw, description="task 3 for the test") other_task.save() uuid2 = other_task['uuid'] self.assertEquals( interface.do_start(dbus.Dictionary({ 'uuid': uuid2, 'resume': 'No' }))[0], "started:" + uuid2) prog = re.compile('started .* left.*') self.assertTrue(prog.match(interface.do_fsm("status")[0])) self.assertEquals(interface.do_fsm("stop")[0], "ok") other_task.delete() self.assertEquals(interface.do_fsm("start")[0], "ok") self.assertTrue(prog.match(interface.do_fsm("status")[0]))
def create_task(**kwargs): tw = TaskWarrior(data_location=(TWDFT_DATA_DIR), taskrc_location=TWDFTRC) verbose = kwargs.pop("verbose", False) open_card = kwargs.pop("open_card", False) inspectors = kwargs.pop("inspectors", False) test_task = Task(tw, **kwargs) test_task.save() if open_card: card_path = create_card( inspection_name=kwargs["description"], inspection_date=kwargs["inspection_date"], inspection_time=kwargs["inspection_time"], open_card=True, inspectors=inspectors, verbose=verbose, ) test_task["card_path"] = card_path[0] test_task["inspection_card_uuid"] = card_path[1] test_task.save() else: card_path = create_card( inspection_name=kwargs["description"], inspection_date=kwargs["inspection_date"], inspection_time=kwargs["inspection_time"], open_card=False, inspectors=inspectors, verbose=verbose, ) test_task["card_path"] = card_path[0] test_task["inspection_card_uuid"] = card_path[1] test_task.save()
try: date1 = datetime.strptime(sys.argv[1], '%Y-%m-%d') date2 = datetime.strptime(sys.argv[2], '%Y-%m-%d') if date2 <= date1: sys.exit("Bad arguments. Second date must be later than first") else: pushdate=date1 while pushdate < date2: dates.append(pushdate) pushdate+=timedelta(days=1) except: sys.exit("Bad date format on date arguments, must be YYYY-MM-DD.") import time from tasklib import Task, TaskWarrior db=TaskWarrior() for date in dates: [wait, scheduled, due, until] = ajrSalat.getSawmTime(date, usrconfig.coords, ((time.mktime(time.localtime()) - time.mktime(time.gmtime())) / 60 / 60), method=usrconfig.methodName, dst=time.localtime().tm_isdst, waitpad=usrconfig.sawmWaitpad, untilpad=usrconfig.sawmUntilpad) sawm_task = Task(db, description=usrconfig.sawmDesc, project=usrconfig.sawmProject, wait=wait[0:19], scheduled=scheduled[0:19], due=due[0:19], until=until[0:19], priority='H', tags=usrconfig.sawmTags) #[0:19] index for tasklib as it cannot process fractional seconds by way of the taskwarrior calc function sawm_task.save()