def __init__(self, server='localhost', database=None, protocol='xmlrpc', port=8069, timeout=120, version=None): if protocol not in ['xmlrpc', 'xmlrpc+ssl', 'netrpc']: txt = ("The protocol '{0}' is not supported by the OERP class. " "Please choose a protocol among these ones: {1}") txt = txt.format(protocol, ['xmlrpc', 'xmlrpc+ssl', 'netrpc']) raise error.InternalError(txt) self._server = server self._port = port self._protocol = protocol self._database = self._database_default = database self._uid = None self._password = None self._user = None self._common = common.Common(self) self._db = db.DB(self) self._wizard = wizard.Wizard(self) self._inspect = inspect.Inspect(self) # Instanciate the server connector try: self._connector = rpc.PROTOCOLS[protocol]( self._server, self._port, timeout, version) except rpc.error.ConnectorError as exc: raise error.InternalError(exc.message) # Dictionary of configuration options self._config = tools.Config( self, {'auto_context': True, 'timeout': timeout})
def _check_root_modules(self): """Check if `root` modules exist, raise an error if not.""" module_obj = self.oerp.get('ir.module.module') for module in self._root_modules: if not module_obj.search([('name', 'ilike', module)]): raise error.InternalError( "'{0}' module does not exist".format(module))
def __isub__(self, records): if not self.parent or not self.parent_field: raise error.InternalError("No parent record to update") try: list(records) except TypeError: records = [records] updated_values = self.parent.__data__['updated_values'] res = [] if updated_values.get(self.parent_field.name): res = updated_values[self.parent_field.name][:] # Copy from oerplib.service.osv import fields for id_ in fields.records2ids(records): if (4, id_) in res: res.remove((4, id_)) if (3, id_) not in res: res.append((3, id_)) return res
def _print_file_data(data): """Print data in a temporary file and return the path of this one.""" if 'result' not in data: raise error.InternalError( "Invalid data, the operation has been canceled.") content = base64.decodestring(data['result']) if data.get('code') == 'zlib': content = zlib.decompress(content) if data['format'] in ['pdf', 'html', 'doc', 'xls', 'sxw', 'odt', 'tiff']: if data['format'] == 'html' and os.name == 'nt': data['format'] = 'doc' (file_no, file_path) = tempfile.mkstemp('.' + data['format'], 'oerplib_') with file(file_path, 'wb+') as fp: fp.write(content) os.close(file_no) return file_path
def make_dot(self): """Returns a `pydot.Dot` object representing relations between models. >>> graph = oerp.inspect.relations(['res.partner']) >>> graph.make_dot() <pydot.Dot object at 0x2bb0650> See the `pydot <http://code.google.com/p/pydot/>`_ documentation for details. """ try: import pydot except ImportError: raise error.InternalError("'pydot' module not found") output = pydot.Dot(graph_type='digraph', overlap='scalexy', splines='true', nodesep=str(self._config['space_between_models'])) for model, data in self._relations.iteritems(): # Generate attributes of the model attrs_ok = False attrs = [] if self._attrs_whitelist \ and match_in(model, self._attrs_whitelist): attrs_ok = True if self._attrs_blacklist \ and match_in(model, self._attrs_blacklist): attrs_ok = False if attrs_ok: subtitle = TPL_MODEL_SUBTITLE.format( color=self._config['model_color_subtitle'], title="Attributes") attrs.append(subtitle) for k, v in sorted(data['fields'].iteritems()): color_name = self._config['color_normal'] if v.get('function'): color_name = self._config['color_function'] if v.get('fnct_inv'): color_name = self._config['color_normal'] #if v.get('required'): # color_name = self._config['color_required'] attr = TPL_MODEL_ATTR.format( name=k, type_=v['type'], color_name=color_name, flags=self._generate_flags_label(v)) attrs.append(attr) # Generate recursive relations of the model relations_r = [] if data['relations_r']: subtitle = TPL_MODEL_SUBTITLE.format( color=self._config['model_color_subtitle'], title="Recursive relations") relations_r.append(subtitle) for data2 in data['relations_r'].itervalues(): label = self._generate_relation_label(data2) flags = self._generate_flags_label(data2) rel_r = TPL_MODEL_REL.format( name=label, flags=flags, color_name=self._config['color_normal'], type_=data2['type']) relations_r.append(rel_r) # Generate the layout of the model model_bgcolor_title = self._config['model_bgcolor_title'] if model in self._models: model_bgcolor_title = self._config['model_root_bgcolor_title'] tpl = TPL_MODEL.format( model_color_title=self._config['model_color_title'], model_bgcolor_title=model_bgcolor_title, model_bgcolor=self._config['model_bgcolor'], name=model, attrs=''.join(attrs), relations_r=''.join(relations_r)) # Add the model to the graph node = self._create_node(model, 'relation', tpl) output.add_node(node) # Draw relations of the model for data2 in data['relations'].itervalues(): if data2['relation'] in self._relations: edge = self._create_edge(model, data2['relation'], data2) output.add_edge(edge) return output
def make_dot(self): """Returns a `pydot.Dot` object representing dependencies between modules. >>> graph = oerp.inspect.dependencies(['base'], ['res.partner']) >>> graph.make_dot() <pydot.Dot object at 0x2f01990> See the `pydot <http://code.google.com/p/pydot/>`_ documentation for details. """ try: import pydot except ImportError: raise error.InternalError("'pydot' module not found") output = pydot.Dot() def get_template(module, data): """Generate the layout of the module.""" root = all(not self._modules[depend]['keep'] for depend in data['depends']) # Model lines tpl_models = [] for model in sorted(data['models']): color_model = self._config['model_color_normal'] if self._models[model]['transient']: color_model = self._config['model_color_transient'] tpl_models.append( TPL_MODULE_MODEL.format(color_model=color_model, model=model)) # Module comment tpl_comment = None if data.get('comment'): tpl_comment = "<tr><td> </td></tr>" tpl_comment += TPL_MODULE_COMMENT.format( module_color_comment=self._config['module_color_comment'], comment=data['comment']) # Module module_color_title = self._config['module_inst_color_title'] module_bgcolor_title = self._config['module_inst_bgcolor_title'] if root: module_color_title = self._config['module_root_color_title'] module_bgcolor_title = self._config[ 'module_root_bgcolor_title'] if not root and tpl_models: module_color_title = \ self._config['module_highlight_color_title'] module_bgcolor_title = \ self._config['module_highlight_bgcolor_title'] if not data.get('installed'): module_color_title = self._config['module_uninst_color_title'] module_bgcolor_title = \ self._config['module_uninst_bgcolor_title'] tpl = TPL_MODULE.format( module_color_title=module_color_title, module_bgcolor_title=module_bgcolor_title, module_bgcolor=self._config['module_bgcolor'], name=module.lower(), models=''.join(tpl_models), comment=tpl_comment or '') return tpl for module, data in self._modules.iteritems(): if not data['keep']: continue # Add the module as node tpl = get_template(module, data) node = self._draw_graph_node(module, tpl) output.add_node(node) for dependency in data['depends']: if not self._modules[dependency]['keep']: continue # Add edge between the module and it's dependency edge = self._draw_graph_edge(dependency, module) output.add_edge(edge) return output