from btray import db
from btray.models import User, WebhookConfig, WebhookResponse

import sys
from getpass import getpass

def usage_and_quit():
    print "Usage: python db.py [install | reset | drop | adduser]"
    exit()

if len(sys.argv) != 2:
    usage_and_quit()

command = sys.argv[1]
print "Received command: %s" % command

if command not in ["install", "reset","drop","adduser"]:
    usage_and_quit()

if command in ["reset","drop"]:
    db.drop_all()
    print("Database cleaned")

if command in ["reset","install"]:
    db.create_all()
    print("Database initialized")

if command == "adduser":
    username = raw_input("Username: ")
    email = raw_input("Email: ")
    password = getpass("Password: ")
    db.session.add(User(username,email,password))

db.session.commit()
print("Committed")


@@ -13,17 +13,22 @@
 mport db
+, app
 %0A
-
 from btr
@@ -82,16 +82,52 @@
 sponse%0A%0A
+from random import sample as sample%0A
 import s
@@ -244,16 +244,27 @@
  adduser
+ %7C generate
 %5D%22%0A    e
@@ -431,16 +431,28 @@
 adduser%22
+, %22generate%22
 %5D:%0A    u
@@ -769,24 +769,24 @@
 assword: %22)%0A
-
     db.sessi
@@ -824,16 +824,1055 @@
 word))%0A%0A
+if command == %22generate%22:%0A    if app.config%5B%22ENVIRONMENT%22%5D == %22production%22:%0A        raise Exception(%22Cannot generate in production%22)%0A%0A    words = %5B%22Horse%22, %22Zenith%22, %22Goose%22, %22Farmer%22, %22Obsidian%22,%0A        %22Grapefruit%22, %22Martian%22, %22Coal%22, %22Morlock%22%5D%0A%0A    password = app.config.get(%22TESTING_USER_PASSWORD%22, None)%0A    if password is None:%0A        password = getpass(%22Password for 'user': %22)%0A%0A    user = User(%22user%22, %22user@example.com%22, password)%0A    for i in range(0,10):%0A        webhook_config = WebhookConfig(%0A            name=%22 %22.join(sample(words, 4)),%0A            notes=%22%5Cn%22.join(sample(words,6)),%0A            bt_merchant_id=%22abc%25s%22 %25 i,%0A            bt_public_key=%22def%25s%22 %25 i,%0A            bt_private_key=%22ghi%25s%22 %25 i%0A        )%0A        user.webhook_configs.append(webhook_config)%0A%0A        for j in range(0, 15):%0A            webhook_config.parse_webhook_response('VGhpcyBpcyBhIHRlc3QNClRoaXMgaXMgb25seSBhIHRlc3QNCklmIHlvdSB0cnkgYW55dGhpbmcgZnVubnkgaXQgd2lsbCBlbmQgcG9vcmx5Lg==','fake-valid-signature-for-testing')%0A    db.session.add(user)%0A%0A
 db.sessi

Add Generate script to gin up a user with data.