Esempio n. 1
0
def cmd_clear(settings):
    """
        Drop all tables and re-create.
    """
    sa = get_session(settings.dbref, metadata=metadata)

    for name, table in metadata.tables.items():

        print(table.delete())
        sa.execute(table.delete())

    sa.commit()

    sa = get_session(settings.dbref, initialize=True, metadata=metadata)
Esempio n. 2
0
def cmd_find(settings, LIKE):
    """
        Look for tag.
    """
    sa = get_session(settings.dbref, metadata=metadata)
    alikes = sa.query(Tag).filter(Tag.name.like(LIKE)).all()
    for tag in alikes:
        print(tag.name)
Esempio n. 3
0
def cmd_list(settings):
    """
        List to root tags.
    """
    sa = get_session(settings.dbref, metadata=metadata)
    roots = sa.query(Tag).filter(Tag.contexts == None).all()
    for root in roots:
        print(root.name)
Esempio n. 4
0
def cmd_record(settings, opts, TAGS):
    """
        Record tags/paths. Report on inconsistencies.
    """
    sa = get_session(settings.dbref, initialize=True, metadata=metadata)
    assert TAGS # TODO: read from stdin
    for raw_tag in TAGS:
        Tag.record(raw_tag, sa, opts)
Esempio n. 5
0
def cmd_insert(title, before_ID):
    """
        todo [options] insert <title-or-ID>
    """
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    before = Task.fetch(((Task.task_id == before_ID[0]),), sa=sa)
    task = Task(title=title, prerequisite_id=before.task_id)
    sa.add(task)
    sa.commit()
Esempio n. 6
0
def cmd_ungroup(ID, settings):
    """
        todo ungroup ID
    """
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    for id_ in ID:
        node = Task.byKey(dict(task_id=id_), sa=sa)
        node.partOf_id = None
        sa.add(node)
    sa.commit()
Esempio n. 7
0
def cmd_rm(ID, settings):
    """
        todo rm ID...

    Delete tasks.
    """
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    for id_ in ID:
        task = Task.fetch(((Task.task_id == id_),), sa=sa)
        sa.delete(task)
        sa.commit()
        print_Task(task)
Esempio n. 8
0
def cmd_update(ID, title, description, group, opts, settings):
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    task = Task.find(( Task.title == title, ), sa=sa)
    if group:
        group = Task.find(( Task.title == group, ), sa=sa)
        assert group, opts.args.group
    # TODO: title, description
    # TODO: prerequisites...
    # requiredFor...
    # partOf
    # subtasks...
    pass
Esempio n. 9
0
def cmd_import(input, settings):
    """
        todo import -i FILE
    """
    input = input or settings.input
    assert input, "Missing input file."
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    json = js.load(open(input, 'r'))
    assert json['version'] == __version__, json['version']
    for t in json['tasks']:
        task = Task(**t)
        sa.add(task)
    sa.commit()
Esempio n. 10
0
def cmd_export(output, settings):
    """
        todo export -o FILE
    """
    output = output or settings.output
    assert settings.output, "Missing output file."
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    tasks = sa.query(Task).all()
    data = {
        'version': __version__,
        'tasks': [ t.copy(True) for t in tasks ]
    }
    js.dump(data, open(settings.output, 'w+'))
Esempio n. 11
0
def cmd_new(title, description, group, opts, settings):
    """
        todo [options] new <title> <description> <group>
    """
    sa = get_session(settings.dbref)
    if group:
        group = Task.find(( Task.title == group, ), sa=sa)
        assert group, opts.args.group
    task = Task(
            title = title,
            description = description,
            partOf = group
    )
    sa.add(task)
    sa.commit()
    print_Task(task)
Esempio n. 12
0
def cmd_depends(ID, DEPENDENCIES, settings):
    """
        todo ID requires DEPENDENCIES...

    """
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    node = Task.byKey(dict(task_id=ID), sa=sa)
    for dep_ID in DEPENDENCIES:
        dep = Task.byKey(dict(task_id=dep_ID), sa=sa)
        dep.requiredFor_id = ID
        sa.add(dep)
        ID = dep_ID
    else:
        dep = Task.byKey(dict(requiredFor_id=ID), sa=sa)
        dep.requiredFor_id = None
        sa.add(dep)
    sa.commit()
Esempio n. 13
0
def cmd_prerequisite(ID, PREREQUISITES, settings):
    """
        todo ID depends PREREQUISITES...

    (Re)Set ID to depend on first prerequisite ID. If more prerequisites are
    given, apply the same to every following ID in sequence.

    This sets an unqualified dependency.
    TODO: check level
    """
    sa = get_session(settings.dbref, metadata=SqlBase.metadata)
    node = Task.byKey(dict(task_id=ID), sa=sa)
    for prereq_ID in PREREQUISITES:
        node.requiredFor_id = prereq_ID
        sa.add(node)
        node = Task.byKey(dict(task_id=prereq_ID), sa=sa)
    else:
        node.requiredFor_id = None
        sa.add(node)
    sa.commit()
Esempio n. 14
0
def cmd_info(settings):

    """
        Verify DB connection is working. Print some settings and storage stats.
    """

    for l, v in (
            ( 'Settings Raw', pformat(settings.todict()) ),
            ( 'DBRef', settings.dbref ),

            ( "Tables in schema", ", ".join(metadata.tables.keys()) ),
            ( "Table lengths", "" ),
    ):
        log.std('{green}%s{default}: {bwhite}%s{default}', l, v)

    sa = get_session(settings.dbref, metadata=metadata)

    for t in metadata.tables:
        try:
            log.std("  {blue}%s{default}: {bwhite}%s{default}",
                    t, sa.query(metadata.tables[t].count()).all()[0][0])
        except Exception, e:
            log.err("Count failed for %s: %s", t, e)
Esempio n. 15
0
def cmd_list(settings):
    sa = get_session(settings.dbref)
    roots = sa.query(Task).filter(Task.partOf_id == None).all()
    indented_tasks('', sa, settings, roots)
Esempio n. 16
0
def cmd_find(title, settings):
    sa = get_session(settings.dbref)
    task = Task.find(( Task.title == title, ), sa=sa)
    print_Task(task)
Esempio n. 17
0
def cmd_init(settings):
    """
        Commit SQL DDL to storage schema. Creates DB file if not present.
    """
    sa = get_session(settings.dbref, initialize=True, metadata=metadata)