Ejemplo n.º 1
0
    def _check_external_dependencies(terp):
        depends = terp.get('external_dependencies')
        if not depends:
            return
        for pydep in depends.get('python', []):
            Module._check_python_external_dependency(pydep)

        for binary in depends.get('bin', []):
            try:
                tools.find_in_path(binary)
            except IOError:
                raise Exception('Unable to find %r in path' % (binary,))
Ejemplo n.º 2
0
    def _check_external_dependencies(terp):
        depends = terp.get('external_dependencies')
        if not depends:
            return
        for pydep in depends.get('python', []):
            try:
                importlib.import_module(pydep)
            except ImportError:
                raise ImportError('No module named %s' % (pydep, ))

        for binary in depends.get('bin', []):
            try:
                tools.find_in_path(binary)
            except IOError:
                raise Exception('Unable to find %r in path' % (binary, ))
Ejemplo n.º 3
0
    def _check_external_dependencies(terp):
        depends = terp.get('external_dependencies')
        if not depends:
            return
        for pydep in depends.get('python', []):
            try:
                importlib.import_module(pydep)
            except ImportError:
                raise ImportError('No module named %s' % (pydep,))

        for binary in depends.get('bin', []):
            try:
                tools.find_in_path(binary)
            except IOError:
                raise Exception('Unable to find %r in path' % (binary,))
Ejemplo n.º 4
0
    def _run(self, test_mode=False):
        _logger.info('==========Rotating Server Logfile==========')
        try:
            log = self.search([], limit=0)

            if not log:
                raise UserError('Logrotate config not found')

            executor = find_in_path('logrotate')
            mode = '-d' if test_mode else '-f'
            process = Popen([executor, mode, log.config], stderr=PIPE)
            _, err_msg = process.communicate()

            if process.returncode:
                if err_msg:
                    err_msg = err_msg.decode('unicode_escape')
                else:
                    err_msg = 'Rotating failed with exit code {}'.format(
                        process.returncode)

                raise UserError(err_msg)

            self._log()
            _logger.info(
                '==========Server Logfile Successfully Rotated==========')
        except Exception:
            self._log(traceback.format_exc(chain=False), error=True)
            _logger.info(
                '==========Rotating Server Logfile is Failed==========')

        return True
Ejemplo n.º 5
0
 def _get_pgbadger_command(self):
     self.ensure_one()
     # TODO: Catch early the following errors.
     try:
         pgbadger_bin = tools.find_in_path('pgbadger')
     except IOError:
         self.description += ("\nInstall 'apt-get install pgbadger'")
         return
     try:
         if not self.pg_log_path:
             raise IOError
         with open(self.pg_log_path, "r"):
             pass
     except IOError:
         self.description += (
             "\nCheck if exists and has permission to read the log file."
             "\nMaybe running: chmod 604 '%s'") % self.pg_log_path
         return
     pgbadger_cmd = [
         pgbadger_bin,
         '-f',
         'stderr',
         '--sample',
         '15',
         '-o',
         '-',
         '-x',
         'html',
         '--quiet',
         '-T',
         self.name,
         '-d',
         self.env.cr.dbname,
         '-b',
         self.date_started,
         '-e',
         self.date_finished,
         self.pg_log_path,
     ]
     return pgbadger_cmd
Ejemplo n.º 6
0
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
#   (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from odoo import api, fields, models, tools
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from datetime import datetime
_logger = logging.getLogger(__name__)

try:
    from statistics import mean
    STATS_PATH = tools.find_in_path('statistics')
except (ImportError, IOError) as err:
    _logger.debug(err)


class StockLocation(models.Model):
    _inherit = 'stock.location'

    def _compute_loc_accuracy(self):
        for rec in self:
            history = self.env['stock.inventory'].search([
                ('location_id', '=', rec.id), ('state', '=', 'done')
            ])
            history = history.sorted(key=lambda r: r.write_date, reverse=True)
            if history:
                wh = rec.get_warehouse()
                if wh.counts_for_accuracy_qty and \
                        len(history) > wh.counts_for_accuracy_qty:
