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
            }
        )
    def get(self):
        data = dtmm_utils.get_modules(self)

        self.dorender(
            'tree.html',
            {
                'tree': data_tree(self, data)
            }
        )
    def test_get_modules(self, _get_tree):
        _get_tree.return_value = [
            {'path': 'bad_file.bleh'},
            {'path': 'good_file.lua'}
        ]

        import dtmm_utils
        modules = dtmm_utils.get_modules()

        self.assertEqual(modules, [_get_tree.return_value[1]])
    def get(self):
        "handlers get requests"
        module_name = self.request.get('name')

        tree = dtmm_utils.get_modules(self)
        tree = filter(
            lambda fragment: dtmm_utils.rpart(fragment['path']) == module_name,
            tree
        )

        self.response.write(data_tree(self, tree))
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
    def get(self):
        "Handlers get requests"

        data = dtmm_utils.get_modules(self)

        module_name = self.request.get('name')
        if module_name not in map(itemgetter('path'), data):
            self.error(404)
            return

        data_dict = {
            rpart(fragment['path']): fragment['url']
            for fragment in data
        }

        encoded_content = dtmm_utils.get_url_content(self, data_dict[module_name])
        content = base64.b64decode(encoded_content['content'])

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.headers['Cache-Control'] = 'no-Cache'
        self.response.write(content)