Пример #1
0
    def setUp(self):
        taskwarrior = TaskWarrior(data_location='tests/test_data/.task',
                                  create=True)
        Task(taskwarrior,
             description='test_yesterday',
             schedule='yesterday',
             estimate='20min').save()
        Task(taskwarrior,
             description='test_9:00_to_10:11',
             schedule='today+9hr',
             estimate='71min',
             project='test').save()
        Task(taskwarrior,
             description='test_14:00_to_16:00',
             schedule='today+14hr',
             estimate='2hr').save()
        Task(taskwarrior,
             description='test_tomorrow',
             schedule='tomorrow',
             estimate='24min').save()

        self.tasks = taskwarrior.tasks.filter(status='pending')
        self.schedule = Schedule(tw_data_dir='tests/test_data/.task',
                                 tw_data_dir_create=True)
        self.schedule.load_tasks()
Пример #2
0
    def task(self):
        # New task object accessed second or later time
        if self.__unsaved_task is not None:
            return self.__unsaved_task

        # Return the corresponding task if alrady set
        # Else try to load it or create a new one
        if self.uuid:
            try:
                return self.cache.task[self.uuid]
            except Task.DoesNotExist:
                # Task with stale uuid, recreate
                self.__unsaved_task = Task(self.tw)
                # If task cannot be loaded, we need to remove the UUID
                vim.command(
                    'echom "UUID \'{0}\' not found, Task on line {1} will be '
                    're-created in TaskWarrior."'.format(
                        self.uuid,
                        self['line_number'] + 1
                    ))
                self.uuid = None
        else:
            # New task object accessed first time
            self.__unsaved_task = Task(self.tw)

        return self.__unsaved_task
Пример #3
0
    def setUp(self):
        taskwarrior = TaskWarrior(data_location='tests/test_data/.task',
                                  create=True)
        Task(taskwarrior,
             description='test_yesterday',
             schedule='yesterday',
             estimate='20min').save()
        Task(taskwarrior,
             description='test_9:00_to_10:11',
             schedule='today+9hr',
             estimate='71min').save()
        Task(taskwarrior,
             description='test_14:00_to_16:00',
             schedule='today+14hr',
             estimate='2hr').save()
        Task(taskwarrior,
             description='test_16:10_to_16:34',
             schedule='today+16hr+10min',
             estimate='24min').save()
        Task(taskwarrior,
             description='test_tomorrow',
             schedule='tomorrow',
             estimate='24min').save()

        self.schedule = Schedule(tw_data_dir='tests/test_data/.task',
                                 tw_data_dir_create=True)
 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()
Пример #5
0
    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)
Пример #6
0
    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
Пример #7
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()
Пример #8
0
 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")
Пример #9
0
 def update(self, idx, description=None, completed=None, due=None):
     if idx is None:
         task = Task(self.taskwarrior)
     else:
         task = self[idx]
     if description is not None:
         task["description"] = description
     if completed is not None:
         if is_task_completed(task):
             if not completed:
                 task["status"] = "pending"
         else:
             if completed:
                 task.done()
     if due is not None:
         task["due"] = due
     if idx is None:
         return self.add(task)
     else:
         return self.commit(idx)
Пример #10
0
    def test_screen_draw(self):
        taskwarrior = TaskWarrior(
            data_location=self.task_dir_path,
            create=True,
            taskrc_location=self.taskrc_path,
        )
        Task(
            taskwarrior,
            description="test_yesterday",
            schedule="yesterday",
            estimate="20min",
        ).save()
        Task(
            taskwarrior,
            description="test_9:00_to_10:11",
            schedule="today+9hr",
            estimate="71min",
            project="test",
        ).save()

        self.screen.draw()
        self.screen.refresh_buffer()
        Task(
            taskwarrior,
            description="test_14:00_to_16:00",
            schedule="today+14hr",
            estimate="2hr",
        ).save()
        time.sleep(0.1)
        self.screen.draw()
        self.screen.refresh_buffer()
        Task(
            taskwarrior,
            description="test_tomorrow",
            schedule="tomorrow",
            estimate="24min",
        ).save()
        time.sleep(0.1)
        self.screen.draw()
        self.screen.refresh_buffer()
Пример #11
0
    def generate_data(self):
        super(MultipleSourceTest, self).generate_data()

        self.extra_dir = tempfile.mkdtemp(dir='/tmp/')

        self.extra_tw = TaskWarrior(data_location=self.extra_dir,
                                    taskrc_location='/')

        extra_tasks = [
            Task(self.extra_tw, **task_kwargs)
            for task_kwargs in self.extra_tasks
        ]

        self.extra_tasks = extra_tasks
        for task in self.extra_tasks:
            task.save()
