Пример #1
0
 def __recalc(self):
     if self.type == 'leaves':
         RecalculateLeaves(self._roots)
     elif self.type == 'unsafe':
         UnsafeUtils.RecalculateConnections(self._roots)
     elif self.type == 'safe':
         SafeUtils.RecalculateConnections(self._roots)
     elif self.type == 'unknown':
         UnknownUtils.RecalculateConnections(self._roots)
     elif self.type == 'resources':
         RecalculateResources(self._roots)
     elif self.type == 'compinst':
         RecalculateComponentInstances(self._roots)
     elif self.type == 'coverage':
         RecalculateCoverageCache(self._roots)
     elif self.type == 'all':
         RecalculateLeaves(self._roots)
         UnsafeUtils.RecalculateConnections(self._roots)
         SafeUtils.RecalculateConnections(self._roots)
         UnknownUtils.RecalculateConnections(self._roots)
         RecalculateResources(self._roots)
         RecalculateComponentInstances(self._roots)
         RecalculateCoverageCache(self._roots)
     elif self.type == 'for_uploaded':
         RecalculateLeaves(self._roots)
         UnsafeUtils.RecalculateConnections(self._roots)
         SafeUtils.RecalculateConnections(self._roots)
         UnknownUtils.RecalculateConnections(self._roots)
         RecalculateComponentInstances(self._roots)
         RecalculateCoverageCache(self._roots)
     else:
         logger.error('Wrong type of recalculation')
         raise BridgeException()
Пример #2
0
def delete_marks(user, marks_type, mark_ids, report_id=None):
    if marks_type == 'safe':
        marks = MarkSafe.objects.filter(id__in=mark_ids)
    elif marks_type == 'unsafe':
        marks = MarkUnsafe.objects.filter(id__in=mark_ids)
    elif marks_type == 'unknown':
        marks = MarkUnknown.objects.filter(id__in=mark_ids)
    else:
        raise ValueError('Unsupported marks type: %s' % marks_type)
    if not all(MarkAccess(user, mark=mark).can_delete() for mark in marks):
        if len(marks) > 1:
            raise BridgeException(_("You can't delete one of the selected marks"))
        elif len(marks) == 1:
            raise BridgeException(_("You don't have an access to delete this mark"))
        else:
            raise BridgeException(_('Nothing to delete'))
    if marks_type == 'safe':
        SafeUtils.delete_marks(marks)
        reports_model = ReportSafe
    elif marks_type == 'unsafe':
        UnsafeUtils.delete_marks(marks)
        reports_model = ReportUnsafe
    else:
        UnknownUtils.delete_marks(marks)
        reports_model = ReportUnknown
    if report_id:
        try:
            report = reports_model.objects.get(id=report_id)
        except ObjectDoesNotExist:
            return None
        return report.id if not isinstance(report, ReportUnsafe) else report.trace_id
Пример #3
0
 def __update(self):
     if isinstance(self._association, MarkSafeReport):
         self.__update_cache(SafeUtils)
     elif isinstance(self._association, MarkUnsafeReport):
         self.__update_cache(UnsafeUtils)
     elif isinstance(self._association, MarkUnknownReport) and self._recalc:
         UnknownUtils.update_unknowns_cache([self._association.report])
Пример #4
0
 def __upload_all(self, marks_dir):
     if self.delete_all:
         SafeUtils.delete_marks(MarkSafe.objects.all())
         UnsafeUtils.delete_marks(MarkUnsafe.objects.all())
         UnknownUtils.delete_marks(MarkUnknown.objects.all())
     for file_name in os.listdir(marks_dir):
         mark_path = os.path.join(marks_dir, file_name)
         if os.path.isfile(mark_path):
             with open(mark_path, mode='rb') as fp:
                 try:
                     mark_type = UploadMark(self.user, fp).type
                     if mark_type in self.numbers:
                         self.numbers[mark_type] += 1
                 except Exception as e:
                     logger.exception(e)
                     self.numbers['fail'] += 1
Пример #5
0
 def __create_mark(self, mark_data, versions):
     mark_utils = {
         'safe': SafeUtils,
         'unsafe': UnsafeUtils,
         'unknown': UnknownUtils
     }
     versions[0].update(mark_data)
     res = mark_utils[self.type].NewMark(self._user, versions[0])
     mark = res.upload_mark()
     for version_data in versions[1:]:
         version_data.update(mark_data)
         try:
             mark_utils[self.type].NewMark(self._user,
                                           version_data).change_mark(
                                               mark, False)
         except Exception:
             mark.delete()
             raise
     if self.type == 'safe':
         SafeUtils.RecalculateTags(
             list(SafeUtils.ConnectMarks([mark]).changes.get(mark.id, {})))
     elif self.type == 'unsafe':
         UnsafeUtils.RecalculateTags(
             list(
                 UnsafeUtils.ConnectMarks([mark]).changes.get(mark.id, {})))
     elif self.type == 'unknown':
         UnknownUtils.ConnectMark(mark)
     return mark
Пример #6
0
 def __get_handler(self):
     if isinstance(self._inst, (ReportSafe, MarkSafe)):
         return SafeUtils.NewMark(self._user, self._data)
     elif isinstance(self._inst, (ReportUnsafe, MarkUnsafe)):
         return UnsafeUtils.NewMark(self._user, self._data)
     elif isinstance(self._inst, (ReportUnknown, MarkUnknown)):
         return UnknownUtils.NewMark(self._user, self._data)
     else:
         raise ValueError('Unsupported type: %s' % type(self._inst))
Пример #7
0
    def __fill_leaf_cache(self, leaf):
        if self.job.weight == JOB_WEIGHT[1][0]:
            self.__cut_parents_branch()
            if self.parent.verifier_input or self.parent.covnum > 0:
                # After verification finish report self.parent.parent will be Core/first-level report
                self._parents_branch.append(self.parent)
            else:
                leaf.parent = self._parents_branch[-1]
                leaf.save()

        if self.data['type'] == 'unknown':
            self.__fill_unknown_cache(leaf)
            UnknownUtils.ConnectReport(leaf)
        elif self.data['type'] == 'safe':
            self.__fill_safe_cache(leaf)
            SafeUtils.ConnectReport(leaf)
            SafeUtils.RecalculateTags([leaf])
Пример #8
0
 def __populate_unknown_marks(self):
     res = UnknownUtils.PopulateMarks(self.manager)
     if res.created > 0:
         self.changes['marks']['unknown'] = (res.created, res.total)