示例#1
0
async def site(loop):  # pylint: disable=unused-argument
    sitedir = tempfile.mkdtemp()
    scanroot = os.path.join(sitedir, 'scanroot')
    os.mkdir(scanroot)
    os.mkdir(os.path.join(scanroot, 'foo'))
    os.mkdir(os.path.join(scanroot, 'bar'))
    siteconf = os.path.join(sitedir, 'marv.conf')
    with open(siteconf, 'w') as fobj:
        fobj.write(inspect.cleandoc(CONFIG))

    site_ = await Site.create(Path(siteconf), init=True)
    site_.scanroot_ = scanroot
    (site_.config.marv.resourcedir / 'answer').write_text('42')

    yield site_

    async with scoped_session(site_.db) as connection:
        tables = (await connection.execute_query(
            'SELECT name FROM sqlite_master WHERE type="table"'))[1]
        tables = (x['name'] for x in tables if x['name'].startswith('l_'))
        for table in sorted(tables, key=len, reverse=True):
            await connection.execute_query(f'DROP TABLE {table}')
    await site_.destroy()
    if not KEEP:
        shutil.rmtree(sitedir)
    else:
        echo(f'Keeping {sitedir}')
示例#2
0
async def marvcli_comment_list(datasets):
    """List comments for datasets.

    Output: setid comment_id date time author message
    """
    async with create_site() as site:
        comments = await site.db.get_comments_by_setids(datasets)
        for comment in sorted(comments,
                              key=lambda x: (x.dataset[0].setid, x.id)):
            echo(
                comment.dataset[0].setid,
                comment.id,
                datetime.datetime.fromtimestamp(int(comment.time_added /
                                                    1000)),  # noqa: DTZ
                comment.author,
                repr(comment.text))
示例#3
0
async def marvcli_show(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
    """
    async with create_site() as site:
        datasets = await site.db.get_datasets_by_setids(datasets,
                                                        prefetch=['files'],
                                                        user='******')
        yamldoc = SHOW_TEMPLATE.render(datasets=datasets)
        echo(yamldoc, end='')
示例#4
0
def print_trace(args):
    echo('TRACE', args)
    return args