Exemplo n.º 1
0
def update(options, args):
    """Usage: update

    Synchronizes your project database with the server."""

    db = ProjectsDb()

    db.update(
            settings.get('default', 'site'),
            settings.get('default', 'username'),
            settings.get('default', 'password')
    )
Exemplo n.º 2
0
def search(options, args):
    """Usage: search search_string

    Searches for a project by its name.
    """

    db = ProjectsDb()

    if len(args) < 2:
        raise Exception(search.__doc__)

    search = args
    search = search[1:]
    projects = db.search(search)
    for project in projects:
        print '%-4s %s' % (project.id, project.name)
Exemplo n.º 3
0
def show(options, args):
    """Usage: show project_id

    Shows the details of the given project_id (you can find it with the search
    command)."""

    db = ProjectsDb()

    if len(args) < 2:
        raise Exception(show.__doc__)

    try:
        project = db.get(int(args[1]))
    except IOError:
        print 'Error: the projects database file doesn\'t exist. Please run `taxi update` to create it'
    except ValueError:
        print 'Error: the project id must be a number'
    else:
        print project

        if project.status == 1:
            print "\nActivities:"
            for activity in project.activities:
                print '%-4s %s' % (activity.id, activity.name)
Exemplo n.º 4
0
def add(options, args):
    """Usage: add search_string

    Searches and prompts for project, activity and alias and adds that as a new entry to .tksrc
    """
    db = ProjectsDb()

    if len(args) < 2:
        raise Exception(add.__doc__)

    search = args[1:]
    projects = db.search(search)

    if len(projects) == 0:
        print 'No project matches your search string \'%s\'' % ' '.join(search)
        return

    for (key, project) in enumerate(projects):
        print '(%d) %-4s %s' % (key, project.id, project.name)

    try:
        number = select_number(len(projects), 'Choose the project (0-%d), (Ctrl-C) to exit: ' % (len(projects) - 1))
    except KeyboardInterrupt:
        return

    project = projects[number]

    print project

    if project.status == 0:
        print 'Warning: this project is not active'

    print "\nActivities:"
    for (key, activity) in enumerate(project.activities):
        print '(%d) %-4s %s' % (key, activity.id, activity.name)

    try:
        number = select_number(len(project.activities), 'Choose the activity (0-%d), (Ctrl-C) to exit: ' % (len(project.activities) - 1))
    except KeyboardInterrupt:
        return

    retry = True
    while retry:
        try:
            alias = select_string('Enter the alias for .tksrc (a-z, - and _ allowed), (Ctrl-C) to exit: ', r'^[\w-]+$')
        except KeyboardInterrupt:
            return

        if settings.activity_exists(alias):
            overwrite = select_string('The selected alias you entered already exists,'\
                ' overwrite? [y/n/R(etry)]: ', r'^[ynr]$', re.I, 'r')

            if overwrite == 'n':
                return
            if overwrite == 'y':
                retry = False
        else:
            retry = False

    activity = project.activities[number]
    settings.add_activity(alias, project.id, activity.id)

    print '\nThe following entry has been added to your .tksrc: %s = %s/%s' % (alias, project.id, activity.id)