Skip to content

Reference

Roger Chen edited this page Feb 6, 2016 · 10 revisions

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: 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);

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