From 69b2f58dac5c4021c83f7afffd5cdef721f5e5ab Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 09:15:08 +0100 Subject: [PATCH 01/10] [IMP] unable to parse PDF reports bzr revid: fp@tinyerp.com-20110104081508-rg2pq652dsggh3m1 --- bin/tools/test_reports.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/tools/test_reports.py b/bin/tools/test_reports.py index 2f27ed9d3df..6e4b08ece2c 100644 --- a/bin/tools/test_reports.py +++ b/bin/tools/test_reports.py @@ -79,8 +79,8 @@ def try_report(cr, uid, rname, ids, data=None, context=None, our_module=None): res_text = tools.ustr(fp.read()) os.unlink(rfname) except Exception: - log.warning("Cannot extract report's text:", exc_info=True) - + log.debug("Unable to parse PDF report: install pdftotext to perform automated tests.") + if res_text is not False: for line in res_text.split('\n'): if ('[[' in line) or ('[ [' in line): @@ -306,4 +306,4 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None, return True -#eof \ No newline at end of file +#eof From 8020189af74d3358042dbccb4d08682c78f85d11 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 10:26:44 +0100 Subject: [PATCH 02/10] [IMP] mobile -> portable bzr revid: fp@tinyerp.com-20110104092644-nz5nldyn8ej02vw3 --- bin/addons/base/i18n/fr.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/addons/base/i18n/fr.po b/bin/addons/base/i18n/fr.po index d83406bc6e8..72864052558 100644 --- a/bin/addons/base/i18n/fr.po +++ b/bin/addons/base/i18n/fr.po @@ -689,7 +689,7 @@ msgstr "Espagnol (UY) / Español (UY)" #: field:res.partner,mobile:0 #: field:res.partner.address,mobile:0 msgid "Mobile" -msgstr "Téléphone mobile" +msgstr "Tél. portable" #. module: base #: model:res.country,name:base.om @@ -3363,9 +3363,9 @@ msgid "" "the correct mobile number" msgstr "" "Fournissez les champs qui seront utilisés pour récupérer le numéro du " -"mobile. Exemple: vous sélectionnez une facture, alors, " +"portable. Exemple: vous sélectionnez une facture, alors, " "`object.invoice_address_id.mobile` est le champ qui représente le numéro du " -"mobile correct." +"portable correct." #. module: base #: view:base.module.upgrade:0 @@ -9274,7 +9274,7 @@ msgstr "%j - Jour dans l'année [001,366]." #. module: base #: field:ir.actions.server,mobile:0 msgid "Mobile No" -msgstr "N° de téléphone mobile" +msgstr "N° de portable" #. module: base #: model:ir.actions.act_window,name:base.action_partner_by_category From 204613eee343951e20c90e2db84c9b96ba33bb7c Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 10:36:36 +0100 Subject: [PATCH 03/10] [IMP] testing lp to have two po terms different context, same id: warehouse, fr bzr revid: fp@tinyerp.com-20110104093636-hxvrtkgm16mzj6tv --- addons/stock/i18n/fr.po | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/stock/i18n/fr.po b/addons/stock/i18n/fr.po index e17796027d7..6346aa1af74 100644 --- a/addons/stock/i18n/fr.po +++ b/addons/stock/i18n/fr.po @@ -2806,11 +2806,15 @@ msgstr "Nom de révision" #. module: stock #: model:ir.model,name:stock.model_stock_warehouse -#: model:ir.ui.menu,name:stock.menu_stock_root #: view:stock.warehouse:0 msgid "Warehouse" msgstr "Entrepôt" +#. module: stock +#: model:ir.ui.menu,name:stock.menu_stock_root +msgid "Warehouse" +msgstr "Stocks" + #. module: stock #: view:stock.location.product:0 msgid "" From 5134ceaff7f472be463fcd3d9b85d7761c18b283 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 11:02:35 +0100 Subject: [PATCH 04/10] [IMP] french translation bzr revid: fp@tinyerp.com-20110104100235-id212wyrrgl4l167 --- addons/mrp/i18n/fr.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mrp/i18n/fr.po b/addons/mrp/i18n/fr.po index 21c1e20d700..aed4bfa13ca 100644 --- a/addons/mrp/i18n/fr.po +++ b/addons/mrp/i18n/fr.po @@ -459,7 +459,7 @@ msgstr "Date planifiée" #. module: mrp #: report:mrp.production.order:0 msgid "Bill Of Material" -msgstr "Nomenclature des Matériaux" +msgstr "Nomenclature" #. module: mrp #: help:mrp.routing,location_id:0 @@ -480,7 +480,7 @@ msgstr "Variation de la valeur de stock" #. module: mrp #: model:ir.actions.act_window,name:mrp.action2 msgid "Bill of Materials Structure" -msgstr "Structure de la nomenclature" +msgstr "Structure des nomenclatures" #. module: mrp #: model:process.node,note:mrp.process_node_serviceproduct0 @@ -577,7 +577,7 @@ msgstr "Valeur du stock" #. module: mrp #: model:ir.actions.act_window,name:mrp.action_product_bom_structure msgid "Product BoM Structure" -msgstr "Structure de la Nomenclature des Produits" +msgstr "Structure des nomenclatures" #. module: mrp #: view:mrp.production:0 @@ -2228,7 +2228,7 @@ msgstr "Sélectionner quantité" #: model:ir.ui.menu,name:mrp.menu_mrp_bom_form_action #: field:product.product,bom_ids:0 msgid "Bill of Materials" -msgstr "Nomenclature" +msgstr "Nomenclatures" #. module: mrp #: help:mrp.routing.workcenter,routing_id:0 From 7873e79a77cd7b4ef9555ebf9ebee89eab0db306 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 11:08:53 +0100 Subject: [PATCH 05/10] [IMP] type fr.po bzr revid: fp@tinyerp.com-20110104100853-8jjac639ueau65qv --- addons/account/i18n/fr.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/i18n/fr.po b/addons/account/i18n/fr.po index e3232286a80..03056b8d204 100644 --- a/addons/account/i18n/fr.po +++ b/addons/account/i18n/fr.po @@ -489,7 +489,7 @@ msgstr "Date de création" #. module: account #: selection:account.journal,type:0 msgid "Purchase Refund" -msgstr "Remboursement d'achat" +msgstr "Avoir fournisseur" #. module: account #: selection:account.journal,type:0 @@ -1632,7 +1632,7 @@ msgstr "Compte fournisseurs débiteurs" #: field:account.tax,account_paid_id:0 #: field:account.tax.template,account_paid_id:0 msgid "Refund Tax Account" -msgstr "Compte de taxe à payer" +msgstr "Compte de taxe pour avoirs" #. module: account #: view:account.bank.statement:0 @@ -9899,7 +9899,7 @@ msgstr "Rechercher une facture" #: view:account.invoice.report:0 #: model:ir.actions.act_window,name:account.action_account_invoice_refund msgid "Refund" -msgstr "Rembourser" +msgstr "Créer un avoir" #. module: account #: field:wizard.multi.charts.accounts,bank_accounts_id:0 From 0de512ebe5d2f25fecef20c41b5642d7e50e020b Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Tue, 4 Jan 2011 11:11:55 +0100 Subject: [PATCH 06/10] [FIX] email_template : Cleaning mailbox send_mail bzr revid: tfr@openerp.com-20110104101155-lru81c424h9x9t4o --- .../email_template/email_template_mailbox.py | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/addons/email_template/email_template_mailbox.py b/addons/email_template/email_template_mailbox.py index acde96dafd4..f546e5f1e7b 100644 --- a/addons/email_template/email_template_mailbox.py +++ b/addons/email_template/email_template_mailbox.py @@ -69,28 +69,12 @@ class email_template_mailbox(osv.osv): try: account_obj = self.pool.get('email_template.account') values = self.read(cr, uid, id, [], context) - #payload = {} attach_to_send = None + if values['attachments_ids']: - #for attid in values['attachments_ids']: - #attachment = attachment_pool.browse(cr, uid, attid, context)#,['datas_fname','datas']) - #payload[attachment.datas_fname] = attachment.datas attach_to_send = self.pool.get('ir.attachment').read(cr, uid, values['attachments_ids'], ['datas_fname','datas', 'name']) attach_to_send = map(lambda x: (x['datas_fname'] or x['name'], base64.decodestring(x['datas'])), attach_to_send) - #work around to uniformize send email while waiting for a merge of fetchmail, email_template, mailgate - #using tools.send_email instead - #No need to use email account - #result = account_obj.send_mail(cr, uid, - # [values['account_id'][0]], - # {'To':values.get('email_to') or u'', - # 'CC':values.get('email_cc') or u'', - # 'BCC':values.get('email_bcc') or u'', - # 'Reply-To':values.get('reply_to') or u''}, - # values['subject'] or u'', - # {'text':values.get('body_text') or u'', 'html':values.get('body_html') or u''}, - # payload=payload, - # message_id=values['message_id'], - # context=context) + if values.get('body_html'): body = values.get('body_html') subtype = "html" From a0a18a7edc8a9a6e41d6629e740ed782c816dec5 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Tue, 4 Jan 2011 11:13:06 +0100 Subject: [PATCH 07/10] [FIX] email_template : revno of previous method bzr revid: tfr@openerp.com-20110104101306-1j1wmpjmb6k6e2f0 --- addons/email_template/email_template_mailbox.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/email_template/email_template_mailbox.py b/addons/email_template/email_template_mailbox.py index f546e5f1e7b..7483ade5d83 100644 --- a/addons/email_template/email_template_mailbox.py +++ b/addons/email_template/email_template_mailbox.py @@ -63,6 +63,7 @@ class email_template_mailbox(osv.osv): return True def send_this_mail(self, cr, uid, ids=None, context=None): + #previous method to send email (link with email account can be found at the revision 4172 and below result = True attachment_pool = self.pool.get('ir.attachment') for id in (ids or []): From bf16725dc8837021a5d9910ba57f01d96c680f64 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 4 Jan 2011 11:13:35 +0100 Subject: [PATCH 08/10] [FIX] all: ensure all open files are closed (partial patch courtesy of Lampman Trading) lp bug: https://launchpad.net/bugs/676931 fixed bzr revid: odo@openerp.com-20110104101335-964sl0e71zsgzfjw --- bin/addons/__init__.py | 74 +++++++++++++--------- bin/addons/base/ir/ir_actions.py | 4 ++ bin/addons/base/ir/ir_ui_menu.py | 8 ++- bin/addons/base/ir/ir_ui_view.py | 15 +++-- bin/addons/base/ir/wizard/wizard_screen.py | 8 ++- bin/addons/base/res/res_company.py | 6 +- bin/report/interface.py | 19 ++++-- bin/report/print_xml.py | 10 ++- bin/report/render/rml2pdf/trml2pdf.py | 36 ++++++----- bin/report/report_sxw.py | 50 +++++++++------ bin/tools/misc.py | 8 ++- bin/tools/translate.py | 16 +++-- bin/tools/yaml_import.py | 8 ++- 13 files changed, 164 insertions(+), 98 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index dcb8f3a2eb0..515b5e53db6 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -316,7 +316,11 @@ def load_information_from_description_file(module): for filename in ['__openerp__.py', '__terp__.py']: description_file = get_module_resource(module, filename) if description_file : - return eval(tools.file_open(description_file).read()) + desc_f = tools.file_open(description_file) + try: + return eval(desc_f.read()) + finally: + desc_f.close() #TODO: refactor the logger in this file to follow the logging guidelines # for 6.0 @@ -355,11 +359,14 @@ def upgrade_graph(graph, cr, module_list, force=None): continue if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'): + terp_f = tools.file_open(terp_file) try: - info = eval(tools.file_open(terp_file).read()) - except: + info = eval(terp_f.read()) + except Exception: logger.notifyChannel('init', netsvc.LOG_ERROR, 'module %s: eval file %s' % (module, terp_file)) raise + finally: + terp_f.close() if info.get('installable', True): packages.append((module, info.get('depends', []), info)) else: @@ -628,29 +635,33 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_cleanup= logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, filename)) _, ext = os.path.splitext(filename) fp = tools.file_open(opj(m, filename)) - if ext == '.csv': - noupdate = (kind == 'init') - tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate) - elif ext == '.sql': - process_sql_file(cr, fp) - elif ext == '.yml': - tools.convert_yaml_import(cr, m, fp, idref, mode=mode, **kwargs) - else: - tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs) - fp.close() + try: + if ext == '.csv': + noupdate = (kind == 'init') + tools.convert_csv_import(cr, m, os.path.basename(filename), fp.read(), idref, mode=mode, noupdate=noupdate) + elif ext == '.sql': + process_sql_file(cr, fp) + elif ext == '.yml': + tools.convert_yaml_import(cr, m, fp, idref, mode=mode, **kwargs) + else: + tools.convert_xml_import(cr, m, fp, idref, mode=mode, **kwargs) + finally: + fp.close() def load_demo_xml(cr, m, idref, mode): for xml in package.data.get('demo_xml', []): name, ext = os.path.splitext(xml) logger.notifyChannel('init', netsvc.LOG_INFO, 'module %s: loading %s' % (m, xml)) fp = tools.file_open(opj(m, xml)) - if ext == '.csv': - tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True) - elif ext == '.yml': - tools.convert_yaml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs) - else: - tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs) - fp.close() + try: + if ext == '.csv': + tools.convert_csv_import(cr, m, os.path.basename(xml), fp.read(), idref, mode=mode, noupdate=True) + elif ext == '.yml': + tools.convert_yaml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs) + else: + tools.convert_xml_import(cr, m, fp, idref, mode=mode, noupdate=True, **kwargs) + finally: + fp.close() def load_data(cr, module_name, id_map, mode): _load_data(cr, module_name, id_map, mode, 'data') @@ -678,17 +689,18 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_cleanup= log.info("module %s: loading %s", module_name, filename) pathname = os.path.join(module_name, filename) file = tools.file_open(pathname) - # TODO manage .csv file with noupdate == (kind == 'init') - if ext == '.sql': - process_sql_file(cr, file) - elif ext == '.csv': - noupdate = (kind == 'init') - tools.convert_csv_import(cr, module_name, pathname, file.read(), id_map, mode, noupdate) - elif ext == '.yml': - tools.convert_yaml_import(cr, module_name, file, id_map, mode, noupdate) - else: - tools.convert_xml_import(cr, module_name, file, id_map, mode, noupdate) - file.close() + try: + if ext == '.sql': + process_sql_file(cr, file) + elif ext == '.csv': + noupdate = (kind == 'init') + tools.convert_csv_import(cr, module_name, pathname, file.read(), id_map, mode, noupdate) + elif ext == '.yml': + tools.convert_yaml_import(cr, module_name, file, id_map, mode, noupdate) + else: + tools.convert_xml_import(cr, module_name, file, id_map, mode, noupdate) + finally: + file.close() # **kwargs is passed directly to convert_xml_import if not status: diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index c8ff67c18d9..7a07ca40ef8 100644 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -55,11 +55,15 @@ class report_xml(osv.osv): for report in self.browse(cursor, user, ids, context=context): data = report[name + '_data'] if not data and report[name[:-8]]: + fp = None try: fp = tools.file_open(report[name[:-8]], mode='rb') data = fp.read() except: data = False + finally: + if fp: + fp.close() res[report.id] = data return res diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py index 8696df80311..08725fbb9cb 100644 --- a/bin/addons/base/ir/ir_ui_menu.py +++ b/bin/addons/base/ir/ir_ui_menu.py @@ -257,8 +257,12 @@ class ir_ui_menu(osv.osv): def read_image(self, path): path_info = path.split(',') icon_path = addons.get_module_resource(path_info[0],path_info[1]) - icon = tools.file_open(icon_path,'rb').read() - return base64.encodestring(icon) + icon_file = tools.file_open(icon_path,'rb') + try: + icon = icon_file.read() + return base64.encodestring(icon) + finally: + icon_file.close() def _get_image_icon(self, cr, uid, ids, name, args, context=None): res = {} diff --git a/bin/addons/base/ir/ir_ui_view.py b/bin/addons/base/ir/ir_ui_view.py index 895f0051719..023c0cc4361 100644 --- a/bin/addons/base/ir/ir_ui_view.py +++ b/bin/addons/base/ir/ir_ui_view.py @@ -33,12 +33,15 @@ def _check_xml(self, cr, uid, ids, context=None): for view in self.browse(cr, uid, ids, context): eview = etree.fromstring(view.arch.encode('utf8')) frng = tools.file_open(os.path.join('base','rng','view.rng')) - relaxng_doc = etree.parse(frng) - relaxng = etree.RelaxNG(relaxng_doc) - if not relaxng.validate(eview): - for error in relaxng.error_log: - logger.error(tools.ustr(error)) - return False + try: + relaxng_doc = etree.parse(frng) + relaxng = etree.RelaxNG(relaxng_doc) + if not relaxng.validate(eview): + for error in relaxng.error_log: + logger.error(tools.ustr(error)) + return False + finally: + frng.close() return True class view_custom(osv.osv): diff --git a/bin/addons/base/ir/wizard/wizard_screen.py b/bin/addons/base/ir/wizard/wizard_screen.py index 56f104d0b13..5762bdc8752 100644 --- a/bin/addons/base/ir/wizard/wizard_screen.py +++ b/bin/addons/base/ir/wizard/wizard_screen.py @@ -31,8 +31,12 @@ class wizard_screen(osv.osv_memory): def _get_image(self, cr, uid, context=None): path = os.path.join('base','res','config_pixmaps','%d.png'%random.randrange(1,4)) - file_data = tools.file_open(path,'rb').read() - return base64.encodestring(file_data) + image_file = file_data = tools.file_open(path,'rb') + try: + file_data = image_file.read() + return base64.encodestring(file_data) + finally: + image_file.close() def _get_image_fn(self, cr, uid, ids, name, args, context=None): image = self._get_image(cr, uid, context) diff --git a/bin/addons/base/res/res_company.py b/bin/addons/base/res/res_company.py index 3fc4595c11c..8cafa28ccff 100644 --- a/bin/addons/base/res/res_company.py +++ b/bin/addons/base/res/res_company.py @@ -220,7 +220,11 @@ class res_company(osv.osv): """ def _get_header(self,cr,uid,ids): try : - return tools.file_open(os.path.join('base', 'report', 'corporate_rml_header.rml')).read() + header_file = tools.file_open(os.path.join('base', 'report', 'corporate_rml_header.rml')) + try: + return header_file.read() + finally: + header_file.close() except: return """
diff --git a/bin/report/interface.py b/bin/report/interface.py index 16dfafe0a18..ce14883986c 100644 --- a/bin/report/interface.py +++ b/bin/report/interface.py @@ -149,13 +149,18 @@ class report_rml(report_int): if not self.xsl: return xml - stylesheet = etree.parse(tools.file_open(self.xsl)) - xsl_path, _ = os.path.split(self.xsl) - for import_child in stylesheet.findall('./import'): - if 'href' in import_child.attrib: - imp_file = import_child.get('href') - _, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True) - import_child.set('href', urllib.quote(str(imp_file))) + stylesheet_file = tools.file_open(self.xsl) + try: + stylesheet = etree.parse(stylesheet_file) + xsl_path, _ = os.path.split(self.xsl) + for import_child in stylesheet.findall('./import'): + if 'href' in import_child.attrib: + imp_file = import_child.get('href') + _, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True) + import_child.set('href', urllib.quote(str(imp_file))) + imp_file.close() + finally: + stylesheet_file.close() #TODO: get all the translation in one query. That means we have to: # * build a list of items to translate, diff --git a/bin/report/print_xml.py b/bin/report/print_xml.py index 3319ee0b558..d637603d341 100644 --- a/bin/report/print_xml.py +++ b/bin/report/print_xml.py @@ -283,9 +283,13 @@ class document(object): if not context: context={} # parses the xml template to memory - self.dom = etree.XML(tools.file_open(filename).read()) - self.doc = etree.Element(self.dom.tag) - self.parse_tree(ids, model, context) + src_file = tools.file_open(filename) + try: + self.dom = etree.XML(src_file.read()) + self.doc = etree.Element(self.dom.tag) + self.parse_tree(ids, model, context) + finally: + src_file.close() def close(self): self.doc = None diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index 40b884f5a06..df826d0eace 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -477,24 +477,26 @@ class _rml_canvas(object): else: self._logger.debug("Open image file %s ", nfile) s = _open_image(nfile, path=self.path) - img = ImageReader(s) - (sx,sy) = img.getSize() - self._logger.debug("Image is %dx%d", sx, sy) - - args = { 'x': 0.0, 'y': 0.0 } - for tag in ('width','height','x','y'): - if node.get(tag): - args[tag] = utils.unit_get(node.get(tag)) - if ('width' in args) and (not 'height' in args): - args['height'] = sy * args['width'] / sx - elif ('height' in args) and (not 'width' in args): - args['width'] = sx * args['height'] / sy - elif ('width' in args) and ('height' in args): - if (float(args['width'])/args['height'])>(float(sx)>sy): - args['width'] = sx * args['height'] / sy - else: + try: + img = ImageReader(s) + (sx,sy) = img.getSize() + self._logger.debug("Image is %dx%d", sx, sy) + args = { 'x': 0.0, 'y': 0.0 } + for tag in ('width','height','x','y'): + if node.get(tag): + args[tag] = utils.unit_get(node.get(tag)) + if ('width' in args) and (not 'height' in args): args['height'] = sy * args['width'] / sx - self.canvas.drawImage(img, **args) + elif ('height' in args) and (not 'width' in args): + args['width'] = sx * args['height'] / sy + elif ('width' in args) and ('height' in args): + if (float(args['width'])/args['height'])>(float(sx)>sy): + args['width'] = sx * args['height'] / sy + else: + args['height'] = sy * args['width'] / sx + self.canvas.drawImage(img, **args) + finally: + s.close() # self.canvas._doc.SaveToFile(self.canvas._filename, self.canvas) def _path(self, node): diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index fe04ca6b680..6a7890be735 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -401,13 +401,17 @@ class report_sxw(report_rml, preprocess.report): report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context) else: title = '' - rml = tools.file_open(self.tmpl, subdir=None).read() - report_type= data.get('report_type', 'pdf') - class a(object): - def __init__(self, *args, **argv): - for key,arg in argv.items(): - setattr(self, key, arg) - report_xml = a(title=title, report_type=report_type, report_rml_content=rml, name=title, attachment=False, header=self.header) + report_file = tools.file_open(self.tmpl, subdir=None) + try: + rml = report_file.read() + report_type= data.get('report_type', 'pdf') + class a(object): + def __init__(self, *args, **argv): + for key,arg in argv.items(): + setattr(self, key, arg) + report_xml = a(title=title, report_type=report_type, report_rml_content=rml, name=title, attachment=False, header=self.header) + finally: + report_file.close() report_xml.header = self.header report_type = report_xml.report_type if report_type in ['sxw','odt']: @@ -590,20 +594,24 @@ class report_sxw(report_rml, preprocess.report): if report_xml.header: #Add corporate header/footer - rml = tools.file_open(os.path.join('base', 'report', 'corporate_%s_header.xml' % report_type)).read() - rml_parser = self.parser(cr, uid, self.name2, context=context) - rml_parser.parents = sxw_parents - rml_parser.tag = sxw_tag - objs = self.getObjects(cr, uid, ids, context) - rml_parser.set_context(objs, data, ids, report_xml.report_type) - rml_dom = self.preprocess_rml(etree.XML(rml),report_type) - create_doc = self.generators[report_type] - odt = create_doc(rml_dom,rml_parser.localcontext) - if report_xml.header: - rml_parser._add_header(odt) - odt = etree.tostring(odt, encoding='utf-8', - xml_declaration=True) - sxw_z.writestr('styles.xml', odt) + rml_file = tools.file_open(os.path.join('base', 'report', 'corporate_%s_header.xml' % report_type)) + try: + rml = rml_file.read() + rml_parser = self.parser(cr, uid, self.name2, context=context) + rml_parser.parents = sxw_parents + rml_parser.tag = sxw_tag + objs = self.getObjects(cr, uid, ids, context) + rml_parser.set_context(objs, data, ids, report_xml.report_type) + rml_dom = self.preprocess_rml(etree.XML(rml),report_type) + create_doc = self.generators[report_type] + odt = create_doc(rml_dom,rml_parser.localcontext) + if report_xml.header: + rml_parser._add_header(odt) + odt = etree.tostring(odt, encoding='utf-8', + xml_declaration=True) + sxw_z.writestr('styles.xml', odt) + finally: + rml_file.close() sxw_z.close() final_op = sxw_io.getvalue() sxw_io.close() diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 390be6b7837..015299bcf05 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -69,8 +69,12 @@ SKIPPED_ELEMENT_TYPES = (etree._Comment, etree._ProcessingInstruction, etree.Com def init_db(cr): import addons f = addons.get_module_resource('base', 'base.sql') - cr.execute(file_open(f).read()) - cr.commit() + base_sql_file = file_open(f) + try: + cr.execute(base_sql_file.read()) + cr.commit() + finally: + base_sql_file.close() for i in addons.get_modules(): mod_path = addons.get_module_path(i) diff --git a/bin/tools/translate.py b/bin/tools/translate.py index e22c51af0fd..c1c09140d0a 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -681,9 +681,13 @@ def trans_generate(lang, modules, dbname=None): report_type = "xsl" if fname and obj.report_type in ('pdf', 'xsl'): try: - d = etree.parse(tools.file_open(fname)) - for t in parse_func(d.iter()): - push_translation(module, report_type, name, 0, t) + report_file = tools.file_open(fname) + try: + d = etree.parse(report_file) + for t in parse_func(d.iter()): + push_translation(module, report_type, name, 0, t) + finally: + report_file.close() except (IOError, etree.XMLSyntaxError): logger.exception("couldn't export translation for report %s %s %s", name, report_type, fname) @@ -772,7 +776,11 @@ def trans_generate(lang, modules, dbname=None): is_mod_installed = module in installed_modules if (('all' in modules) or (module in modules)) and is_mod_installed: logger.debug("Scanning code of %s at module: %s", frelativepath, module) - code_string = tools.file_open(fabsolutepath, subdir='').read() + src_file = tools.file_open(fabsolutepath, subdir='') + try: + code_string = src_file.read() + finally: + src_file.close() if module in installed_modules: frelativepath = str("addons" + frelativepath) ite = re_dquotes.finditer(code_string) diff --git a/bin/tools/yaml_import.py b/bin/tools/yaml_import.py index 6e5a581be73..2b5c982ca7b 100644 --- a/bin/tools/yaml_import.py +++ b/bin/tools/yaml_import.py @@ -684,8 +684,12 @@ class YamlInterpreter(object): if node.auto: values['auto'] = eval(node.auto) if node.sxw: - sxw_content = misc.file_open(node.sxw).read() - values['report_sxw_content'] = sxw_content + sxw_file = misc.file_open(node.sxw) + try: + sxw_content = sxw_file.read() + values['report_sxw_content'] = sxw_content + finally: + sxw_file.close() if node.header: values['header'] = eval(node.header) values['multi'] = node.multi and eval(node.multi) From 4a90463eb65e5f80c9b31bfa7689ad973dfcde9e Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 4 Jan 2011 11:18:47 +0100 Subject: [PATCH 09/10] [IMP] better menu tip for modules bzr revid: fp@tinyerp.com-20110104101847-d1tjsqitciprle1f --- bin/addons/base/i18n/fr.po | 2 +- bin/addons/base/module/module_view.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/addons/base/i18n/fr.po b/bin/addons/base/i18n/fr.po index 72864052558..03a93e16a33 100644 --- a/bin/addons/base/i18n/fr.po +++ b/bin/addons/base/i18n/fr.po @@ -7167,7 +7167,7 @@ msgstr "Tunisie" #. module: base #: model:ir.ui.menu,name:base.menu_mrp_root msgid "Manufacturing" -msgstr "Gestion de Production" +msgstr "GPAO" #. module: base #: view:base.language.export:0 diff --git a/bin/addons/base/module/module_view.xml b/bin/addons/base/module/module_view.xml index 2d391cdd8e6..16527641656 100644 --- a/bin/addons/base/module/module_view.xml +++ b/bin/addons/base/module/module_view.xml @@ -169,7 +169,7 @@ tree,form - List all certified modules available to configure your OpenERP. Modules that are installed are flagged as such. You can search for a specific module using the name or the description of the module. You do not need to install modules one by one, you can install many at the same time by clicking on the schedule button in this list. Then, apply the schedule upgrade from Action menu once for all the ones you have scheduled for installation. + You can install new modules in order to activate new features, menu, reports or data in your OpenERP instance. To install some modules, click on the button "Schedule for Installation" from the form view, then click on "Apply Scheduled Upgrades" to migrate your system. From 4ae76de3ded8acdac9a4569397f1fe904bf8d955 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Tue, 4 Jan 2011 12:27:52 +0100 Subject: [PATCH 10/10] [FIX] mrp/report : fix pychart import bzr revid: tfr@openerp.com-20110104112752-xi0p9xfxbwf6wi7j --- addons/mrp/report/workcenter_load.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/mrp/report/workcenter_load.py b/addons/mrp/report/workcenter_load.py index befde4d8667..95331d6fdf0 100644 --- a/addons/mrp/report/workcenter_load.py +++ b/addons/mrp/report/workcenter_load.py @@ -30,6 +30,8 @@ from report.misc import choice_colors import random import StringIO +from pychart import * + theme.use_color = 1 random.seed(0)