Exemple #1
0
def main():
    # FIgure out what to delete.
    delete_submissions = raw_input(
        "Are you sure you want to delete all submissions? ") == "yes"
    delete_assignments = delete_submissions and raw_input(
        "Are you sure you want to delete all assignments? ") == "yes"
    delete_users = delete_assignments and raw_input(
        "Are you sure you want to delete all non-admin users? ") == "yes"
    delete_classes = delete_users and raw_input(
        "Are you sure you want to delete all classes? ") == "yes"

    # First we need to get mongoengine connected to our mongo installation
    import mongoengine
    mongoengine.connect("galah")

    from galah.base.config import load_config
    config = load_config("global")

    if delete_submissions:
        # Delete all of the submissions from the filesystem
        import subprocess
        print "Deleting all submissions from the filesystem..."
        subprocess.check_call(["rm", "-r", config["SUBMISSION_DIRECTORY"]])
    
        import galah.db.models as models

        # Delete all of the submissions from the database. Submissions point to
        # both users and assignments, so they must be deleted before both.
        print "Deleting all submissions from the database..."
        models.Submission.objects().delete()

    if delete_users:
        # Delete all of the non-admin users from the database. Users point to
        # classes.
        print "Deleting all non-admin users from the database..."
        models.User.objects(account_type__ne = "admin").delete()

    if delete_assignments:
        # Delete all of the assignments from the database. Assignments point to
        # classes.
        print "Deleting all assignments from the database..."
        models.Assignment.objects().delete()

    if delete_classes:
        # Delete all of the classes from the database.
        print "Deleting all classes from the database..."
        models.Class.objects().delete()
Exemple #2
0
def main():
    # FIgure out what to delete.
    delete_submissions = raw_input(
        "Are you sure you want to delete all submissions? ") == "yes"
    delete_assignments = delete_submissions and raw_input(
        "Are you sure you want to delete all assignments? ") == "yes"
    delete_users = delete_assignments and raw_input(
        "Are you sure you want to delete all non-admin users? ") == "yes"
    delete_classes = delete_users and raw_input(
        "Are you sure you want to delete all classes? ") == "yes"

    # First we need to get mongoengine connected to our mongo installation
    import mongoengine
    mongoengine.connect("galah")

    from galah.base.config import load_config
    config = load_config("global")

    if delete_submissions:
        # Delete all of the submissions from the filesystem
        import subprocess
        print "Deleting all submissions from the filesystem..."
        subprocess.check_call(["rm", "-r", config["SUBMISSION_DIRECTORY"]])
    
        import galah.db.models as models

        # Delete all of the submissions from the database. Submissions point to
        # both users and assignments, so they must be deleted before both.
        print "Deleting all submissions from the database..."
        models.Submission.objects().delete()

    if delete_users:
        # Delete all of the non-admin users from the database. Users point to
        # classes.
        print "Deleting all non-admin users from the database..."
        models.User.objects(account_type__ne = "admin").delete()

    if delete_assignments:
        # Delete all of the assignments from the database. Assignments point to
        # classes.
        print "Deleting all assignments from the database..."
        models.Assignment.objects().delete()

    if delete_classes:
        # Delete all of the classes from the database.
        print "Deleting all classes from the database..."
        models.Class.objects().delete()
Exemple #3
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Galah Group General Public License for more details.
#
# You should have received a copy of the Galah Group General Public License
# along with Galah.  If not, see <http://www.galahgroup.com/licenses>.

from galah.db.models import Assignment, Submission, Class, User
from bson import ObjectId
import os.path
import shutil
import errno

# Set up configuration and logging
from galah.base.config import load_config
config = load_config("sisyphus")

import logging
logger = logging.getLogger("galah.sisyphus.delete_assignments")

def _delete_assignments(ids, delete_class):
    if delete_class:
        delete_class = ObjectId(delete_class)

    # Convert all of the IDs we were given to ObjectIDs in one go
    ids = [ObjectId(i) for i in ids]

    logger.info("Deleting assignments %s.", str(ids))

    # Query the database for all the assignments we are supposed to delete
    assignments = list(Assignment.objects(id__in = ids))
Exemple #4
0
## The Actual View ##
from galah.web import app
from galah.web.auth import account_type_required
from bson.objectid import ObjectId
from bson.errors import InvalidId
from flask import abort, request, flash, redirect, url_for
from flask.ext.login import current_user
from galah.db.models import Submission, Assignment, TestResult
from galah.shepherd.api import send_test_request
from galah.web.util import is_url_on_site, GalahWebAdapter
import datetime
import logging

