Пример #1
0
def prepareObject(function, obj):
    """
    This is a funtion that serves to make interacting with the
    backend as transparent as possible. It"s sole purpose it to
    prepare the attributes and data of the various pyrrd objects
    for use by the functions that call out to rrdtool.

    For all of the rrdtool-methods in this module, we need to split
    the named parameters up into pairs, assebled all the stuff in
    the list obj.data, etc.

    This function will get called by methods in the pyrrd wrapper
    objects. For instance, most of the methods of pyrrd.rrd.RRD
    will call this function. In graph, Pretty much only the method
    pyrrd.graph.Graph.write() will call this function.
    """
    if function == 'create':
        validParams = ['start', 'step']
        params = buildParameters(obj, validParams)
        params += [unicode(x) for x in obj.ds]
        params += [unicode(x) for x in obj.rra]
        return (obj.filename, params)

    if function == 'update':
        validParams = ['template']
        params = buildParameters(obj, validParams)
        FIRST_VALUE = 0
        DATA = 1
        TIME_OR_DATA = 0
        if obj.values[FIRST_VALUE][DATA]:
            params += ['%s:%s' % (time, values) for time, values in obj.values]
        else:
            params += [data for data, nil in obj.values]
        return (obj.filename, params)

    if function == 'fetch':
        validParams = ['resolution', 'start', 'end']
        params = buildParameters(obj, validParams)
        return (obj.filename, [obj.cf] + params)

    if function == 'info':
        return (obj.filename, obj)

    if function == 'graph':
        validParams = [
            'start', 'end', 'step', 'title', 'vertical_label', 'width',
            'height', 'only_graph', 'upper_limit', 'lower_limit', 'rigid',
            'alt_autoscale', 'alt_autoscale_max', 'no_gridfit', 'x_grid',
            'y_grid', 'alt_y_grid', 'logarithmic', 'units_exponent', 'zoom',
            'font', 'font_render_mode', 'interlaced', 'no_legend',
            'force_rules_legend', 'tabwidth', 'base', 'color', 'imgformat',
            'slope_mode'
        ]
        params = buildParameters(obj, validParams)
        params += [unicode(x) for x in obj.data]
        return (obj.filename, params)
Пример #2
0
def prepareObject(function, obj):
    """
    This is a funtion that serves to make interacting with the
    backend as transparent as possible. It's sole purpose it to
    prepare the attributes and data of the various pyrrd objects
    for use by the functions that call out to rrdtool.

    For all of the rrdtool-methods in this module, we need a filename
    and then parameters -- both as strings. That's it.

    This function will get called by methods in the pyrrd wrapper
    objects. For instance, most of the methods of pyrrd.rrd.RRD
    will call this function. In graph, Pretty much only the method
    pyrrd.graph.Graph.write() will call this function.
    """
    if function == 'create':
        validParams = ['start', 'step']
        params = common.buildParameters(obj, validParams)
        data = [ str(x) for x in obj.ds ]
        data += [ str(x) for x in obj.rra ]
        return (obj.filename, params + data)

    if function == 'update':
        validParams = ['template']
        params = common.buildParameters(obj, validParams)
        FIRST_VALUE = 0
        DATA = 1
        TIME_OR_DATA = 0
        if obj.values[FIRST_VALUE][DATA]:
            data = ['%s:%s' % (time, values)
                    for time, values in obj.values]
        else:
            data = [data for data, nil in obj.values]
        return (obj.filename, params + data)

    if function == 'fetch':
        validParams = ['resolution', 'start', 'end']
        params = common.buildParameters(obj, validParams)
        
        params.insert(0,obj.cf)
        return (obj.filename, params)

    if function == 'info':
        return (obj.filename, obj)

    if function == 'graph':
        validParams = ['start', 'end', 'step', 'title',
            'vertical_label', 'width', 'height', 'only_graph',
            'upper_limit', 'lower_limit', 'rigid', 'alt_autoscale',
            'alt_autoscale_max', 'no_gridfit', 'x_grid', 'y_grid',
            'alt_y_grid', 'logarithmic', 'units_exponent', 'zoom',
            'font', 'font_render_mode', 'interlaced', 'no_legend',
            'force_rules_legend', 'tabwidth', 'base', 'color']
        params = common.buildParameters(obj, validParams)
        data = [ str(x) for x in obj.data ]
        return (obj.filename, params + data)