Пример #1
0
def round_value(x):
    if none(x):
        return None


#    x = float(nominal_value(x))

    prefix = ''
    if x == 0:
        pass
    elif abs(x) >= 1e9:
        x = x / 1e9
        prefix = 'G'
    elif abs(x) >= 1e6:
        x = x / 1e6
        prefix = 'M'
    elif abs(x) >= 1e3:
        x = x / 1e3
        prefix = 'k'
    elif abs(x) < 1e-9:
        x = x / 1e-12
        prefix = 'p'
    elif abs(x) < 1e-6:
        x = x / 1e-9
        prefix = 'n'
    elif abs(x) < 1e-3:
        x = x / 1e-6
        prefix = 'u'
    elif abs(x) < 1:
        x = x / 1e-3
        prefix = 'm'
    return (x, prefix)
Пример #2
0
def round_value(x):
    if none(x):
        return None

#    x = float(nominal_value(x))

    prefix = ''
    if x == 0:
        pass
    elif abs(x) >= 1e9:
        x = x / 1e9
        prefix = 'G'
    elif abs(x) >= 1e6:
        x = x / 1e6
        prefix = 'M'
    elif abs(x) >= 1e3:
        x = x / 1e3
        prefix = 'k'
    elif abs(x) < 1e-9:
        x = x / 1e-12
        prefix = 'p'
    elif abs(x) < 1e-6:
        x = x / 1e-9
        prefix = 'n'
    elif abs(x) < 1e-3:
        x = x / 1e-6
        prefix = 'u'
    elif abs(x) < 1:
        x = x / 1e-3
        prefix = 'm'
    return (x, prefix)
Пример #3
0
def format_beta(x):
    if none(x):
        return ''
    if x > 1:
        return format_int(x)
    else:
        return '%0.1f' % (x)
Пример #4
0
def format_beta(x):
    if none(x):
        return ''
    if x > 1:
        return format_int(x)
    else:
        return '%0.1f' % (x)
Пример #5
0
    def add_triage(self,
                   triage: Triage,
                   scope: TriageScope = None,
                   product_id=None,
                   group_id=None):
        '''
        adds an existing Protecode triage to a specified target. The existing triage is usually
        retrieved from an already uploaded product (which is represented by `AnalysisResult`).
        This method is offered to support "transporting" existing triages.

        Note that - depending on the effective target scope, the `product_id`, `group_id` formal
        parameters are either required or forbidden.

        @param triage: the triage to "copy"
        @param scope: if given, overrides the triage's scope
        @param product_id: target product_id. required iff scope in FN, FH, R
        @param group_id: target group_id. required iff scope is G(ROUP)
        '''
        url = self._routes.triage()

        # if no scope is set, use the one from passed triage
        scope = scope if scope else triage.scope()

        # depending on the scope, different arguments are required
        if scope == TriageScope.ACCOUNT_WIDE:
            none(product_id)
            none(group_id)
        elif scope in (TriageScope.FILE_NAME, TriageScope.FILE_HASH,
                       TriageScope.RESULT):
            not_none(product_id)
            none(group_id)
        elif scope == TriageScope.GROUP:
            none(product_id)
            not_none(group_id)
        else:
            raise NotImplementedError()

        # "copy" data from existing triage
        triage_dict = {
            'component': triage.component_name(),
            'version': triage.component_version(),
            'vulns': [triage.vulnerability_id()],
            'scope': triage.scope().value,
            'reason': triage.reason(),
            'description': triage.description(),
        }

        if product_id:
            triage_dict['product_id'] = product_id

        if group_id:
            triage_dict['group_id'] = group_id

        self._put(
            url=url,
            json=triage_dict,
        )
Пример #6
0
def format_ufloat(x, format_func):
    if none(x):
        return ''

    if nominal_value(x):
        perc = 100 * x.std_dev() / x.nominal_value
    else:
        perc = 0
    s = u'%10s  \u00B1 %0.1f %% \u00B1 %10s' % (format_func(
        x.nominal_value), perc, format_func(x.std_dev()))
    return s
Пример #7
0
def format_ufloat(x, format_func):
    if none(x):
        return ''

    if nominal_value(x):
        perc = 100 * x.std_dev() / x.nominal_value
    else:
        perc = 0
    s = u'%10s  \u00B1 %0.1f %% \u00B1 %10s' % (format_func(x.nominal_value),
                                                perc,
                                                format_func(x.std_dev())
                                                )
    return s
Пример #8
0
def format_percent(x):
    if none(x):
        return ''
    return '%0.1f %%' % (100 * x)
Пример #9
0
def format_analog(x):
    if none(x):
        return ''
    return str(int(nominal_value(x)))
Пример #10
0
def format_int(x):
    if none(x):
        return ''
    return str(int(x))
Пример #11
0
def format_percent(x):
    if none(x):
        return ''
    return '%0.1f %%' % (100 * x)
Пример #12
0
def format_analog(x):
    if none(x):
        return ''
    return str(int(nominal_value(x)))
Пример #13
0
def format_int(x):
    if none(x):
        return ''
    return str(int(x))