# Path: mothership/forms.py
# class CampaignForm(Form):
# class MakeTestsForm(Form):
# 	def validate(self):
# 	def validate(self):
# 
# Path: mothership/models.py
# def init_db():
# 	def process_bind_param(self, value, dialect):
# 	def process_result_value(self, value, dialect):
# 	def get(cls, **kwargs):
# 	def all(cls, **kwargs):
# 	def create(cls, **kwargs):
# 	def put(self):
# 	def delete(self):
# 	def commit():
# 	def update(self, **kwargs):
# 	def update_all(cls, **kwargs):
# 	def to_dict(self):
# 	def children(self):
# 	def __init__(self, name):
# 	def started(self):
# 	def active_fuzzers(self):
# 	def master_fuzzer(self):
# 	def num_executions(self):
# 	def num_crashes(self):
# 	def bitmap_cvg(self):
# 	def name(self):
# 	def campaign(self):
# 	def started(self):
# 	def running(self):
# class JsonType(types.TypeDecorator):
# class Model:
# class Campaign(Model, db.Model):
# class FuzzerInstance(Model, db.Model):
# class FuzzerSnapshot(Model, db.Model):
# class Crash(Model, db.Model):
# 
# Path: mothership/utils.py
# def format_timedelta_secs(secs, time_format='{days} days {hours} hours {minutes} minutes'):
# 	return format_timedelta(datetime.timedelta(seconds=secs), time_format=time_format)
# 
# def pretty_size_dec(value):
# 	return pretty_size(value, b=1000, u = '', pre = ['', 'Thousand', 'Million', 'Billion'])
# 
# def format_ago(current_time, ago):
# 	return (format_timedelta_secs(current_time - ago) + ' ago') if ago else 'none so far',


import shutil
import subprocess
import time
import os
import sqlalchemy
from flask import Blueprint, render_template, render_template_string, flash, redirect, request, url_for, jsonify, current_app
from datetime import datetime
from sqlalchemy import case
from werkzeug.utils import secure_filename
from mothership import forms, models
from mothership.utils import format_timedelta_secs, pretty_size_dec, format_ago




campaigns = Blueprint('campaigns', __name__)


@campaigns.route('/')
def list_campaigns():
	if not os.path.exists(os.path.join(current_app.config['DATA_DIRECTORY'], 'libdislocator.so')):
		flash('Missing libdislocator.so', 'danger')
	if not os.path.exists(os.path.join(current_app.config['DATA_DIRECTORY'], 'afl-fuzz')):
		flash('Missing afl-fuzz', 'danger')
	return render_template('campaigns.html', campaigns=models.Campaign.all(parent_id=None))

@campaigns.route('/campaigns/new', methods=['GET', 'POST'])
def new_campaign():

# Path: mothership/forms.py
# class CampaignForm(Form):
# class MakeTestsForm(Form):
# 	def validate(self):
# 	def validate(self):
# 
# Path: mothership/models.py
# def init_db():
# 	def process_bind_param(self, value, dialect):
# 	def process_result_value(self, value, dialect):
# 	def get(cls, **kwargs):
# 	def all(cls, **kwargs):
# 	def create(cls, **kwargs):
# 	def put(self):
# 	def delete(self):
# 	def commit():
# 	def update(self, **kwargs):
# 	def update_all(cls, **kwargs):
# 	def to_dict(self):
# 	def children(self):
# 	def __init__(self, name):
# 	def started(self):
# 	def active_fuzzers(self):
# 	def master_fuzzer(self):
# 	def num_executions(self):
# 	def num_crashes(self):
# 	def bitmap_cvg(self):
# 	def name(self):
# 	def campaign(self):
# 	def started(self):
# 	def running(self):
# class JsonType(types.TypeDecorator):
# class Model:
# class Campaign(Model, db.Model):
# class FuzzerInstance(Model, db.Model):
# class FuzzerSnapshot(Model, db.Model):
# class Crash(Model, db.Model):
# 
# Path: mothership/utils.py
# def format_timedelta_secs(secs, time_format='{days} days {hours} hours {minutes} minutes'):
# 	return format_timedelta(datetime.timedelta(seconds=secs), time_format=time_format)
# 
# def pretty_size_dec(value):
# 	return pretty_size(value, b=1000, u = '', pre = ['', 'Thousand', 'Million', 'Billion'])
# 
# def format_ago(current_time, ago):
# 	return (format_timedelta_secs(current_time - ago) + ' ago') if ago else 'none so far',


# Path: mothership/controllers/campaigns.py
import shutil
import subprocess
import time
import os
import sqlalchemy
from flask import Blueprint, render_template, render_template_string, flash, redirect, request, url_for, jsonify, current_app
from datetime import datetime
from sqlalchemy import case
from werkzeug.utils import secure_filename
from mothership import forms, models
from mothership.utils import format_timedelta_secs, pretty_size_dec, format_ago





campaigns = Blueprint('campaigns', __name__)


@campaigns.route('/')
def list_campaigns():
	if not os.path.exists(os.path.join(current_app.config['DATA_DIRECTORY'], 'libdislocator.so')):
		flash('Missing libdislocator.so', 'danger')
	if not os.path.exists(os.path.join(current_app.config['DATA_DIRECTORY'], 'afl-fuzz')):
		flash('Missing afl-fuzz', 'danger')
	return render_template('campaigns.html', campaigns=models.Campaign.all(parent_id=None))

@campaigns.route('/campaigns/new', methods=['GET', 'POST'])
def new_campaign():

	form = forms.CampaignForm()