Skip to content

Commit

Permalink
[ADD] file-not-used: Emit message if there are xml, yml, sql or csv f…
Browse files Browse the repository at this point in the history
…iles but It isn't referenced from manifest (#53)

[ADD] file-not-used: Emit message if there are xml, yml, sql or csv files but It isn't referenced from manifest
  • Loading branch information
moylop260 authored and pedrobaeza committed Aug 19, 2016
1 parent c9bf52a commit 91dc3e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
50 changes: 48 additions & 2 deletions pylint_odoo/checkers/modules_odoo.py
@@ -1,6 +1,7 @@
"""Visit module to add odoo checks
"""

import ast
import os

import astroid
Expand Down Expand Up @@ -96,13 +97,22 @@
'dangerous-view-replace-wo-priority',
settings.DESC_DFLT
),
'W%d30' % settings.BASE_OMODULE_ID: (
'%s not used from manifest',
'file-not-used',
settings.DESC_DFLT
),
}


DFTL_README_TMPL_URL = 'https://github.com/OCA/maintainer-tools' + \
'/blob/master/template/module/README.rst'
DFTL_EXTFILES_TO_LINT = ['xml', 'csv', 'po', 'js', 'mako']
DFTL_MIN_PRIORITY = 99
# Files supported from manifest to convert
# Extracted from openerp/tools/convert.py:def convert_file
DFLT_EXTFILES_CONVERT = ['csv', 'sql', 'xml', 'yml']
DFLT_EXTFILES_TO_LINT = DFLT_EXTFILES_CONVERT + [
'po', 'js', 'mako', 'rst', 'md', 'markdown']


class ModuleChecker(misc.WrapperModuleChecker):
Expand All @@ -118,7 +128,7 @@ class ModuleChecker(misc.WrapperModuleChecker):
('extfiles_to_lint', {
'type': 'csv',
'metavar': '<comma separated values>',
'default': DFTL_EXTFILES_TO_LINT,
'default': DFLT_EXTFILES_TO_LINT,
'help': 'List of extension files to check separated by a comma.'
}),
('min-priority', {
Expand All @@ -127,6 +137,13 @@ class ModuleChecker(misc.WrapperModuleChecker):
'default': DFTL_MIN_PRIORITY,
'help': 'Minimum priority number of a view with replace of fields.'
}),
('extfiles_convert', {
'type': 'csv',
'metavar': '<comma separated values>',
'default': DFLT_EXTFILES_CONVERT,
'help': 'List of extension files supported to convert '
'from manifest separated by a comma.'
}),
)

class_inherit_names = []
Expand Down Expand Up @@ -495,3 +512,32 @@ def _check_missing_newline_extrafiles(self):
if self.msg_args:
return False
return True

def _get_manifest_referenced_files(self):
referenced_files = []
data_keys = ['data', 'demo', 'demo_xml', 'init_xml', 'test',
'update_xml']
with open(self.manifest_file) as f_manifest:
manifest_dict = ast.literal_eval(f_manifest.read())
for key in data_keys:
referenced_files.extend(manifest_dict.get(key) or [])
return referenced_files

def _get_module_files(self):
module_files = []
for type_file in self.config.extfiles_convert:
for ext_file_rel in self.filter_files_ext(type_file, relpath=True):
module_files.append(ext_file_rel)
return module_files

def _check_file_not_used(self):
"""Check if a file is not used from manifest"""
self.msg_args = []
module_files = set(self._get_module_files())
referenced_files = set(self._get_manifest_referenced_files())
for no_referenced_file in (module_files - referenced_files):
if not no_referenced_file.startswith('static/'):
self.msg_args.append((no_referenced_file,))
if self.msg_args:
return False
return True
1 change: 1 addition & 0 deletions pylint_odoo/test/main.py
Expand Up @@ -23,6 +23,7 @@
'duplicate-id-csv': 2,
'duplicate-xml-fields': 6,
'duplicate-xml-record-id': 2,
'file-not-used': 8,
'incoherent-interpreter-exec-perm': 3,
'invalid-commit': 4,
'javascript-lint': 2,
Expand Down
2 changes: 2 additions & 0 deletions pylint_odoo/test_repo/test_module/__openerp__.py
Expand Up @@ -9,6 +9,8 @@
],
'data': [
'security/ir.model.access.csv',
'res_users.xml',
'model_view.xml',
],
'external_dependencies': {
'bin': [
Expand Down
3 changes: 3 additions & 0 deletions pylint_odoo/test_repo/test_module/static/src/xml/widget.xml
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
</templates>

0 comments on commit 91dc3e4

Please sign in to comment.