# Load Galah's configuration
from galah.base.config import load_config
config = load_config("shepherd")

logger = \
    GalahWebAdapter(logging.getLogger("galah.web.views.upload_submissions"))

@app.route("/assignments/<assignment_id>/resubmit/<submission_id>")
@account_type_required(("student", "teacher", "teaching_assistant"))
def resubmit_submission(assignment_id, submission_id):
    # Figure out which assignment the submission belongs to.
    try:
        assignment_id = ObjectId(assignment_id)
        assignment = Assignment.objects.get(id = assignment_id)
    except (InvalidId, Assignment.DoesNotExist) as e:
        logger.info("Could not retrieve assignment: %s", str(e))

        abort(404)
Exemple #5
0
from flask import Flask
app = Flask("galah.web")

from galah.base.config import load_config
app.config.update(load_config("web"))

oauth_enabled = bool(
    app.config.get("GOOGLE_SERVERSIDE_ID")
    and app.config.get("GOOGLE_SERVERSIDE_SECRET")
    and app.config.get("GOOGLE_APICLIENT_ID")
    and app.config.get("GOOGLE_APICLIENT_SECRET"))

import mongoengine
mongoengine.connect(app.config["MONGODB"])

# Plug the auth system into our app
from auth import login_manager
login_manager.setup_app(app)

import views
Exemple #6
0
import sys
import logging
from optparse import OptionParser, make_option

# galah external
from galah.core.objects import *
import galah.core.backends.redis

# internal
from galah.vmfactory.providers.vz import OpenVZProvider

log = logging.getLogger("galah.vmfactory")

# Parse the configuration file
from galah.base.config import load_config
config = load_config("")

