예제 #1
0
    def _migrate_papers(self):
        self.contrib_reviewers = _invert_mapping(self.pr._reviewerContribution)
        self.contrib_referees = _invert_mapping(self.pr._refereeContribution)
        self.contrib_editors = _invert_mapping(self.pr._editorContribution)

        for contrib_id, old_contrib in self.conf.contributions.iteritems():
            if old_contrib not in self.event_ns.legacy_contribution_map:
                self.print_warning(
                    '%[yellow!]Contribution {} not found in event'.format(
                        contrib_id))
                continue

            contribution = self.event_ns.legacy_contribution_map[old_contrib]
            revisions = Paper(contribution).revisions
            self._migrate_paper_roles(old_contrib, contribution)

            review_manager = getattr(old_contrib, '_reviewManager', None)
            if review_manager:
                self._migrate_revisions(old_contrib, contribution,
                                        review_manager)

            reviewing = getattr(old_contrib, 'reviewing', None)

            # if there were no materials attached to the contribution or no revisions, we're done
            if not reviewing or not revisions:
                continue

            # these are the resources that correspond to the latest revision
            for resource in reviewing._Material__resources.itervalues():
                self._migrate_resource(
                    contribution, revisions[-1], resource,
                    getattr(reviewing, '_modificationDS', strict_now_utc()),
                    set())
예제 #2
0
    def _migrate_paper_files(self, old_contrib, contribution, old_revision,
                             revision):
        reviewing = getattr(old_contrib, 'reviewing', None)
        last_file = None
        ignored_checksums = set()

        if not getattr(old_revision, '_materials', None):
            return
        assert len(old_revision._materials) == 1
        for resource in old_revision._materials[
                0]._Material__resources.itervalues():
            res_file = self._migrate_resource(
                contribution, revision, resource,
                getattr(reviewing, '_modificationDS', strict_now_utc()),
                ignored_checksums)
            if res_file:
                last_file = res_file

        # if a revision has no files (because they've all been ignored), then keep around a copy of each
        if not revision.files and ignored_checksums:
            for checksum in ignored_checksums:
                paper_file = self.checksum_map[checksum]
                paper_file._contribution = contribution
                revision.files.append(paper_file)
                self.print_warning(
                    '%[yellow!]File {} (rev. {}) reinstated'.format(
                        paper_file.filename, revision.id))

        return last_file
예제 #3
0
    def _migrate_revisions(self, old_contrib, contribution, rm):
        revision_dts = set()
        self.print_info('%[white!]{}%[reset]'.format(contribution))

        self.file_checksums = defaultdict()

        # Here we iterate over what the legacy PR mode calls "Reviews" (our `PaperRevisions`)
        for n, old_revision in enumerate(rm._versioning, 1):
            old_judgment = old_revision._refereeJudgement
            old_content_reviews = old_revision._reviewerJudgements.values()
            old_layout_review = old_revision._editorJudgement

            # keep track of the last legacy revision, so that we can come back to it
            # during paper file migration
            self.legacy_contrib_last_revision_map[old_contrib] = old_revision

            # skip revisions that haven't been submitted by the author
            if not old_revision._isAuthorSubmitted:
                # ... except if said revision has been judged before being marked as submitted (!)
                if old_judgment._submitted:
                    self.print_warning(
                        '%[yellow!]Revision judged without being submitted! [{}: {}]'
                        .format(contribution, old_revision._version))
                else:
                    continue

            # It seems contradictory, but 'submitted' in legacy means that there is a final decision
            # We'll ignore legacy custom states and use TBC
            state = (JUDGMENT_STATE_REVISION_MAP.get(
                int(old_judgment._judgement._id),
                PaperRevisionState.to_be_corrected) if old_judgment._submitted
                     else PaperRevisionState.submitted)
            judge = self.global_ns.avatar_merged_user[
                old_judgment._author.id] if old_judgment._submitted else None
            judgment_dt = _to_utc(old_judgment._submissionDate
                                  ) if old_judgment._submitted else None
            # Legacy didn't keep track of the submission date (nor submitter for that matter)
            # we're taking the most recent uploaded file and using that one
            # if there are no files, the event's end date will be used
            revision = PaperRevision(state=state,
                                     submitter=self.system_user,
                                     judge=judge,
                                     judgment_dt=judgment_dt,
                                     judgment_comment=convert_to_unicode(
                                         old_judgment._comments))
            self.legacy_contrib_revision_map[(
                old_contrib, old_revision._version)] = revision

            # Then we'll add the layout and content reviews
            review_colors = ''

            for old_content_review in old_content_reviews:
                if old_content_review._submitted:
                    review = self._migrate_review(contribution,
                                                  old_content_review,
                                                  PaperReviewType.content)
                    revision.reviews.append(review)
                    review_colors += _review_color(review, 'C')
            if old_layout_review._submitted:
                review = self._migrate_review(contribution, old_layout_review,
                                              PaperReviewType.layout)
                revision.reviews.append(review)
                review_colors += _review_color(review, 'L')
            contribution._paper_revisions.append(revision)

            self.print_info(
                '\tRevision %[blue!]{}%[reset] %[white,{}]  %[reset] {}'.
                format(n, STATE_COLOR_MAP[state], review_colors))

            last_file = self._migrate_paper_files(old_contrib, contribution,
                                                  old_revision, revision)
            submitted_dt = _to_utc(last_file.created_dt) if last_file else min(
                self.event.end_dt, strict_now_utc())

            # some dates may be duplicates (shouldn't happen if CRC is used, though)
            while submitted_dt in revision_dts:
                submitted_dt += timedelta(seconds=1)
            revision_dts.add(submitted_dt)
            revision.submitted_dt = submitted_dt

            db.session.flush()