Beispiel #1
0
    def dump_pgbadger(self, dir_dump, output, cursor):
        pgbadger = find_in_path("pgbadger")
        if not pgbadger:
            _logger.error("Pgbadger not found")
            return
        filename = os.path.join(dir_dump, output)
        pg_version = dump_db_manifest(cursor)['pg_version']
        log_path = os.environ.get('PG_LOG_PATH', DFTL_LOG_PATH % pg_version)
        if not os.path.exists(os.path.dirname(filename)):
            try:
                os.makedirs(os.path.dirname(filename))
            except OSError as exc:
                # error is different than File exists
                if exc.errno != errno.EEXIST:
                    _logger.error("File can be created")
                    return
        _logger.info("Generating PG Badger report.")
        exclude_query = self.get_exclude_query()
        dbname = cursor.dbname
        command = [
            pgbadger, '-f', 'stderr', '-T', 'Odoo-Profiler', '-o', '-', '-d',
            dbname, '-b', ProfilerController.begin_date, '-e',
            ProfilerController.end_date, '--sample', '2', '--disable-type',
            '--disable-error', '--disable-hourly', '--disable-session',
            '--disable-connection', '--disable-temporary', '--quiet'
        ]
        command.extend(exclude_query)
        command.append(log_path)

        _logger.info("Pgbadger Command:")
        _logger.info(command)
        result = tools.exec_command_pipe(*command)
        with open(filename, 'w') as fw:
            fw.write(result[1].read())
        _logger.info("Done")
    def get_proximity_graph(self, cr, uid, module_id, context=None):
        pool_obj = pooler.get_pool(cr.dbname)
        module_obj = pool_obj.get('ir.module.module')
        nodes = [('base', 'unknown')]
        edges = []

        def get_depend_module(module_id):
            module_record = module_obj.browse(
                cr, uid, module_id, context=context
            )
            if module_record.name not in nodes:
                # Add new field ir.module.module object in server side.
                # field name = module_type/
                nodes.append((module_record.name, "unknown"))
            if module_record.dependencies_id:
                for depen in module_record.dependencies_id:
                    if (module_record.name, depen.name) not in edges:
                        edges.append((module_record.name, depen.name))
                    if depen.name == "base":
                        continue
                    id = module_obj.browse(cr, uid, module_obj.search(
                        cr, uid, [('name', '=', depen.name)]), context=context
                    )
                    if id:
                        get_depend_module(id[0].id)
        get_depend_module(module_id)
        graph = pydot.Dot(
            graph_type='digraph',
            fontsize='10',
            label="""
            Proximity Graph.
            Gray Color-Official Modules,
            Red Color-Extra Addons Modules,
            Blue Color-Community Modules,
            Purple Color-Unknow Modules
            """,
            center='1'
        )
        for node in nodes:
            if node[1] == "official":
                graph.add_node(
                    pydot.Node(
                        node[0], style="filled", fillcolor="lightgray"
                    )
                )
            elif node[1] == "extra_addons":
                graph.add_node(
                    pydot.Node(
                        node[0], style="filled", fillcolor="red"
                    )
                )
            elif node[1] == "community":
                graph.add_node(
                    pydot.Node(
                        node[0], style="filled", fillcolor="#000FFF"
                    )
                )
            elif node[1] == "unknown":
                graph.add_node(
                    pydot.Node(
                        node[0], style="filled", fillcolor="purple"
                    )
                )
        for edge in edges:
            graph.add_edge(pydot.Edge(edge[0], edge[1]))

        ps_string = graph.create(prog='dot', format='ps')
        if os.name == "nt":
            prog = 'ps2pdf.bat'
        else:
            prog = 'ps2pdf'

        args = (prog, '-', '-')
        input, output = tools.exec_command_pipe(*args)
        input.write(ps_string)
        input.close()
        return output.read()
    def get_proximity_graph(self, cr, uid, module_id, context=None):
        pool_obj = pooler.get_pool(cr.dbname)
        module_obj = pool_obj.get('ir.module.module')
        nodes = [('base', 'unknown')]
        edges = []

        def get_depend_module(module_id):
            module_record = module_obj.browse(cr,
                                              uid,
                                              module_id,
                                              context=context)
            if module_record.name not in nodes:
                # Add new field ir.module.module object in server side.
                # field name = module_type/
                nodes.append((module_record.name, "unknown"))
            if module_record.dependencies_id:
                for depen in module_record.dependencies_id:
                    if (module_record.name, depen.name) not in edges:
                        edges.append((module_record.name, depen.name))
                    if depen.name == "base":
                        continue
                    id = module_obj.browse(cr,
                                           uid,
                                           module_obj.search(
                                               cr, uid,
                                               [('name', '=', depen.name)]),
                                           context=context)
                    if id:
                        get_depend_module(id[0].id)

        get_depend_module(module_id)
        graph = pydot.Dot(graph_type='digraph',
                          fontsize='10',
                          label="""
            Proximity Graph.
            Gray Color-Official Modules,
            Red Color-Extra Addons Modules,
            Blue Color-Community Modules,
            Purple Color-Unknow Modules
            """,
                          center='1')
        for node in nodes:
            if node[1] == "official":
                graph.add_node(
                    pydot.Node(node[0], style="filled", fillcolor="lightgray"))
            elif node[1] == "extra_addons":
                graph.add_node(
                    pydot.Node(node[0], style="filled", fillcolor="red"))
            elif node[1] == "community":
                graph.add_node(
                    pydot.Node(node[0], style="filled", fillcolor="#000FFF"))
            elif node[1] == "unknown":
                graph.add_node(
                    pydot.Node(node[0], style="filled", fillcolor="purple"))
        for edge in edges:
            graph.add_edge(pydot.Edge(edge[0], edge[1]))

        ps_string = graph.create(prog='dot', format='ps')
        if os.name == "nt":
            prog = 'ps2pdf.bat'
        else:
            prog = 'ps2pdf'

        args = (prog, '-', '-')
        input, output = tools.exec_command_pipe(*args)
        input.write(ps_string)
        input.close()
        return output.read()
