#!/usr/bin/python
#
# File:   create_groups.py
#
# Create all staff_* groups for classes in data directory.

import os, sys, string, re

sys.path.append(os.path.abspath('.'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'lms.envs.dev'

try:
    from lms.envs.dev import *
except Exception as err:
    print "Run this script from the top-level mitx directory (mitx_all/mitx), not a subdirectory."
    sys.exit(-1)

from django.conf import settings
from django.contrib.auth.models import User, Group
from path import path

data_dir = settings.DATA_DIR
print "data_dir = %s" % data_dir

for course_dir in os.listdir(data_dir):
    # print course_dir
    if not os.path.isdir(path(data_dir) / course_dir):
        continue
    gname = 'staff_%s' % course_dir
    if Group.objects.filter(name=gname):
        print "group exists for %s" % gname
        continue
    g = Group(name=gname)
    g.save()
    print "created group %s" % gname

@@ -506,16 +506,39 @@
 ort path
+%0Afrom lxml import etree
 %0A%0Adata_d
@@ -725,24 +725,353 @@
    continue%0A
+    %0A    cxfn = path(data_dir) / course_dir / 'course.xml'%0A    coursexml = etree.parse(cxfn)%0A    cxmlroot = coursexml.getroot()%0A    course = cxmlroot.get('course')%0A    if course is None:%0A        print %22oops, can't get course id for %25s%22 %25 course_dir%0A        continue%0A    print %22course=%25s for course_dir=%25s%22 %25 (course,course_dir)%0A%0A
     gname = 
@@ -1085,28 +1085,24 @@
 %25s' %25 course
-_dir
 %0A    if Grou

update utility script to create course groups