Ejemplo n.º 1
0
def main(cli_args=None):
    """Main function to implement command-line interface"""
    if cli_args is None:
        cli_args = sys.argv[1:]

    args = parse_args(cli_args)

    # Print defined parameters
    v = dict(vars(args))
    to_delete = [k for k in v if v[k] is None]
    for k in to_delete:
        v.pop(k, None)  # Remove undefined parameters
    v["version"] = pkg_resources.get_distribution("seaflowpy").version
    print "Defined parameters:"
    print json.dumps(v, indent=2)
    print ""

    # Find EVT files
    if args.evt_dir:
        files = evt.find_evt_files(args.evt_dir)
    elif args.s3:
        # Make sure configuration for s3 is ready to go
        config = conf.get_aws_config(s3_only=True)
        cloud = clouds.AWS(config.items("aws"))
        # Make sure try to access S3 up front to setup AWS credentials before
        # launching child processes.
        try:
            files = cloud.get_files(args.cruise)
            files = evt.parse_file_list(files)  # Only keep EVT files
        except botocore.exceptions.NoCredentialsError as e:
            print "Please configure aws first:"
            print "  $ conda install aws"
            print "  or"
            print "  $ pip install aws"
            print "  then"
            print "  $ aws configure"
            sys.exit(1)

    # Restrict length of file list with --limit
    if (not args.limit is None) and (args.limit > 0):
        files = files[:args.limit]

    filter_keys = ["notch1", "notch2", "width", "offset", "origin"]
    filter_options = dict((k, getattr(args, k)) for k in filter_keys)

    # Filter
    if args.twopass:
        filterer = filterevt.two_pass_filter
    else:
        filterer = filterevt.filter_evt_files
    filterer(files, args.cruise, filter_options, args.db,
             args.opp_dir, s3=args.s3, process_count=args.process_count,
             every=args.resolution)

    # Index
    if args.db:
        db.ensure_indexes(args.db)
Ejemplo n.º 2
0
    def setUp(self):
        db.users_coll.drop();
        db.questions_coll.drop()
        db.ensure_indexes()

        question_mod.init(flush=True)

        db.create_user('dan', 'no password')
        self.dan_user = user_mod.User.from_username('dan')
Ejemplo n.º 3
0
    def setUp(self):
        db.users_coll.drop();
        db.questions_coll.drop()
        db.ensure_indexes()

        db.create_user('dan', 'no password')
        self.dan_user = user_mod.User.from_username('dan')

        db.create_user('sean', 'i love dan irl')
        question_doc = db.insert_question('question #1', 'correct answer', 'wrong1', 'wrong2', 'wrong3')
        self.question1 = question_mod.Question.from_doc(question_doc)

        self.sean_user = user_mod.User.from_username('sean')
        self.sean_user.add_demographic('masculinity', True)
        self.sean_user.add_demographic('favorite_food', 'pancakes in a bowl')
        self.sean_user.add_demographic('hair color', 'red')
Ejemplo n.º 4
0
def main(cli_args=None):
    """Main function to implement command-line interface"""
    if cli_args is None:
        cli_args = sys.argv[1:]

    args = parse_args(cli_args)

    db.ensure_tables(args.db)
    db.ensure_indexes(args.db)

    if args.evt_dir:
        # Try to insert all SFl files in EVT dir
        insert_files_recursive(
            args.db, args.evt_dir, args.cruise, gga=args.gga, west=args.west)
    else:
        # User specified SFL file
        insert_files(
            [args.sfl], args.db, args.cruise, gga=args.gga, west=args.west)
Ejemplo n.º 5
0
def main(cli_args=None):
    """Main function to implement command-line interface"""
    if cli_args is None:
        cli_args = sys.argv[1:]

    args = parse_args(cli_args)

    db.ensure_tables(args.db)
    db.ensure_indexes(args.db)

    if args.evt_dir:
        # Try to insert all SFl files in EVT dir
        insert_files_recursive(args.db,
                               args.evt_dir,
                               args.cruise,
                               gga=args.gga,
                               west=args.west)
    else:
        # User specified SFL file
        insert_files([args.sfl],
                     args.db,
                     args.cruise,
                     gga=args.gga,
                     west=args.west)
Ejemplo n.º 6
0
from bson.objectid import ObjectId, InvalidId
from flask import Flask, request, jsonify
from pymongo.errors import DuplicateKeyError

import question_mod
import random
import user_mod
import db
import sha

app = Flask(__name__)
db.ensure_indexes()

def get_oid(oid_str):
    if not oid_str:
        return None, "No id string"

    try:
        oid = ObjectId(oid_str)
    except InvalidId:
        return None, "Invalid id string"

    return oid, None

def hash_password(password):
    salted = "this is my " + password + " salting secret key"
    return sha.sha(salted).hexdigest()

@app.route("/create_user", methods=["GET"])
def create_user():
    username = request.args.get("username", None)
Ejemplo n.º 7
0
@app.route('/error')
def error():
    return "Error!"


@app.errorhandler(404)
def page_not_found(e):
    try:
        url = request.url
    except Exception:
        url = ""
    return render_template('404.html', url=url), 404


app.jinja_env.globals['csrf_field'] = csrf_field
with open(join(dirname(__file__), "../config.json")) as f:
    config = load(f)

redis = Redis()
db.init(connect_db(config), redis)
db.ensure_indexes()

app.secret_key = config["secret_key"]
app.session_cookie_name = "SESSION_ID"
app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024
app.session_interface = RedisSessionManager(redis)

if __name__ == "__main__":
    app.run("0.0.0.0", 10000, debug=True)