Beispiel #4
0
    def __init__(self, cr, uid, ids, data):
        try:
            import pydot
        except Exception as e:
            _logger.warning(
                'Import Error for pydot, you will not be able to render workflows.\n'
                'Consider Installing PyDot or dependencies: http://dkbza.org/pydot.html.'
            )
            raise e
        self.done = False

        try:
            cr.execute('select * from wkf where osv=%s limit 1',
                       (data['model'], ))
            wkfinfo = cr.dictfetchone()
            if not wkfinfo:
                ps_string = '''%PS-Adobe-3.0
/inch {72 mul} def
/Times-Roman findfont 50 scalefont setfont
1.5 inch 15 inch moveto
(No workflow defined) show
showpage'''
            else:
                cr.execute(
                    'select i.id from wkf_instance i left join wkf w on (i.wkf_id=w.id) where res_id=%s and osv=%s',
                    (data['id'], data['model']))
                inst_ids = cr.fetchall()
                if not inst_ids:
                    ps_string = '''%PS-Adobe-3.0
/inch {72 mul} def
/Times-Roman findfont 50 scalefont setfont
1.5 inch 15 inch moveto
(No workflow instance defined) show
showpage'''
                else:
                    graph = pydot.Dot(
                        graph_name=data['model'].replace('.', '_'),
                        fontsize='16',
                        label="""\\\n\\nWorkflow: %s\\n OSV: %s""" %
                        (wkfinfo['name'], wkfinfo['osv']),
                        size='7.3, 10.1',
                        center='1',
                        ratio='auto',
                        rotate='0',
                        rankdir='TB',
                    )
                    for inst_id in inst_ids:
                        inst_id = inst_id[0]
                        graph_instance_get(cr, graph, inst_id,
                                           data.get('nested', False))
                    ps_string = graph.create(prog='dot', format='ps')
        except Exception:
            _logger.exception('Exception in call:')
            # string is in PS, like the success message would have been
            ps_string = '''%PS-Adobe-3.0
/inch {72 mul} def
/Times-Roman findfont 50 scalefont setfont
1.5 inch 15 inch moveto
(No workflow available) show
showpage'''
        if os.name == "nt":
            prog = 'ps2pdf.bat'
        else:
            prog = 'ps2pdf'
        args = (prog, '-', '-')
        input, output = tools.exec_command_pipe(*args)
        input.write(ps_string)
        input.close()
        self.result = output.read()
        output.close()
        self.done = True