Ejemplo n.º 1
0
def main():

    # Create the Taskwarrior backend till
    # [this](https://github.com/robgolding/tasklib/issues/58) bug is fixed

    task_command = sys.argv[3].split(':')[1].strip()
    if (task_command != 'delete' and task_command != 'done' and True):
        sys.exit(0)

    tw = tasklib.TaskWarrior(
        taskrc_location=sys.argv[4].split(':')[1],
        data_location=sys.argv[5].split(':')[1],
    )
    task = tasklib.task.Task.from_input(backend=tw)
    task_command = sys.argv[3].split(':')[1].strip()

    if task['r'] is None:
        sys.exit(0)

    prt = ProcessRecurrentTask(task)

    if task['rlastinstance'] is not None:
        if task_command == 'delete':
            prt.delete_child_task()
    else:
        prt.synthetize_next_child()

    sys.exit(0)
Ejemplo n.º 2
0
    def setUp(self):
        self.local_zone = tzlocal.get_localzone()

        self.tzlocal_patch = patch('taskwarrior_recurrence.main.tzlocal')
        self.tzlocal = self.tzlocal_patch.start()

        self.temp_dir = tempfile.mkdtemp()
        shutil.copyfile('tests/files/taskrc', self.temp_dir + '/taskrc')

        self.tw = tasklib.TaskWarrior(
            taskrc_location=self.temp_dir + '/taskrc',
            data_location=self.temp_dir,
        )

        self.task_data = {
            "entry": "20370702T194712Z",
            "uuid": "3f0a43d0-a713-4ebe-9e5c-b1facf49f078",
            "modified": "20370708T085429Z",
            "status": "completed",
            "description": "This is a periodic recurring task",
            "end": '20370708T085429',
            "due": '20370708T010000',
            "r": '1w',
            "rparent": "012339c8-a8fe-41da-82db-a990f989237e",
            "project": 'test_project',
            "myuda": 'udavalue',
        }
        self.task = self.import_task(self.task_data)

        self.parent_task_data = {
            "entry": "20370701T194712Z",
            "uuid": "012339c8-a8fe-41da-82db-a990f989237e",
            "modified": "20370706T085429Z",
            "status": "recurring",
            "description": "This is a periodic recurring task",
            "due": '20370708T010000',
            "r": '1w',
            'rtype': 'periodic',
            "recur": '1w',
            "rlastinstance": self.task_data['uuid'],
            "project": 'test_project',
            "myuda": 'udavalue',
        }
        self.parent_task = self.import_task(self.parent_task_data)

        self.tzlocal.get_localzone.return_value.localize.return_value = \
            self.local_zone.localize(
                datetime.datetime.strptime(
                    self.task_data['end'],
                    '%Y%m%dT%H%M%S'
                )
            )

        self.prt = ProcessRecurrentTask(self.task)
Ejemplo n.º 3
0
def taskw_mock(taskw_active_description, taskw_tagged_description):
    active_description = taskw_active_description
    tagged_description = taskw_tagged_description
    task_path = Path.cwd().joinpath(".temp_task")
    tw = tasklib.TaskWarrior(data_location=task_path, create=True)
    new_tagged_task = tasklib.Task(
        tw,
        description=tagged_description,
        tags=["tggd"],
    )
    new_tagged_task.save()
    new_active_task = tasklib.Task(tw, description=active_description)
    new_active_task.save()
    new_active_task.start()
    yield task_path
    for p in task_path.iterdir():
        p.unlink()
    task_path.rmdir()
Ejemplo n.º 4
0
def main():

    tw = tasklib.TaskWarrior(
        taskrc_location=sys.argv[1],
        data_location=sys.argv[2],
    )
    children_recurring_tasks = tw.tasks.filter(rparent__not=None)

    for task in children_recurring_tasks:
        if task['status'] in ['completed', 'deleted', 'recurring']:
            continue
        parent_task = tw.tasks.get(uuid=task['rparent'])
        if parent_task['rlastinstance'] != task['uuid']:
            print('Regenerating rlastinstance of {} - {}'.format(
                parent_task['uuid'],
                parent_task['description'],
            ))
            parent_task['rlastinstance'] = task['uuid']
            parent_task.save()
Ejemplo n.º 5
0
def alert(scheduleEntry, time):
    if scheduleEntry == "":
        os.system('notify-send ' + "'take a long break!'")
    elif scheduleEntry in projects:
        os.system('notify-send "' + scheduleEntry + '"')

        tw = tasklib.TaskWarrior(data_location='~/.task', create=False)

        tasks = tw.tasks.filter(status='pending', project=scheduleEntry)

        if len(tasks) > 0:
            for task in tasks:
                os.system('notify-send ' + str(task))
        else:
            os.system('notify-send ' + "'no " + scheduleEntry + " tasks left'")
    else:
        os.system('notify-send "' + scheduleEntry + '"')

    playsound(scheduleEntry)
Ejemplo n.º 6
0
def main():

    # Create the Taskwarrior backend till
    # [this](https://github.com/robgolding/tasklib/issues/58) bug is fixed

    tw = tasklib.TaskWarrior(
        taskrc_location=sys.argv[4].split(':')[1],
        data_location=sys.argv[5].split(':')[1],
    )
    task = tasklib.task.Task.from_input(backend=tw)

    if task['r'] is None or task['rparent'] is not None:
        print(task.export_data())
        sys.exit(0)

    prt = ProcessRecurrentTask(task)

    if task['rtype'] == 'chained' or task['rtype'] == 'periodic':
        task = prt.add_recurrent_task()

    print(task.export_data())
    sys.exit(0)
Ejemplo n.º 7
0
def main():

    tw = tasklib.TaskWarrior(
        taskrc_location=sys.argv[1],
        data_location=sys.argv[2],
    )
    recurring_tasks = tw.tasks.filter(status='recurring')

    for task in recurring_tasks:
        try:
            child_task = tw.tasks.get(uuid=task['rlastinstance'])
        except Exception:
            import pdb
            pdb.set_trace()  # XXX BREAKPOINT
        if child_task['status'] == 'deleted' or \
                child_task['status'] == 'completed':
            print('Regenerating child of {} - {}'.format(
                task['uuid'],
                task['description'],
            ))
            prt = taskwarrior_recurrence.main.ProcessRecurrentTask(child_task)
            task = prt.synthetize_next_child()
## Author: Tomas Babej
## License: undetermined

import os
import datetime
import icalendar
import tasklib

tw = tasklib.TaskWarrior()
tasks = tw.tasks.filter('due.not:')


def export_to_ical(task):
    calendar = icalendar.Calendar()
    calendar.add('prodid', '-//Taskwarrior exporter//Version 1//EN')
    calendar.add('version', '2.0')

    event = icalendar.Event()
    event['summary'] = task['description']
    event.add('dtstart', task['due'])
    event.add('dtend', task['due'] + datetime.timedelta(seconds=1))
    event.add('dtstamp', task['entry'])
    event.add('uid', task['uuid'].upper())

    calendar.add_component(event)

    filename = '~/.calendars/tw/{0}.ics'.format(event['uid'])
    with open(os.path.expanduser(filename), 'w') as f:
        f.write(calendar.to_ical())