Ejemplo n.º 7
0
# Copyright 2017 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from io import BytesIO
import PyPDF2
import os
from contextlib import closing
import logging
import tempfile
from subprocess import Popen, PIPE
from odoo import api, models, tools

_logger = logging.getLogger(__name__)
try:
    from fdfgen import forge_fdf
    EXTERNAL_DEPENDENCY_BINARY_PDFTK = tools.find_in_path('pdftk')
except (ImportError, IOError) as err:
    _logger.debug('Error while importing: %s.' % err)
    EXTERNAL_DEPENDENCY_BINARY_PDFTK = ""


class ReportFillPDFAbstract(models.AbstractModel):
    _name = 'report.report_fillpdf.abstract'

    def fill_report(self, docids, data):
        objs = self.env[self.env.context.get('active_model')].browse(docids)
        oring_file = self.get_original_document_path(data, objs)
        document_values = self.get_document_values(data, objs)
        pdf_file = PyPDF2.PdfFileReader(oring_file)
        fields = pdf_file.getFields()
        readonly_fields = [
Ejemplo n.º 8
0
# Copyright 2017-18 ForgeFlow S.L.
#   (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging
from datetime import datetime

from odoo import fields, models, tools
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

_logger = logging.getLogger(__name__)

try:
    from statistics import mean

    STATS_PATH = tools.find_in_path("statistics")
except (ImportError, IOError) as err:
    _logger.debug(err)


class StockLocation(models.Model):
    _inherit = "stock.location"

    def _compute_loc_accuracy(self):
        for rec in self:
            history = self.env["stock.inventory"].search(
                [("location_ids", "in", rec.id), ("state", "=", "done")],
                order="write_date desc",
            )
            if history:
                wh = rec.get_warehouse()
Ejemplo n.º 9
0
def _get_wkhtmltopdf_bin():
    return find_in_path("wkhtmltopdf")
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
from odoo import tools

_logger = logging.getLogger(__name__)

try:
    from openupgradelib import openupgrade
    EXTERNAL_DEPENDENCY_BINARY_OPENUPGRADELIB_PATH = tools.find_in_path(
        'openupgradelib')
except (ImportError, IOError) as err:
    _logger.debug(err)


def pre_init_hook(cr):
    """Loaded before installing the module.
    """
    openupgrade.update_module_names(
        cr, [('stock_location_restrict_group',
              'stock_location_restrict_procurement_group')],
        merge_modules=True)
Ejemplo n.º 11
0
# -*- coding: utf-8 -*-

import logging
from os import path
from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)

try:
    import textract
    TEXTRACT_PATH = tools.find_in_path('textract')
except (ImportError, IOError) as err:
    _logger.debug(err)


class Document(models.Model):

    _name = 'tmc.document'
    _inherit = 'tmc.document'

    indexed_content = fields.Text(readonly=True)

    pdf_url = fields.Char(compute='_compute_pdf_url', readonly=True)

    def _get_path_and_url(self):
        try:
            repository_path = self.env['ir.config_parameter'].get_param(
                'tmc.document.repository_path')
            repository_url = self.env['ir.config_parameter'].get_param(
                'tmc.document.repository_url')
# -*- coding: utf-8 -*-
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
#   (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from odoo import api, fields, models, tools
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from datetime import datetime

_logger = logging.getLogger(__name__)

try:
    from numpy import mean
    NUMPY_PATH = tools.find_in_path('numpy')
except (ImportError, IOError) as err:
    _logger.debug(err)


class StockLocation(models.Model):
    _inherit = 'stock.location'

    @api.multi
    def _compute_loc_accuracy(self):
        for rec in self:
            history = self.env['stock.inventory'].search([
                ('location_id', '=', rec.id), ('state', '=', 'done')
            ])
            history = history.sorted(key=lambda r: r.write_date, reverse=True)
            if history: