示例#1
0
 def refresh_attempts(self, attempts=None, student_visible=None, refresh_all=False):
     """Bulk-refresh all missing assignment data."""
     attempt_keys = []
     students = self.students.values()
     if attempts is None:
         if student_visible is not None:
             students = list(filter(student_visible, students))
         for user in students:
             for assignment_id, assignment in user.assignments.items():
                 if refresh_all or assignment.cached_attempts is None:
                     attempt_keys.append((user.id, assignment_id))
     else:
         attempt_ids = set(attempt.id for attempt in attempts)
         for user in students:
             for assignment_id, assignment in user.assignments.items():
                 a = assignment.cached_attempts or []
                 if any(attempt.id in attempt_ids for attempt in a):
                     attempt_keys.append((user.id, assignment_id))
     if not attempt_keys:
         return
     logger.info("Fetching %d attempt list%s",
                 len(attempt_keys), '' if len(attempt_keys) == 1 else 's')
     attempt_data = dwr_get_attempts_info(self.session, attempt_keys)
     for (user_id, aid), attempts in zip(attempt_keys, attempt_data):
         self.students[user_id]['assignments'][aid]['attempts'] = attempts
示例#2
0
文件: grading.py 项目: kse/bbfetch
 def refresh(self):
     logger.info("Refresh gradebook")
     self.gradebook.refresh()
     if not self.attempt_state:
         self.attempt_state = {}
     self.groups = fetch_groups(self.session)
     self.autosave()
示例#3
0
 def refresh_attempts(self,
                      attempts=None,
                      student_visible=None,
                      refresh_all=False):
     """Bulk-refresh all missing assignment data."""
     attempt_keys = []
     students = self.students.values()
     if attempts is None:
         if student_visible is not None:
             students = list(filter(student_visible, students))
         for user in students:
             for assignment_id, assignment in user.assignments.items():
                 if refresh_all or assignment.cached_attempts is None:
                     attempt_keys.append((user.id, assignment_id))
     else:
         attempt_ids = set(attempt.id for attempt in attempts)
         for user in students:
             for assignment_id, assignment in user.assignments.items():
                 a = assignment.cached_attempts or []
                 if any(attempt.id in attempt_ids for attempt in a):
                     attempt_keys.append((user.id, assignment_id))
     if not attempt_keys:
         return
     logger.info("Fetching %d attempt list%s", len(attempt_keys),
                 '' if len(attempt_keys) == 1 else 's')
     attempt_data = dwr_get_attempts_info(self.session, attempt_keys)
     for (user_id, aid), attempts in zip(attempt_keys, attempt_data):
         self.students[user_id]['assignments'][aid]['attempts'] = attempts
示例#4
0
文件: grading.py 项目: OEHC/bbfetch
 def refresh_attempt_files(self, attempt):
     assert isinstance(attempt, Attempt)
     logger.info("Fetch details for attempt %s", attempt)
     new_state = fetch_attempt(
         self.session, attempt.id, attempt.assignment.group_assignment)
     st = self.get_attempt_state(attempt, create=True)
     st.update(new_state)
     self.autosave()
示例#5
0
 def refresh(self, **kwargs):
     logger.info("Refresh gradebook")
     self.gradebook.refresh(student_visible=self.get_student_visible,
                            **kwargs)
     if not self.attempt_state:
         self.attempt_state = {}
     if self.should_refresh_groups():
         self.refresh_groups()
     self.autosave()
示例#6
0
文件: grading.py 项目: Mortal/bbfetch
 def refresh(self, **kwargs):
     logger.info("Refresh gradebook")
     self.gradebook.refresh(
         student_visible=self.get_student_visible,
         **kwargs)
     if not self.attempt_state:
         self.attempt_state = {}
     if self.should_refresh_groups():
         self.refresh_groups()
     self.autosave()
示例#7
0
    def download_attempt_files(self, attempt):
        assert isinstance(attempt, Attempt)
        try:
            files = self.get_attempt_files(attempt)
        except NotYetSubmitted:
            logger.info('Skip downloading %s (not yet submitted)', attempt)
            return
        d = self.get_attempt_directory(attempt, create=True)
        for o in files:
            filename = o['filename']
            outfile = os.path.join(d, filename)
            if os.path.exists(outfile):
                logger.info("Skip downloading %s %s (already exists)", attempt,
                            outfile)

            elif 'contents' in o:
                s = o['contents']
                if s and not s.endswith('\n'):
                    s += '\n'
                with open(outfile, 'w') as fp:
                    fp.write(s)
                logger.info("Storing %s %s (text content)", attempt, filename)

            else:
                download_link = o['download_link']
                response = self.session.session.get(download_link, stream=True)
                logger.info("Download %s %s", attempt, outfile)
                with open(outfile, 'wb') as fp:
                    for chunk in response.iter_content(chunk_size=64 * 1024):
                        if chunk:
                            fp.write(chunk)
                self.extract_archive(outfile)
示例#8
0
文件: grading.py 项目: Mortal/bbfetch
    def download_attempt_files(self, attempt):
        assert isinstance(attempt, Attempt)
        files = self.get_attempt_files(attempt)
        d = self.get_attempt_directory(attempt, create=True)
        for o in files:
            filename = o['filename']
            outfile = os.path.join(d, filename)
            if os.path.exists(outfile):
                logger.info("Skip downloading %s %s (already exists)",
                            attempt, outfile)

            elif 'contents' in o:
                s = o['contents']
                if s and not s.endswith('\n'):
                    s += '\n'
                with open(outfile, 'w') as fp:
                    fp.write(s)
                logger.info("Storing %s %s (text content)", attempt, filename)

            else:
                download_link = o['download_link']
                response = self.session.session.get(download_link, stream=True)
                logger.info("Download %s %s", attempt, outfile)
                with open(outfile, 'wb') as fp:
                    for chunk in response.iter_content(chunk_size=64*1024):
                        if chunk:
                            fp.write(chunk)
                self.extract_archive(outfile)
示例#9
0
文件: grading.py 项目: kse/bbfetch
    def download_attempt_files(self, attempt):
        assert isinstance(attempt, Attempt)
        files = self.get_attempt_files(attempt)
        d = self.get_attempt_directory(attempt, create=True)
        for o in files:
            filename = o['filename']
            outfile = os.path.join(d, filename)
            if os.path.exists(outfile):
                logger.info("%s already exists; skipping", outfile)
                continue

            if 'contents' in o:
                with open(outfile, 'w') as fp:
                    fp.write(o['contents'])
                logger.info("Saving %s for attempt %s", filename, attempt)
                continue

            download_link = o['download_link']
            response = self.session.session.get(download_link, stream=True)
            logger.info("Download %s %s (%s bytes)", attempt,
                        outfile, response.headers.get('content-length'))
            with open(outfile, 'wb') as fp:
                for chunk in response.iter_content(chunk_size=64*1024):
                    if chunk:
                        fp.write(chunk)
            self.extract_archive(outfile)
示例#10
0
文件: grading.py 项目: OEHC/bbfetch
 def refresh_groups(self):
     logger.info("Fetching student group memberships")
     self.groups = fetch_groups(self.session)
     if any(k.startswith('Access the profile') for k in self.groups.keys()):
         raise Exception("fetch_groups returned bad usernames")