Esempio n. 1
0
def marvcli_user_list():
    """List existing users"""
    app = create_app()
    query = db.session.query(User).options(db.joinedload(User.groups))\
                                  .order_by(User.name)
    users = [(user.name, ', '.join(sorted(x.name for x in user.groups)))
             for user in query]
    users = [('User', 'Groups')] + users
    uwidth, gwidth = reduce(lambda (xm, ym), (x, y): (max(x, xm), max(y, ym)),
                            ((len(x), len(y)) for x, y in users))
    fmt = '{:%ds} | {}' % uwidth
    for x, y in users:
        click.echo(fmt.format(x, y))
Esempio n. 2
0
def marvcli_comment_list(datasets):
    """Lists comments for datasets.

    Output: setid comment_id date time author message
    """
    app = create_app()
    ids = parse_setids(datasets, dbids=True)
    comments = db.session.query(Comment)\
                         .options(db.joinedload(Comment.dataset))\
                         .filter(Comment.dataset_id.in_(ids))
    for comment in sorted(comments, key=lambda x: (x.dataset._setid, x.id)):
        print(comment.dataset.setid, comment.id,
              datetime.datetime.fromtimestamp(int(comment.time_added / 1000)),
              comment.author, repr(comment.text))
Esempio n. 3
0
def marvcli_show(ctx, datasets):
    """Show information for one or more datasets in form of a yaml document.

    Set ids may be abbreviated as long as they are unique.
    \b
    Some examples
      marv show setid  # show one dataset
      marv query --col=* | xargs marv show   # show all datasets
    """
    app = create_app()
    ids = parse_setids(datasets, dbids=True)
    datasets = db.session.query(Dataset)\
                         .options(db.joinedload(Dataset.files))\
                         .filter(Dataset.id.in_(ids))\
                         .all()
    yamldoc = SHOW_TEMPLATE.render(datasets=datasets)
    print(yamldoc, end='')