def delete_course_and_groups(course_key, user_id):
 module_store = modulestore()
 with module_store.bulk_operations(course_key):
  module_store.delete_course(course_key, user_id)
  print 'removing User permissions from course....'
  try:
   remove_all_instructors(course_key)
  except Exception as err:
   log.error('Error in deleting course groups for {0}: {1}'.format(course_key, err))

def delete_course_and_groups ( course_key , user_id ) : module_store = modulestore ( ) with module_store . bulk_operations ( course_key ) : module_store . delete_course ( course_key , user_id ) print 'removing User permissions from course....' try : remove_all_instructors ( course_key ) except Exception as err : log . error ( 'Error in deleting course groups for {0}: {1}' . format ( course_key , err ) )
this deletes the courseware associated with a course_key as well as cleaning update_item the various user table stuff .