Пример #12
0
    def generate_data(self):
        self.dir = tempfile.mkdtemp(dir='/tmp/')

        # Create an actual taskrc file where we can write later
        self.taskrc_path = os.path.join(self.dir, "taskrc")
        with open(self.taskrc_path, 'w') as f:
            f.write("#testing taskrc\n")

        self.tw = TaskWarrior(data_location=self.dir,
                              taskrc_location=self.taskrc_path)

        new_tasks = [
            Task(self.tw, **task_kwargs) for task_kwargs in self.tasks
        ]

        self.tasks = new_tasks
        for task in self.tasks:
            task.save()
Пример #13
0
else:
    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()
Пример #14
0
 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]))
Пример #15
0
class TestPomodoro(unittest.TestCase):
    tw = TaskWarrior(data_location='.task/', create=True)
    new_task = Task(tw, description="task for the test")
    new_task.save()
    uuid = new_task['uuid']

    def get_active_task(self):
        for task in self.tw.tasks.pending():
            if task.active:
                #get all fields in task
                task.refresh()
                return task
        return {}

    def tearDown(self):
        try:
            interface.do_fsm("stop")[0]
        except:
            return

    def start(self):
        self.assertEquals(
            interface.do_start(
                dbus.Dictionary({
                    'uuid': self.uuid,
                    'resume': 'No'
                }))[0], "started:" + self.uuid)

    def test_stop(self):
        self.start()
        self.assertEquals(interface.do_fsm("stop")[0], "ok")

    def test_status(self):
        prog = re.compile('stopped .* left.*')
        self.assertTrue(prog.match(interface.do_fsm("status")[0]))
        self.start()
        prog = re.compile('started .* left.*')
        self.assertTrue(prog.match(interface.do_fsm("status")[0]))
        self.assertTrue(interface.do_fsm("pause")[0])
        prog = re.compile('paused .* left.*')
        self.assertTrue(prog.match(interface.do_fsm("status")[0]))

    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 test_reset(self):
        self.start()
        # from start to reset with previous task
        self.assertEquals(interface.do_fsm("reset")[0], "ok")
        prog = re.compile('started .* left.*')
        self.assertTrue(prog.match(interface.do_fsm("status")[0]))
        # from pause to reset with previous task
        self.assertEquals(interface.do_fsm("pause")[0], "ok")
        self.assertEquals(interface.do_fsm("reset")[0], "ok")
        self.assertTrue(prog.match(interface.do_fsm("status")[0]))

    def test_warning(self):
        self.assertEquals(interface.do_fsm("stop")[0], "Already stopped")
        self.start()
        self.assertEquals(interface.do_fsm("start")[0], "Already started")
        self.assertEquals(interface.do_fsm("pause")[0], "ok")
        # doing a resume so
        self.assertEquals(interface.do_fsm("pause")[0], "ok")

    # close the daemon last
    def test_zzz(self):
        self.new_task.delete()
        # remove the directory
        shutil.rmtree('.task/')
        interface.do_quit(False)
Пример #16
0
    def setUp(self):
        self.taskrc_path = "tests/test_data/.taskrc"
        self.task_dir_path = "tests/test_data/.task"
        self.assertEqual(os.path.isdir(self.taskrc_path), False)
        self.assertEqual(os.path.isdir(self.task_dir_path), False)

        # Create a sample .taskrc
        with open(self.taskrc_path, "w+") as file:
            file.write("# User Defined Attributes\n")
            file.write("uda.estimate.type=duration\n")
            file.write("uda.estimate.label=Est\n")
            file.write("# User Defined Attributes\n")
            file.write("uda.tb_estimate.type=numeric\n")
            file.write("uda.tb_estimate.label=Est\n")
            file.write("uda.tb_real.type=numeric\n")
            file.write("uda.tb_real.label=Real\n")

        # Create a sample empty .task directory
        os.makedirs(self.task_dir_path)

        taskwarrior = TaskWarrior(
            data_location="tests/test_data/.task",
            create=True,
            taskrc_location="tests/test_data/.taskrc",
        )
        Task(
            taskwarrior,
            description="test_yesterday",
            schedule="yesterday",
            estimate="20min",
        ).save()
        Task(
            taskwarrior,
            description="test_9:00_to_10:11",
            schedule="today+9hr",
            estimate="71min",
        ).save()
        Task(
            taskwarrior,
            description="test_14:00_to_16:00",
            schedule="today+14hr",
            estimate="2hr",
        ).save()
        Task(
            taskwarrior,
            description="test_16:10_to_16:34",
            schedule="today+16hr+10min",
            estimate="24min",
        ).save()
        Task(
            taskwarrior,
            description="test_tomorrow",
            schedule="tomorrow",
            estimate="24min",
        ).save()

        self.schedule = Schedule(
            tw_data_dir="tests/test_data/.task",
            tw_data_dir_create=False,
            taskrc_location="tests/test_data/.taskrc",
        )