cli.py 1.35 KB
Newer Older
Aurélien Campéas's avatar
Aurélien Campéas committed
1
2
3
4
5
from threading import Thread
import socket
import webbrowser

import click
6
from sqlalchemy import create_engine
Aurélien Campéas's avatar
Aurélien Campéas committed
7

8
from rework import schema as baseschema, helper
Aurélien Campéas's avatar
Aurélien Campéas committed
9
from rework_ui.app import startapp
10
from rework_ui import schema, taskstable
Aurélien Campéas's avatar
Aurélien Campéas committed
11
12
13
14
15
16


@click.command()
@click.argument('db-uri')
def view(db_uri):
    """monitor and control workers and tasks"""
17
    ipaddr = helper.host()
Aurélien Campéas's avatar
Aurélien Campéas committed
18
19
20
21
22
23
    port = 5679
    server = Thread(name='reworkui.webapp', target=startapp,
                    kwargs={'host': ipaddr, 'port': port, 'dburi': db_uri})
    server.daemon = True
    server.start()

Aurélien Campéas's avatar
Aurélien Campéas committed
24
    webbrowser.open('http://{ipaddr}:{port}'.format(ipaddr=ipaddr, port=port))
Aurélien Campéas's avatar
Aurélien Campéas committed
25
    input()
26
27


28
@click.command(name='init-db')
29
@click.argument('dburi')
30
31
def init_db(dburi):
    "initialize the database schema for rework in its own namespace"
32
    engine = create_engine(dburi)
33
34
    baseschema.reset(engine)
    baseschema.init(engine)
35
36
37
38
39
40
41
42
43
44
45
46
    schema.init(engine)


@click.command(name='generate-tasks-table')
@click.argument('dburi')
@click.option('--loop', is_flag=True, default=False)
@click.option('--period', type=int, default=2)
def generate_tasks_table(dburi, loop=False, period=2):
    """fill (periodically if needed) the tasks table used by the tasks view"""

    engine = create_engine(dburi)
    taskstable.refresh_tasks_file(engine, loop=loop, sleeptime=period)