You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # Copyright 2017 LasLabs Inc.
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  3. import logging
  4. from odoo import api, fields, models
  5. from odoo.modules.module import get_module_path
  6. _logger = logging.getLogger(__name__)
  7. try:
  8. from checksumdir import dirhash
  9. except ImportError:
  10. _logger.debug('Cannot `import checksumdir`.')
  11. class Module(models.Model):
  12. _inherit = 'ir.module.module'
  13. checksum_dir = fields.Char(
  14. compute='_compute_checksum_dir',
  15. )
  16. checksum_installed = fields.Char()
  17. @api.depends('name')
  18. def _compute_checksum_dir(self):
  19. exclude = self.env["ir.config_parameter"].get_param(
  20. "module_auto_update.checksum_excluded_extensions",
  21. "pyc,pyo",
  22. ).split(",")
  23. for r in self:
  24. try:
  25. r.checksum_dir = dirhash(
  26. get_module_path(r.name),
  27. 'sha1',
  28. excluded_extensions=exclude,
  29. )
  30. except TypeError:
  31. _logger.debug(
  32. "Cannot compute dir hash for %s, module not found",
  33. r.display_name)
  34. @api.multi
  35. def _store_checksum_installed(self, vals):
  36. """Store the right installed checksum, if addon is installed."""
  37. if 'checksum_installed' not in vals:
  38. try:
  39. version = vals["latest_version"]
  40. except KeyError:
  41. return # Not [un]installing/updating any addon
  42. if version is False:
  43. # Uninstalling
  44. self.write({'checksum_installed': False})
  45. else:
  46. # Installing or updating
  47. for one in self:
  48. one.checksum_installed = one.checksum_dir
  49. @api.model
  50. def create(self, vals):
  51. res = super(Module, self).create(vals)
  52. res._store_checksum_installed(vals)
  53. return res
  54. @api.multi
  55. def write(self, vals):
  56. res = super(Module, self).write(vals)
  57. self._store_checksum_installed(vals)
  58. return res