def read_static_dir(course_key): ''' Reads static_dir from course configuration. ''' sys.path.append(os.path.dirname(os.path.dirname( os.path.abspath(__file__)))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "grader.settings") from access.config import ConfigParser config = ConfigParser() course = config.course_entry(course_key) if 'static_dir' in course: return course['static_dir'] return ''
def handle(self, *args, **options): config = ConfigParser() # Check arguments. if len(args) < 1 or "/" not in args[0]: raise CommandError("Required arguments missing: course_key/exercise_key") course_key, exercise_key = args[0].split("/", 1) # Get exercise configuration. (course, exercise) = config.exercise_entry(course_key, exercise_key) if course is None: raise CommandError("Course not found for key: %s" % (course_key)) if exercise is None: raise CommandError("Exercise not found for key: %s/%s" % (course_key, exercise_key)) self.stdout.write('Exercise configuration retrieved.') # Check exercise type. if not "actions" in exercise: raise CommandError("Cannot grade: exercise does not configure asynchronous actions") # Create submission. sdir = create_submission_dir(course, exercise) if len(args) == 1: os.makedirs(sdir + "/user") for n in range(1, len(args)): name = args[n] # Copy individual files. if os.path.isfile(name): submit_path = submission_file_path(sdir, os.path.basename(name)) shutil.copy2(name, submit_path) # Copy a directory. elif os.path.isdir(name): if len(args) != 2: raise CommandError("Can only submit one directory or multiple files.") shutil.copytree(name, sdir + "/user", True) else: raise CommandError("Submit file not found: %s" % (name)) # Run actions. r = runactions(course, exercise, sdir) self.stdout.write("Response body:") self.stdout.write(template_to_str(course, exercise, "", r["template"], r["result"]))
def setUp(self): import access settings.COURSES_PATH = os.path.join(os.path.dirname(__file__), 'test_data') self.config = ConfigParser()
def setUp(self): self.config = ConfigParser()
def setUp(self): import access access.config.DIR = os.path.join(os.path.dirname(__file__), 'test_data') self.config = ConfigParser()