def test_get_live_module_data(self, get_url_content):
        get_url_content.return_value = {
            'content': base64.b64encode('''
                MODULE = {
                    Type = "Hardware",
                    Name = "HMD2043",
                    Version = "1.1",
                    SDescription = "Deprecated HMD2043 hardware device",
                    URL = "False URL"
                };''')
        }

        import dtmm_utils
        end_data = dtmm_utils.get_live_module_data(
            None, {"url": "http://mock.url/hardware_file"})
        self.assertEqual(
            end_data,
            {
                'URL': 'False URL',
                'SDescription': 'Deprecated HMD2043 hardware device',
                'Version': '1.1',
                'Type': 'Hardware',
                'Name': 'HMD2043'
            }
        )
Exemplo n.º 2
0
def data_tree(handler, data):
    "given a data tree, will return a html-based representation"

    modules = []
    for fragment in data:
        cur_path = dtmm_utils.rpart(fragment['path'])
        module_data = dtmm_utils.get_live_module_data(handler, fragment)

        if module_data['Type'].lower() == 'hardware':
            hardware_data = dtmm_utils.get_live_hardware_data(
                handler, fragment)

            hardware_data = {
                'ID': hex(hardware_data['ID']),
                'Version': hex(hardware_data['Version']),
                'Manufacturer': hex(hardware_data['Manufacturer'])
            }
        else:
            hardware_data = None

        modules.append({
            'cur_path': cur_path,
            'module_data': module_data,
            'hardware_data': hardware_data
        })

    return handler.dorender(
        'data_tree.html',
        {
            'modules': modules
        }, write=False
    )
Exemplo n.º 3
0
    def get(self):
        tree = memcache.get('pretty_tree_tree')
        calc = memcache.get('pretty_tree_calc')
        if not tree or not calc:
            data_tree = dtmm_utils.get_modules(self)

            tree = []
            break_on = 3
            header_diff = 20
            width = 900
            calc = {
                'width': width,
                'cell_height': 80,  # in pixels :D
                'margin_width': width / 2
            }

            for fragment_num, fragment in enumerate(data_tree):
                logging.info('Fragment; %s' % fragment)
                logging.info('Fragment_num; %s' % fragment_num)

                cur_module = dtmm_utils.get_live_module_data(self, fragment)

                cur_module.update({
                    'filename': dtmm_utils.rpart(fragment['path']),
                    'row': fragment_num % break_on == 0,
                    'width': calc['width'] / break_on,
                    'index': fragment_num
                })

                tree.append(cur_module)

            rows = len(filter(itemgetter('row'), tree))
            calc['height'] = (rows * calc['cell_height']) + header_diff
            logging.info('This many rows; %s' % (rows))
            calc['margin_height'] = calc['height'] / 2
            calc['outer_container_height'] = calc['height']

            if len(tree) % break_on != 0:
                remainer = len(tree) % break_on
                for i in range(1, remainer + 1):
                    tree[-i]['width'] = calc['width'] / remainer

            tree[0]['row'] = False
            memcache.set_multi({
                'pretty_tree_tree': tree,
                'pretty_tree_calc': calc
            })

        # we want the colours to be different everytime
        colours = pretty_colours(len(tree))
        for idx, fragment in enumerate(tree):
            fragment.update({'background': colours[idx]})

        self.dorender(
            'tree_pretty.html',
            {
                'tree': tree,
                'calc': calc
            }
        )
Exemplo n.º 4
0
def search(handler, query, requested_type=''):
    "filters modules according to input"
    output = []
    query = query.lower()
    data = dtmm_utils.get_modules(handler)
    requested_type = requested_type.lower()

    if requested_type not in module_types:
        logging.info('Type was not specified')
        for fragment in data:
            if query in fragment['path'].split('/')[-1]:
                output.append(fragment)
    else:
        logging.info('Type was specified: {}'.format(requested_type))
        for fragment in data:
            mod_data_frag = dtmm_utils.get_live_module_data(handler, fragment)
            if query in dtmm_utils.rpart(fragment['path']).lower():
                if requested_type.lower() == mod_data_frag['Type'].lower():
                    output.append(fragment)
    return output