Browse Source

[REM] rem cert hash

12.0-vracoop-pos
default 3 years ago
parent
commit
7e5a259319
  1. 1
      pos_hash_cert/__init__.py
  2. 14
      pos_hash_cert/__manifest__.py
  3. 1
      pos_hash_cert/models/__init__.py
  4. 63
      pos_hash_cert/models/pos_hash_cert.py
  5. 15
      pos_hash_cert/views/ir_module.xml

1
pos_hash_cert/__init__.py

@ -1 +0,0 @@
from . import models

14
pos_hash_cert/__manifest__.py

@ -1,14 +0,0 @@
{
"name": "POS Hash Certification",
"summary": "Module de certification ",
"version": "12.0.1.0.1",
"category": "POS",
"website": "https://vracoop.fr/",
"author": " Coop IT Easy SCRLfs",
"license": "AGPL-3",
"application": False,
"installable": True,
"external_dependencies": {"python": ["checksumdir"]},
"depends": [],
"data": ["views/ir_module.xml"],
}

1
pos_hash_cert/models/__init__.py

@ -1 +0,0 @@
from . import pos_hash_cert

63
pos_hash_cert/models/pos_hash_cert.py

@ -1,63 +0,0 @@
import logging
import os
from odoo import api, fields, models
from odoo.tools.config import config
from checksumdir import dirhash
_logger = logging.getLogger(__name__)
CERT_DIR = config.get('certified_modules_directory', 'pos_certified_modules')
USER_DIR = os.path.expanduser("~")
class ModuleHash(models.Model):
_inherit = 'ir.module.module'
hash = fields.Char(compute='_compute_hash',
help='Module hash')
@api.multi
def _compute_hash(self):
_logger.debug("[pos_hash_cert] USER_DIR = %s" % USER_DIR)
start_dir = os.path.dirname(os.path.realpath(__file__))
_logger.debug("[pos_hash_cert] start_DIR = %s" % start_dir)
last_root = start_dir
current_root = start_dir
found_cert_dir = None
while found_cert_dir is None and current_root != os.path.dirname(USER_DIR):
pruned = False
for root, dirs, files in os.walk(current_root):
if not pruned:
try:
# Remove the part of the tree we already searched
del dirs[dirs.index(os.path.basename(last_root))]
pruned = True
except ValueError:
pass
if CERT_DIR in dirs:
# found the directory, stop
found_cert_dir = os.path.join(root, CERT_DIR)
break
# Otherwise, pop up a level, search again
last_root = current_root
current_root = os.path.dirname(last_root)
if found_cert_dir:
_logger.debug("[pos_hash_cert] found_cert_dir = %s" % found_cert_dir)
certified_modules = [
name
for name in os.listdir(found_cert_dir)
if os.path.isdir(os.path.join(found_cert_dir, name))
]
for record in self:
if record.name in certified_modules:
record.hash = dirhash(found_cert_dir, 'sha256', excluded_extensions=['pyc'])
else:
_logger.debug("[pos_hash_cert] no certified modules directory found")
pass

15
pos_hash_cert/views/ir_module.xml

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="view_hash_module">
<field name="name">ir.module.module.form.hashview</field>
<field name="model">ir.module.module</field>
<field name="inherit_id" ref="base.module_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='installed_version']" position="after">
<field name="hash" attrs="{'invisible':[('hash', '=', False)]}"/>
</xpath>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save