def parse_arguments(args = sys.argv[1:]):
    option_list = [
        make_option(
            "--destroy-vms", action = "store_true", default = False,
            help =
                "If specified, the vmfactory will collect all galah-created "
                "VMs on the system and destroy them. This can be useful when "
                "changing VM templates or during testing. After destroying "
                "the VMs the VMFactory will exit."
        ),
        make_option(
            "--recover", action = "store_true", default = False,
            help =
                "If specified, the vmfactory will enter a recovery mode on "
Exemple #7
0
import galah.sheep.utility.universal as universal
import galah.sheep.utility.exithelpers as exithelpers
from galah.base.flockmail import FlockMessage
import threading
import logging
import consumer
import producer
import time
import zmq

# Load Galah's configuration.
from galah.base.config import load_config
config = load_config("sheep")

# Set up logging
import logging
logger = logging.getLogger("galah.sheep.maintainer")

poll_timeout = 10

# A counter used to generate names for consumer threads, not guarenteed to be
# the number of consumers currently extant.
_consumer_counter = 0
def start_consumer():
    global _consumer_counter

    consumerThread = threading.Thread(target = consumer.run,
                                      name = "consumer-%d" % _consumer_counter)
    consumerThread.start()

    _consumer_counter += 1
Exemple #8
0
                for j in item.get(i):
                    result.tests.append(SubTestResult.from_dict(j))

            elif i in item:
                result.__setattr__(i, item.get(i))

        # Make sure all the correct fields were given and formatted correctly.
        result.validate()

        return result

import os.path

# Load up the configuration so we know where the submission directory is
from galah.base.config import load_config
config = load_config("global")

class Submission(Document):
    assignment = ObjectIdField(required = True)
    user = StringField(required = True)
    timestamp = DateTimeField(required = True)
    most_recent = BooleanField()
    test_type = StringField(choices = ["public", "final"])
    test_results = ObjectIdField()
    test_request_timestamp = DateTimeField()

    # Each filename should be a path relative to the root of the archive they
    # uploaded if they uploaded an archive, otherwise each filename should be
    # just the filename. Include extensions.
    uploaded_filenames = ListField(StringField())
Exemple #9
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Galah Group General Public License for more details.
#
# You should have received a copy of the Galah Group General Public License
# along with Galah.  If not, see <http://www.galahgroup.com/licenses>.

import time
import datetime
from bson import ObjectId

from galah.db.models import Submission, Assignment

# Set up configuration and logging
from galah.base.config import load_config
from galah.shepherd.api import send_test_request
config = load_config("sisyphus")
shepherd_config = load_config("shepherd")

import logging
logger = logging.getLogger("galah.sisyphus.rerun_test_harness")

def _rerun_test_harness(assignment):
    try:
        # Get assignment
        assn = Assignment.objects.get(id = ObjectId(assignment))

        if not assn.test_harness:
            logger.info("Attempting to rerun test harnesses on assignment "
                        "with no test harnesses")
            return
Exemple #10
0
#!/usr/bin/env python

import threading

# Load Galah's configuration.
from galah.base.config import load_config
config = load_config("sheep")

# Set up logging
import logging
logger = logging.getLogger("galah.sheep")

import zmq
import galah.sheep.utility.universal as universal
universal.context = zmq.Context()

import Queue
universal.orphaned_results = Queue.Queue()

# Initialize the correct consumer based on the selected virtual suite.
from galah.sheep.utility.suitehelpers import get_virtual_suite
virtual_suite = get_virtual_suite(config["VIRTUAL_SUITE"])
virtual_suite.setup(logger)

# Start the maintainer (who will start up the other threads)
import galah.sheep.components as components
maintainer = threading.Thread(target=components.maintainer.run,
                              args=(config["NCONSUMERS"], ),
                              name="maintainer")
maintainer.start()
Exemple #11
0
from mongoengine import *

# Load up the configuration for the email validation regular expression
from galah.base.config import load_config
config = load_config("global")


class User(Document):
    email = EmailField(unique=True,
                       primary_key=True,
                       regex=config["EMAIL_VALIDATION_REGEX"])
    seal = StringField()
    account_type = StringField(
        choices=["student", "teaching_assistant", "teacher", "admin"],
        required=True)
    classes = ListField(ObjectIdField())

    # The individual cutoff date
    personal_deadline = MapField(DateTimeField())

    # The individual due date
    personal_due_date = MapField(DateTimeField())

    meta = {"indexes": ["email", "classes"], "allow_inheritance": False}
Exemple #12
0
import galah.sheep.utility.exithelpers as exithelpers
from galah.sheep.utility.testrequest import PreparedTestRequest
import pyvz
import time
import Queue
import socket
import os
import os.path
import json
import datetime

# Load Galah's configuration.
from galah.base.config import load_config
config = load_config("sheep/vz")

containers = Queue.Queue(maxsize = config["MAX_MACHINES"])

# Performs one time setup for the entire module. Cannot be a member function of
# producer because it needs to be called once at startup, and the producer class
# would not have been made yet.
def setup(logger):
    if config["MAX_MACHINES"] == 0:
        logger.warning(
            "MAX_MACHINES is 0. Infinitely many virtual machines will be "
            "created. If this is not what you want (which it probably isn't), "
            "stop this sheep and edit the configuration file."
        )

    # Get a list of all of the clean virtual machines that already exist
    clean_machines = pyvz.get_containers("galah-vm: clean")
Exemple #13
0
import galah.sheep.utility.exithelpers as exithelpers
from galah.sheep.utility.testrequest import PreparedTestRequest
import pyvz
import time
import Queue
import socket
import os
import os.path
import json
import datetime

# Load Galah's configuration.
from galah.base.config import load_config

config = load_config("sheep/vz")

containers = Queue.Queue(maxsize=config["MAX_MACHINES"])


# Performs one time setup for the entire module. Cannot be a member function of
# producer because it needs to be called once at startup, and the producer class
# would not have been made yet.
def setup(logger):
    if config["MAX_MACHINES"] == 0:
        logger.warning(
            "MAX_MACHINES is 0. Infinitely many virtual machines will be "
            "created. If this is not what you want (which it probably isn't), "
            "stop this sheep and edit the configuration file.")

    # Get a list of all of the clean virtual machines that already exist
    clean_machines = pyvz.get_containers("galah-vm: clean")
Exemple #14
0
## The Actual View ##
from galah.web import app
from flask.ext.login import current_user
from galah.web.auth import account_type_required
from bson.objectid import ObjectId
from bson.errors import InvalidId
from flask import abort, render_template, get_flashed_messages, request
from galah.db.models import Assignment, Submission, TestResult, User
from galah.base.pretty import pretty_time
from galah.web.util import create_time_element, GalahWebAdapter
import datetime
import logging

# Load Galah's configuration
from galah.base.config import load_config
config = load_config("web")

logger = GalahWebAdapter(logging.getLogger("galah.web.views.view_assignment"))


# Custom filter to output submission timestamp in ISO format
def isoformat(datetime):
    import re
    # Date String is close enough, just replace three trailing zeroes with Z
    datestring = datetime.isoformat()
    return re.sub(r"000$", "Z", datestring)


app.jinja_env.filters['isoformat'] = isoformat

Exemple #15
0
## The Actual View ##
from galah.web import app
from galah.web.auth import account_type_required
from bson.objectid import ObjectId
from bson.errors import InvalidId
from flask import abort, request, flash, redirect, url_for
from flask.ext.login import current_user
from galah.db.models import Submission, Assignment, TestResult
from galah.shepherd.api import send_test_request
from galah.web.util import is_url_on_site, GalahWebAdapter
import datetime
import logging

# Load Galah's configuration
from galah.base.config import load_config
config = load_config("shepherd")

logger = \
    GalahWebAdapter(logging.getLogger("galah.web.views.upload_submissions"))

@app.route("/assignments/<assignment_id>/resubmit/<submission_id>")
@account_type_required(("student", "teacher", "teaching_assistant"))
def resubmit_submission(assignment_id, submission_id):
    # Figure out which assignment the submission belongs to.
    try:
        assignment_id = ObjectId(assignment_id)
        assignment = Assignment.objects.get(id = assignment_id)
    except (InvalidId, Assignment.DoesNotExist) as e:
        logger.info("Could not retrieve assignment: %s", str(e))

        abort(404)
Exemple #16
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Galah Group General Public License for more details.
#
# You should have received a copy of the Galah Group General Public License
# along with Galah.  If not, see <http://www.galahgroup.com/licenses>.

from flask import Flask
app = Flask("galah.web")

# Hack to work around the destruction of error handlers by Flask's deferred
# processing.
app.logger_name = "nowhere"
app.logger

from galah.base.config import load_config
app.config.update(load_config("web"))

oauth_enabled = bool(
    app.config.get("GOOGLE_SERVERSIDE_ID") and
    app.config.get("GOOGLE_SERVERSIDE_SECRET") and
    app.config.get("GOOGLE_APICLIENT_ID") and
    app.config.get("GOOGLE_APICLIENT_SECRET")
)

cas_enabled = bool(
    app.config.get("CAS_SERVER_URL")
)

import mongoengine
mongoengine.connect(app.config["MONGODB"])
Exemple #17
0
from galah.web import app
from flask.ext.login import current_user
from galah.web.auth import account_type_required
from bson.objectid import ObjectId
from bson.errors import InvalidId
from flask import abort, render_template, get_flashed_messages, request
from galah.db.models import Assignment, Submission, TestResult, User
from galah.base.pretty import pretty_time
from galah.web.util import create_time_element, GalahWebAdapter
import datetime
import logging

# Load Galah's configuration
from galah.base.config import load_config

config = load_config("web")

logger = GalahWebAdapter(logging.getLogger("galah.web.views.view_assignment"))

# Custom filter to output submission timestamp in ISO format
def isoformat(datetime):
    import re

    # Date String is close enough, just replace three trailing zeroes with Z
    datestring = datetime.isoformat()
    return re.sub(r"000$", "Z", datestring)


app.jinja_env.filters["isoformat"] = isoformat

Exemple #18
0
import shutil
import subprocess
import os
import datetime
import os.path
from bson import ObjectId

from galah.db.models import Submission, CSV, TestResult, User, Assignment

# Set up configuration and logging
from galah.base.config import load_config
config = load_config("sisyphus")

import logging
logger = logging.getLogger("galah.sisyphus.create_assignment_csv")


def _create_assignment_csv(csv_id, requester, assignment):
    csv_id = ObjectId(csv_id)

    csv_file = temp_directory = ""

    # Find any expired archives and remove them
    deleted_files = []
    for i in CSV.objects(expires__lt=datetime.datetime.today()):
        deleted_files.append(i.file_location)

        if i.file_location:
            try:
                os.remove(i.file_location)
            except OSError as e:
Exemple #19
0
import time
import datetime
from bson import ObjectId

from galah.db.models import Submission, Assignment

# Set up configuration and logging
from galah.base.config import load_config
from galah.shepherd.api import send_test_request
config = load_config("sisyphus")
shepherd_config = load_config("shepherd")

import logging
logger = logging.getLogger("galah.sisyphus.rerun_test_harness")

def _rerun_test_harness(assignment):
    try:
        # Get assignment
        assn = Assignment.objects.get(id = ObjectId(assignment))

        if not assn.test_harness:
            logger.info("Attempting to rerun test harnesses on assignment "
                        "with no test harnesses")
            return

        # Form the submissions query
        query = {
            "assignment": ObjectId(assignment),
            "most_recent": True
        }