← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/stock-logistic-barcode/7.0-fix_1182904-houssinebakali+afe into lp:stock-logistic-barcode

 

Alexandre Fayolle - camptocamp has proposed merging lp:~camptocamp/stock-logistic-barcode/7.0-fix_1182904-houssinebakali+afe into lp:stock-logistic-barcode.

Requested reviews:
  Stock and Logistic Core Editors (stock-logistic-core-editors)
Related bugs:
  Bug #1182904 in Stock And Logistic Bar Code: "Useless dependency on rsvg-convert"
  https://bugs.launchpad.net/stock-logistic-barcode/+bug/1182904
  Bug #1285603 in Stock And Logistic Bar Code: "tr_barcode: race condition in barcode generation"
  https://bugs.launchpad.net/stock-logistic-barcode/+bug/1285603

For more details, see:
https://code.launchpad.net/~camptocamp/stock-logistic-barcode/7.0-fix_1182904-houssinebakali+afe/+merge/208584

remove useless dependency on rsvg-convert (lp:1182904)
remove some insecure temporary file management (lp:1285603)
-- 
https://code.launchpad.net/~camptocamp/stock-logistic-barcode/7.0-fix_1182904-houssinebakali+afe/+merge/208584
Your team Stock and Logistic Core Editors is requested to review the proposed merge of lp:~camptocamp/stock-logistic-barcode/7.0-fix_1182904-houssinebakali+afe into lp:stock-logistic-barcode.
=== modified file 'tr_barcode/tr_barcode.py'
--- tr_barcode/tr_barcode.py	2013-02-18 09:27:15 +0000
+++ tr_barcode/tr_barcode.py	2014-02-27 12:26:04 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #/#############################################################################
-#    
+#
 #    Tech-Receptives Solutions Pvt. Ltd.
 #    Copyright (C) 2004-TODAY Tech-Receptives(<http://www.tech-receptives.com>).
 #
@@ -15,19 +15,23 @@
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 #/#############################################################################
 
 import os
+import logging
+import base64
+from tempfile import mkstemp
+
+_logger = logging.getLogger(__name__)
 from openerp.osv import fields, osv, orm
-import base64
+
 from PIL import Image
 try:
-    from reportlab.graphics.barcode import createBarcodeDrawing, \
-            getCodes
+    from reportlab.graphics.barcode import createBarcodeDrawing, getCodes
 except :
-    print "ERROR IMPORTING REPORT LAB"
+    _logger.warning("ERROR IMPORTING REPORT LAB")
 
 def _get_code(self, cr, uid, context=None):
     """get availble code """
@@ -40,14 +44,14 @@
     _name = "tr.barcode"
     _description = "Barcode"
     _rec_name = 'code'
-    
+
     def _get_barcode2(self, cr, uid, ids, name, attr, context=None):
         res = {}
         barcodes = self.browse(cr, uid, ids, context=context)
         for barcode in barcodes:
             res[barcode.id] = barcode.code
         return res
-    
+
     _columns = {
         'code': fields.char('Barcode',size=256),
         'code2': fields.function(_get_barcode2, method=True, string='Barcode2', type='char', size=256, store=True),
@@ -76,16 +80,21 @@
                 ret_val = createBarcodeDrawing(code, value=str(value), **options)
             except Exception, e:
                 raise osv.except_osv('Error', e)
-            ret_val.save(formats=['svg'], fnRoot='barcode', outDir='/tmp/')
-            os.system('rsvg-convert %s -o %s' % ('/tmp/barcode.svg', '/tmp/barcode.png'))
-            return base64.encodestring(open("/tmp/barcode.png","rb").read())
+            image_data = ret_val.asString('png')
+            return base64.encodestring(image_data)
         else:
             ret_val = False
             from qrtools import QR
+            fd, temp_path = mkstemp(suffix='.png')
             qrCode = QR(data=value)
-            qrCode.encode()
-            return base64.encodestring(open(qrCode.filename,"rb").read())
-    
+            qrCode.encode(temp_path)
+            fdesc = open(qrCode.filename,"rb")
+            data = base64.encodestring(fdesc.read())
+            fdesc.close()
+            os.close(fd)
+            os.remove(temp_path)
+            return data
+
     def generate_image(self, cr, uid, ids, context=None):
         "button function for genrating image """
         if not context:


Follow ups