Skip to content

Reference

Roger Chen edited this page Aug 24, 2016 · 10 revisions

Adding a student roster

See the main article on student rosters.

Useful Python functions

Generate a list of class logins

import string
import itertools

def generate_login_list(num, minimum_length=2):
    """
    Generates a list of class logins, starting with 2-letter logins. Does not include logins that
    start with 't' or 'r'.

    >>> generate_login_list(3)
    ['aa', 'ab', 'ac']

    """
    accounts = []
    alph = string.lowercase
    non_reserved = lambda account: account[0] not in ('t', 'r')
    for length in itertools.count(minimum_length):
        accounts.extend(map(''.join, filter(non_reserved, itertools.product(alph, repeat=length))))
        if len(accounts) >= num:
            return accounts[:num]

Feature: The IPython shell (autograder-shell)

If you run ob2 with the --ipython switch, it will open a IPython shell for you to run administrative tasks. As an example:

#!/bin/bash

# Use our virtualenv
source "/srv/virtualenv/ob2/bin/activate"

# Get into the ob2 directory
cd "/srv/ob2/"

# Start ob2 with --ipython, using our autograder configuration directories
python -m ob2 --ipython -C "/srv/autograder/" -C "/srv/ob2_production_config/"

Once inside the ob2 shell, you can import and run a lot of the ob2 functions, which will be helpful for various administrative tasks. For example, here is how you might get a list of repos in your GitHub organization:

# The _get_github_admin function is already imported from ob2.util.github_api
github = _get_github_admin()

org = github.organization(config.github_organization)
repos = list(org.iter_repos())

Feature: Student photos

When students register, they can be prompted to upload a photo of themselves using this student photos feature. This feature can be enabled or disabled using the student_photos_enabled configuration option.

A client-sided photo cropper is bundled with ob2, which uses Canvas2D to crop photos into a square. The photos are stored in the photo column of the users table.

Feature: Account forms

You can add support for instructional account forms by enabling the inst_account_enabled configuration option. At UC Berkeley, each student in an EECS course receives an instructional account form PDF, which contains a username and password for their instructional course account. The usernames for CS162 take the form cs162-aa, where the "aa" is varied between different students. These accounts can be used to log in to instructional computing resources.

Every student needs a unique value for the login field, regardless of whether the account forms feature is used. (This is because the login is use as the GitHub repository name.)

If you would also like to use the account forms feature, you just need to configure the inst_account_forms_path configuration option to point to a directory with account forms PDFs in the form of aa.pdf, ab.pdf, etc.

(Note: Filesystem paths are always relative to the configuration root.)

config.yaml

inst_account_enabled: true
inst_account_forms_path: "inst_account_forms/"

Then, inside inst_account_forms/, you should place your account form PDFs. Octobear 2 will validate the existence of required account forms when it starts up. Check out the example ob2 configuration for a full example.

Feature: Staff accounts

There is a super column in the users table, to allow you to distinguish staff accounts from student accounts. A non-zero value of super has the following effects:

  • Shows "(Staff)" next to the user's name in the TA interface
  • Excludes grades from statistics (ranking, histogram, etc)

Student accounts should have a super value of 0.

Here is an example query that could be used to create a staff account:

INSERT INTO users (id, name, sid, login, github, email, super, grouplimit, photo)
VALUES (1, "Peter Perfect", "1620000", "ta", "peterperfect162", "cs162@eecs.berkeley.edu", 1, 0, NULL);

Configuring Email

To configure the email system, you'll need to register a filter on the connect-to-smtp hook. For example, you can insert this code in your functions.py to tell ob2 to connect to a local mail daemon on the loopback interface:

# This function lets you tell ob2 how to connect to your SMTP server. Our cs162.eecs server has a
# mail exchanger listening on 0.0.0.0:25, so we'll just use that one.
@register_filter("connect-to-smtp")
def cs162_connect_to_smtp(smtp_obj):
    """
    Given an instance of smtplib.SMTP, connect and/or authenticate with the desired mail exchanger
    used to send mail. Returns smtp_obj (or a compatible object).

    """

    smtp_obj.connect("127.0.0.1")
    return smtp_obj

Creating groups manually

There are only 2 steps to creating a group manually:

  • Modify the database
  • Create the GitHub repository for the group

You can just insert new groups into the groupsusers table, but make sure to update the group_next_group_number as well!

-- Create a new group named "group11" with 2 users.
INSERT INTO groupsusers (`group`, user) VALUES ("group11", 123), ("group11", 321);

-- Update the auto-incrementing "group_next_group_number" value
-- NOTE: This value is the LARGEST EXISTING GROUP NUMBER. The name is misleading, sorry.
UPDATE options SET value = 11 WHERE key = "group_next_group_number" LIMIT 1;

Then, use the autograder-shell to create their GitHub repo;

from ob2.util.github_api import _assign_repo

# Assigns a repo named "group11" to 2 collaborators
# The "group11" repo will be created if it doesn't exist.
# The GitHub users "username1" and "username2" will be added to the repo
# Existing collaborators will NOT be deleted.
_assign_repo("group11", ["username1", "username2"])

Adding a member to an existing group

You can add a member to an existing group with 2 steps:

  • Insert them into the database
  • Add them to the GitHub repo
-- Add a user with ID 123 to group11
INSERT INTO groupsusers (`group`, user) VALUES ("group11", 123);

Then, use the autograder-shell to give them access to the existing GitHub repo;

from ob2.util.github_api import _assign_repo

# Assigns a repo named "group11" to 1 student with GitHub username "rogerhub"
# Existing collaborators will NOT be deleted.
_assign_repo("group11", ["rogerhub"])

Clone this wiki locally