Skip to content

Instantly share code, notes, and snippets.

@atelic
Created August 11, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atelic/b317dbae4e4cd0049badf10f249bcca1 to your computer and use it in GitHub Desktop.
Save atelic/b317dbae4e4cd0049badf10f249bcca1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from invoke import run, task
@task(aliases=['a'])
def assets(ctx, watch=False):
cmd = './node_modules/.bin/webpack --colors --progress'
if watch:
cmd += ' --watch'
run(cmd, echo=True)
@task(aliases=['c'])
def clean(ctx):
cmd = 'find . -name "*.pyc" -delete'
run(cmd, echo=True)
@task
def credentials(ctx):
content = """config = {
# Put your FAS credentials here...
# but leave them commented out. Note that, if you leave your fas
# credentials out, some widgets won't be as accurate as they could be..
# but it also makes the app faster than it would otherwise be (which is
# nice for development).
#'fas_credentials': {
# 'username': 'YOUR_FAS_USERNAME',
# 'password': 'YOUR_FAS_PASSWORD',
#},
# Go and generate a token for this here:
# https://github.com/settings/tokens
'github.oauth_token': 'YOUR_GITHUB_TOKEN',
}"""
run('touch fedmsg.d/credentials.py', echo=True)
print('Writing credential template')
print(content)
with open('fedmsg.d/credentials.py', 'w') as fp:
fp.write(content)
@task(aliases=['flake8'])
def flake(ctx):
run('flake8 .', echo=True)
@task
def populate(ctx):
run('python populate.py', echo=True)
@task(aliases=['rdb'])
def restart_db(ctx, serve=False):
cmd = 'rm /var/tmp/hubs.db;\
rm /var/tmp/fedora-hubs-cache.db;\
PYTHONPATH=. python populate.py;'
if serve:
cmd += 'gunicorn -w 8 -t 240 --log-config logging.ini hubs.app:app'
run(cmd, echo=True)
@task(aliases=['req'])
def requirements(ctx, test=False):
run('pip install -r requirements.txt', echo=True)
if test:
run('pip install -r test-requirements.txt', echo=True)
@task(aliases=['s', 'serve'])
def server(ctx, gunicorn=False, log=False, config=True):
cmd = ''
if gunicorn:
cmd = 'gunicorn -w 8 -t 240 --log-config logging.ini hubs.app:app'
elif config:
cmd = 'python runserver.py -c config'
else:
cmd = 'python runserver.py'
if log:
cmd += ' >>log 2>&1'
run(cmd, echo=True)
@task
def shell(ctx):
'''
required:
pip install ipython
'''
import requests
import fedmsg.config
import fedmsg.meta
import hubs.models
import hubs.widgets.base
from hubs.app import app
fedmsg_config = fedmsg.config.load_config()
fedmsg.meta.make_processors(**fedmsg_config)
session = hubs.models.init(fedmsg_config['hubs.sqlalchemy.uri'])
context = {
'requests': requests,
'fedmsg_config': fedmsg_config,
'session': session,
'models': hubs.models,
'widgets.base': hubs.widgets.base,
'app': app
}
try:
try:
# 0.10.x
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell(global_ns={}, local_ns=context)
except ImportError:
# 0.12+
from IPython import embed
embed(user_ns=context)
return
except ImportError:
pass
@task
def stream(ctx):
cmd = 'python ev-server/hubs-stream-server.py'
run(cmd, echo=True)
@task(aliases=['t', 'tests'])
def test(ctx, coverage=False):
cmd = 'PYTHON_PATH=. nosetests '
if coverage:
cmd += '--with-coverage --cover-erase --cover-package=hubs --cover-html'
run(cmd, echo=True)
@task(default=True)
def usage(ctx):
run('invoke --list')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment