def main(): module = os.path.basename( os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) d = load_information_from_description_file(module) with open('manifest', 'w') as out: manifest_content = (d['description'] if 'description' in d else d['summary'] if 'summary' in d else '') out.write(manifest_content)
def get_module_info(cls, name): try: return modules.load_information_from_description_file(name) except Exception: _logger.debug( 'Error when trying to fetch information for module %s', name, exc_info=True) return {}
def import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: raise UserError(_("Unmet module dependencies: %s") % ', '.join(unmet_dependencies)) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: _logger.info("module %s: loading %s", module, filename) noupdate = False if filename.endswith('.csv') and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'r') as fp: data = fp.read().encode('base64') url_path = '/%s%s' % (module, full_path.split(path)[1].replace(os.path.sep, '/')) url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def analyze_code_one(self, branch): # Change log level to avoid warning, when parsing odoo manifests logger1 = logging.getLogger('openerp.modules.module') logger2 = logging.getLogger('openerp.addons.base.module.module') currentLevel1 = logger1.level currentLevel2 = logger2.level logger1.setLevel(logging.ERROR) logger2.setLevel(logging.ERROR) try: module_version_obj = self.env['odoo.module.version'] # Delete all associated module versions module_versions = module_version_obj.search([ ('repository_branch_id', '=', branch.id) ]) module_versions.with_context( dont_change_repository_branch_state=True).unlink() # Compute path(s) to analyze if branch.module_paths: paths = [] for path in branch.module_paths.split('\n'): if path.strip(): paths.append(os.path.join(branch.local_path, path)) else: paths = [branch.local_path] # Scan each path, if exists for path in paths: if not os.path.exists(path): _logger.warning( "Unable to analyse %s. Source code not found." % (path)) else: # Analyze folders and create module versions _logger.info("Analyzing repository %s ..." % path) for module_name in self.listdir(path): full_module_path = os.path.join(path, module_name) module_info = load_information_from_description_file( module_name, full_module_path) # Create module version, if the module is installable # in the serie if module_info.get('installable', False): module_info['technical_name'] = module_name module_version_obj.create_or_update_from_manifest( module_info, branch, full_module_path) finally: # Reset Original level for module logger logger1.setLevel(currentLevel1) logger2.setLevel(currentLevel2) return super(GithubRepositoryBranch, self).analyze_code_one(branch)
def _analyze_module_name(self, path, module_name, branch): module_version_obj = self.env['odoo.module.version'] try: full_module_path = os.path.join(path, module_name) module_info = load_information_from_description_file( module_name, full_module_path) # Create module version, if the module is installable # in the serie if module_info.get('installable', False): module_info['technical_name'] = module_name module_version_obj.create_or_update_from_manifest( module_info, branch, full_module_path) except Exception as e: _logger.error('Cannot process module with name %s, error ' 'is: %s', module_name, e)
def _analyze_module_name(self, path, module_name, branch): module_version_obj = self.env['odoo.module.version'] try: full_module_path = os.path.join(path, module_name) module_info = load_information_from_description_file( module_name, full_module_path) # Create module version, if the module is installable # in the serie if module_info.get('installable', False): module_info['technical_name'] = module_name module_version_obj.create_or_update_from_manifest( module_info, branch, full_module_path) except Exception as e: _logger.error('Cannot process module with name %s, error ' 'is: %s' % (module_name, e))
def _analyze_module_name(self, path, module_name): self.ensure_one() module_version_obj = self.env["odoo.module.version"] try: full_module_path = os.path.join(path, module_name) module_info = load_information_from_description_file( module_name, full_module_path) # Create module version, if the module is installable # in the serie if module_info.get("installable", False): module_info["technical_name"] = module_name module_version_obj.create_or_update_from_manifest( module_info, self, full_module_path) except Exception as e: _logger.error( "Cannot process module with name %s, error " "is: %s", module_name, e)
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) if not terp: return False values = self.get_values_from_terp(terp) if 'version' in terp: values['latest_version'] = terp['version'] unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: \n\n - %s") % '\n - '.join( known_mods.filtered( lambda mod: mod.name in unmet_dependencies).mapped( 'shortdesc')) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError( _("Studio customizations require the Odoo Studio app.")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create( dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format( module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, str): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def get_module_info(cls, name): try: return modules.load_information_from_description_file(name) except Exception: _logger.debug('Error when trying to fetch information for module %s', name, exc_info=True) return {}
def complex_report(self, docids, data, report, ctx): """ Returns an aeroo report generated by aeroolib """ self.model = ctx.get('active_model', False) # tmpl_type = 'odt' self.record_ids = docids self.ctx = ctx self.company = self.env.user.company_id self.report = report #======================================================================= def barcode(barcode_type, value, width=600, height=100, humanreadable=0): # TODO check that asimage and barcode both accepts width and height img = self.env['ir.actions.report'].barcode( barcode_type, value, width=width, height=height, humanreadable=humanreadable) return self._asimage(base64.b64encode(img)) self.localcontext = { 'user': self.env.user, 'user_lang': ctx.get('lang', False), 'data': data, 'time': time, 'asarray': self._asarray, 'average': self._average, 'currency_to_text': self._currency_to_text, 'asimage': self._asimage, 'get_selection_item': self._get_selection_items('item'), 'get_selection_items': self._get_selection_items(), 'get_log': self._get_log, 'asarray': self._asarray, '__filter': self.__filter, # Don't use in the report template! 'getLang': self._get_lang, 'setLang': self._set_lang, 'formatLang': self._format_lang, '_': self._translate_text, 'gettext': self._translate_text, 'test': self.test, 'fields': fields, 'company': self.env.user.company_id, 'barcode': barcode, } self.localcontext.update(ctx) self._set_lang(self.company.partner_id.lang) self._set_objects(self.model, docids) file_data = None if report.tml_source == 'database': if not report.report_data or report.report_data == 'False': # TODO log report ID etc. raise MissingError( _("Aeroo Reports could'nt find report template")) file_data = b64decode(report.report_data) elif report.tml_source == 'file': if not report.report_file or report.report_file == 'False': # TODO log report ID etc. raise MissingError( _("No Aeroo Reports template filename provided")) file_data = report._read_template() else: rec_id = ctx.get('active_id', data.get('id')) or data.get('id') file_data = self.get_other_template(self.model, rec_id) if not file_data: # TODO log report ID etc. raise MissingError( _("Aeroo Reports could'nt find report template")) template_io = BytesIO(file_data) if report.styles_mode == 'default': serializer = OOSerializer(template_io) else: style_io = BytesIO(self.get_stylesheet(report)) serializer = OOSerializer(template_io, oo_styles=style_io) basic = Template(source=template_io, serializer=serializer, lookup=StrictLookup) # Add metadata ser = basic.Serializer model_obj = self.env.get('ir.model') model_name = model_obj.search([('model', '=', self.model)])[0].name ser.add_title(model_name) user_name = self.env.user.name ser.add_creation_user(user_name) module_info = load_information_from_description_file('report_aeroo') version = module_info['version'] ser.add_generator_info('Aeroo Lib/%s Aeroo Reports/%s' % (aeroolib_version, version)) ser.add_custom_property('Aeroo Reports %s' % version, 'Generator') ser.add_custom_property('Odoo %s' % odoo_release.version, 'Software') ser.add_custom_property(module_info['website'], 'URL') ser.add_creation_date(time.strftime('%Y-%m-%dT%H:%M:%S')) file_data = basic.generate(**self.localcontext).render().getvalue() #======================================================================= code = mime_dict[report.in_format] #_logger.info("End process %s (%s), elapsed time: %s" % (self.name, self.model, time.time() - aeroo_print.start_time), logging.INFO) # debug mode return file_data, code
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: raise UserError( _("Unmet module dependencies: %s") % ', '.join(unmet_dependencies)) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create( dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if filename.endswith('.csv') and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/%s%s' % (module, full_path.split(path)[1].replace( os.path.sep, '/')) url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) values = self.get_values_from_terp(terp) unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: %s") % ', '.join( unmet_dependencies, ) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError(_("Studio customizations require Studio")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, pycompat.text_type): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, datas_fname=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) return True
def _import_module(self, module, path, force=False): known_mods = self.search([]) known_mods_names = {m.name: m for m in known_mods} installed_mods = [m.name for m in known_mods if m.state == 'installed'] terp = load_information_from_description_file(module, mod_path=path) if not terp: return False values = self.get_values_from_terp(terp) if 'version' in terp: values['latest_version'] = terp['version'] unmet_dependencies = set(terp['depends']).difference(installed_mods) if unmet_dependencies: if (unmet_dependencies == set(['web_studio']) and _is_studio_custom(path)): err = _("Studio customizations require Studio") else: err = _("Unmet module dependencies: \n\n - %s") % '\n - '.join( known_mods.filtered(lambda mod: mod.name in unmet_dependencies).mapped('shortdesc') ) raise UserError(err) elif 'web_studio' not in installed_mods and _is_studio_custom(path): raise UserError(_("Studio customizations require the Odoo Studio app.")) mod = known_mods_names.get(module) if mod: mod.write(dict(state='installed', **values)) mode = 'update' if not force else 'init' else: assert terp.get('installable', True), "Module not installable" self.create(dict(name=module, state='installed', imported=True, **values)) mode = 'init' for kind in ['data', 'init_xml', 'update_xml']: for filename in terp[kind]: ext = os.path.splitext(filename)[1].lower() if ext not in ('.xml', '.csv', '.sql'): _logger.info("module %s: skip unsupported file %s", module, filename) continue _logger.info("module %s: loading %s", module, filename) noupdate = False if ext == '.csv' and kind in ('init', 'init_xml'): noupdate = True pathname = opj(path, filename) idref = {} convert_file(self.env.cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname) path_static = opj(path, 'static') IrAttachment = self.env['ir.attachment'] if os.path.isdir(path_static): for root, dirs, files in os.walk(path_static): for static_file in files: full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) if not isinstance(url_path, str): url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename, url=url_path, res_model='ir.ui.view', type='binary', datas=data, ) attachment = IrAttachment.search([('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')]) if attachment: attachment.write(values) else: IrAttachment.create(values) IrAsset = self.env['ir.asset'] assets_vals = [] # Generate 'ir.asset' record values for each asset delared in the manifest for bundle, commands in terp.get('assets', {}).items(): for command in commands: directive, target, path = IrAsset._process_command(command) path = path if path.startswith('/') else '/' + path # Ensures a '/' at the start assets_vals.append({ 'name': f'{module}.{bundle}.{path}', 'directive': directive, 'target': target, 'path': path, 'bundle': bundle, }) # Look for existing assets existing_assets = IrAsset.search([('name', 'in', [vals['name'] for vals in assets_vals])]) existing_assets = existing_assets.mapped(lambda r: (r.name, r)) assets_to_create = [] # Update existing assets and generate the list of new assets values for values in assets_vals: if values['name'] in existing_assets: existing_assets[values['name']].write(values) else: assets_to_create.append(values) # Create new assets and attach 'ir.model.data' records to them created_assets = IrAsset.create(assets_to_create) self.env['ir.model.data'].create([{ 'name': f"{asset['bundle']}.{asset['path']}", 'model': 'ir.asset', 'module': module, 'res_id': asset.id, } for asset in created_assets]) return True
'next': self._next(aeroo_print) }) env = odoo.api.Environment(cr, uid, context or {}) user_name = env['res.users'].browse(uid).name model_id = env['ir.model'].search([ ('model', '=', context.get('active_model', data['model']) or data['model']) ]).id model_name = env['ir.model'].browse(model_id).name #basic = Template(source=None, filepath=odt_path) basic.Serializer.add_title(model_name) basic.Serializer.add_creation_user(user_name) module_info = load_information_from_description_file('report_aeroo') version = module_info['version'] basic.Serializer.add_generator_info('Aeroo Lib/%s Aeroo Reports/%s' % (aeroolib_version, version)) basic.Serializer.add_custom_property('Aeroo Reports %s' % version, 'Generator') basic.Serializer.add_custom_property('Odoo %s' % release.version, 'Software') basic.Serializer.add_custom_property(module_info['website'], 'URL') basic.Serializer.add_creation_date(time.strftime('%Y-%m-%dT%H:%M:%S')) try: if deferred: deferred.set_status(_('Generate document')) data = basic.generate(**oo_parser.localcontext).render().getvalue() except osv.except_osv, e: