def get_lib(self, cursor, uid): """Return the lib wkhtml path""" env = api.Environment(cursor, SUPERUSER_ID, {}) proxy = env['ir.config_parameter'] webkit_path = proxy.get_param('webkit_path') #print "===webkit_path===",webkit_path if not webkit_path: try: defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) #print "===os.pathsep.join(defpath)===",os.pathsep.join(defpath) if hasattr(sys, 'frozen'): defpath.append(os.getcwd()) if tools.config['root_path']: defpath.append(os.path.dirname(tools.config['root_path'])) webkit_path = tools.which('wkhtmltopdf', path=os.pathsep.join(defpath)) except IOError: webkit_path = None #print "===eeeeewebkit_path===",webkit_path if webkit_path: return webkit_path raise UserError(_('Wkhtmltopdf library path is not set') + ' ' + _('Please install executable on your system' ' (sudo apt-get install wkhtmltopdf) or download it from here:' ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the' ' path in the ir.config_parameter with the webkit_path key.' 'Minimal version is 0.9.9'))
def get_lib(self, cr, uid): """Return the lib wkhtml path""" proxy = self.env['ir.config_parameter'].sudo() webkit_path = proxy.get_param('webkit_path') if not webkit_path: try: defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) if hasattr(sys, 'frozen'): defpath.append(os.getcwd()) if tools.config['root_path']: defpath.append(os.path.dirname(tools.config['root_path'])) webkit_path = tools.which('wkhtmltopdf', path=os.pathsep.join(defpath)) except IOError: webkit_path = None if webkit_path: return webkit_path raise UserError(_('Wkhtmltopdf library path is not set') + ' ' + _('Please install executable on your system' ' (sudo apt-get install wkhtmltopdf) or download it from here:' ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the' ' path in the ir.config_parameter with the webkit_path key.' 'Minimal version is 0.9.9'))
def __initialize_repo(self): self.ensure_one() if os.path.exists(self.local_directory): raise ValidationError( 'Repository {} already exists, choose a different name!'. format(self.system_name)) subprocess.check_call( [which('git'), 'init', '--bare', self.local_directory])
def _installed_version(self, env, name): try: exe = which(name) out = str(subprocess.check_output([exe, '--version'])) # Py3 str() match = re.search('[\d.]+', out) if not match: raise CheckWarning( 'Unable to detect version for executable {}'.format(name), details="Command {} --version returned <pre>{}</pre>".format(exe, out) ) return match.group(0) except subprocess.CalledProcessError as e: raise CheckWarning( 'Unable to detect version for executable {}: {}'.format(name, e), details=self._details() )
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') required_pylint_version = LooseVersion('1.6.4') if sys.version_info >= (3, 6): required_pylint_version = LooseVersion('1.7.0') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < required_pylint_version: self._skip_test('please upgrade pylint to >= %s' % required_pylint_version) paths = [tools.config['root_path']] for module in get_modules(): module_path = get_module_path(module) if not module_path.startswith( join(tools.config['root_path'], 'addons')): paths.append(module_path) options = [ '--rcfile=%s' % os.devnull, '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", '--load-plugins=pylint.extensions.bad_builtin,_odoo_checker_sql_injection,_odoo_checker_gettext', '--bad-functions=%s' % ','.join(self.BAD_FUNCTIONS), '--deprecated-modules=%s' % ','.join(self.BAD_MODULES) ] pypath = HERE + os.pathsep + os.environ.get('PYTHONPATH', '') env = dict(os.environ, PYTHONPATH=pypath) try: pylint_bin = tools.which('pylint') process = subprocess.Popen( [pylint_bin] + options + paths, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, ) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out, err = process.communicate() if process.returncode: self.fail("pylint test failed:\n" + (b"\n" + out + b"\n" + err).decode('utf-8').strip())
def test_pylint(self): if pylint is None: self._skip_test('please install pylint') required_pylint_version = LooseVersion('1.6.4') if sys.version_info >= (3, 6): required_pylint_version = LooseVersion('1.7.0') if LooseVersion(getattr(pylint, '__version__', '0.0.1')) < required_pylint_version: self._skip_test('please upgrade pylint to >= %s' % required_pylint_version) paths = [tools.config['root_path']] for module in get_modules(): module_path = get_module_path(module) if not module_path.startswith(join(tools.config['root_path'], 'addons')): paths.append(module_path) options = [ '--rcfile=%s' % os.devnull, '--disable=all', '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n', "--msg-template='{msg} ({msg_id}) at {path}:{line}'", '--load-plugins=pylint.extensions.bad_builtin,_odoo_checkers', '--bad-functions=%s' % ','.join(self.BAD_FUNCTIONS), '--deprecated-modules=%s' % ','.join(self.BAD_MODULES) ] pypath = HERE + os.pathsep + os.environ.get('PYTHONPATH', '') env = dict(os.environ, PYTHONPATH=pypath) try: pylint_bin = tools.which('pylint') process = subprocess.Popen( [pylint_bin] + options + paths, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, ) except (OSError, IOError): self._skip_test('pylint executable not found in the path') else: out, err = process.communicate() if process.returncode: self.fail("pylint test failed:\n" + (b"\n" + out + b"\n" + err).decode('utf-8').strip())
def _dependency_installed(self, env, name): try: which(name) return True except IOError: return False
import json import os import tempfile import unittest from subprocess import run, PIPE from textwrap import dedent from odoo import tools from odoo.tests.common import TransactionCase try: import pylint except ImportError: pylint = None try: pylint_bin = tools.which('pylint') except IOError: pylint_bin = None HERE = os.path.dirname(os.path.realpath(__file__)) @unittest.skipUnless(pylint and pylint_bin, "testing lints requires pylint") class TestSqlLint(TransactionCase): def check(self, testtext): with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', delete=False) as f: self.addCleanup(os.remove, f.name) f.write(dedent(testtext).strip())