← Back to team overview

savoirfairelinux-openerp team mailing list archive

Re: [Merge] lp:~savoirfairelinux-openerp/knowledge-addons/cmis into lp:knowledge-addons/7.0

 

Looking a lot better, still issues about the comments preceding functions which would be more useful as docstrings.

Diff comments:

> === added directory 'cmis'
> === added file 'cmis/__init__.py'
> --- cmis/__init__.py	1970-01-01 00:00:00 +0000
> +++ cmis/__init__.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,26 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +from . import cmis_model
> +from . import backend
> +
> +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added file 'cmis/__openerp__.py'
> --- cmis/__openerp__.py	1970-01-01 00:00:00 +0000
> +++ cmis/__openerp__.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,62 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +{
> +    'name': 'CMIS',
> +    'version': '0.1',
> +    'category': 'Connector',
> +    'summary': 'Cmis Connector',
> +    'description': """
> +Cmis Connector
> +==============
> +
> +This module is the base for OpenERP modules implementing different integration scenario with a CMIS server.
> +It allows you to configure a CMIS backend in OpenERP.
> +
> +Configuration
> +=============
> +
> +Create a new CMIS backend with the host, login and password.
> +
> +Contributors
> +------------
> +* El Hadji Dem (elhadji.dem@xxxxxxxxxxxxxxxxxxxx)
> +""",
> +    'author': 'Savoir-faire Linux',
> +    'website': 'www.savoirfairelinux.com',
> +    'license': 'AGPL-3',
> +    'depends': [
> +        'connector',
> +    ],
> +    'data': [
> +        'cmis_model_view.xml',
> +        'cmis_menu.xml',
> +    ],
> +    'js': [],
> +    'qweb': [],
> +    'test': [],
> +    'demo': [],
> +    'installable': True,
> +    'auto_install': False,
> +}
> +
> +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added file 'cmis/backend.py'
> --- cmis/backend.py	1970-01-01 00:00:00 +0000
> +++ cmis/backend.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,32 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +import openerp.addons.connector.backend as backend
> +
> +
> +cmis = backend.Backend('cmis')
> +""" Generic CMIS Backend """
> +
> +cmis1000 = backend.Backend(parent=cmis, version='1.0')
> +""" CMIS Backend for version 1.0 """
> +
> +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added file 'cmis/cmis_menu.xml'
> --- cmis/cmis_menu.xml	1970-01-01 00:00:00 +0000
> +++ cmis/cmis_menu.xml	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,17 @@
> +<?xml version="1.0" encoding="utf-8"?>
> +<openerp>
> +  <data>
> +
> +    <menuitem id="menu_cmis_root"
> +              parent="connector.menu_connector_root"
> +              name="Cmis"
> +              sequence="10"
> +              groups="connector.group_connector_manager"/>
> +
> +    <menuitem id="menu_cmis_backend"
> +              name="Backends"
> +              parent="menu_cmis_root"
> +              action="action_cmis_backend"/>
> +
> +  </data>
> +</openerp>
> 
> === added file 'cmis/cmis_model.py'
> --- cmis/cmis_model.py	1970-01-01 00:00:00 +0000
> +++ cmis/cmis_model.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,183 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +from openerp.osv import orm, fields
> +from openerp.tools.translate import _
> +from cmislib.model import CmisClient
> +import cmislib.exceptions
> +import urllib2
> +
> +
> +class cmis_backend(orm.Model):
> +    _name = 'cmis.backend'
> +    _description = 'CMIS Backend'
> +    _inherit = 'connector.backend'
> +
> +    _backend_type = 'cmis'
> +
> +    def _select_versions(self, cr, uid, context=None):
> +        return [('1.0', '1.0')]
> +
> +    # Test connection with GED
> +    def _auth(self, cr, uid, context=None):
> +        if context is None:
> +            context = {}
> +        # Get the url, user and password for GED
> +        ids = self.search(cr, uid, [])
> +        res = self.read(cr, uid, ids,
> +                        ['location',
> +                         'username',
> +                         'password'], context=context)[0]
> +        url = res['location']
> +        user_name = res['username']
> +        user_password = res['password']
> +        client = CmisClient(url, user_name, user_password)
> +
> +        try:
> +            return client.defaultRepository
> +        except cmislib.exceptions.ObjectNotFoundException:
> +            raise orm.except_orm(_('Cmis connection Error!'),
> +                                 _("Check your cmis account configuration."))
> +        except cmislib.exceptions.PermissionDeniedException:
> +            raise orm.except_orm(_('Cmis connection Error!'),
> +                                 _("Check your cmis account configuration."))
> +        except urllib2.URLError:
> +            raise orm.except_orm(_('Cmis connection Error!'),
> +                                 _("SERVER is down."))
> +
> +    # Function to check if we have access right to write from the path

This comment is better suited to be a docstring. This isn't java. Put it as the first line of your function in triple quotes (""")
There a few others which would benefit from this.

> +    def check_directory_of_write(self, cr, uid, ids, context=None):
> +        if context is None:
> +            context = {}
> +        cmis_backend_obj = self.pool.get('cmis.backend')
> +        datas_fname = 'testdoc'
> +        # login with the cmis account
> +        repo = self._auth(cr, uid, context=context)
> +        cmis_backend_rec = cmis_backend_obj.read(
> +            cr, uid, ids, ['initial_directory_write'],
> +            context=context)[0]
> +        folder_path_write = cmis_backend_rec['initial_directory_write']
> +        # Testing the path
> +        rs = repo.query("SELECT cmis:path FROM  cmis:folder")
> +        bool_path_write = self.check_existing_path(rs, folder_path_write)
> +        # Check if we can create a doc from OE to EDM
> +        # Document properties
> +        if bool_path_write:
> +            sub = repo.getObjectByPath(folder_path_write)
> +            try:
> +                sub.createDocumentFromString(
> +                    datas_fname,
> +                    contentString='hello, world',
> +                    contentType='text/plain')
> +            except cmislib.exceptions.UpdateConflictException:
> +                raise orm.except_orm(
> +                    _('Cmis  Error!'),
> +                    _("The test file is already existed in DMS. "
> +                      "Please remove it and try again."))
> +            except cmislib.exceptions.RuntimeException:
> +                raise orm.except_orm(
> +                    _('Cmis access right Error!'),
> +                    ("Please check your access right."))
> +        self.get_error_for_path(bool_path_write, folder_path_write)
> +
> +    # Function to check if we have access right to read from the path
> +    def check_directory_of_read(self, cr, uid, ids, context=None):
> +        ir_attach_obj = self.pool.get('ir.attachment')
> +        if context is None:
> +            context = {}
> +        cmis_backend_obj = self.pool.get('cmis.backend')
> +        cmis_backend_rec = cmis_backend_obj.read(
> +            cr, uid, ids, ['initial_directory_read'],
> +            context=context)[0]
> +        # Login with the cmis account
> +        repo = self._auth(cr, uid, context=context)
> +        folder_path_read = cmis_backend_rec['initial_directory_read']
> +        # Testing the path
> +        rs = repo.query("SELECT cmis:path FROM  cmis:folder ")
> +        bool_path_read = self.check_existing_path(rs, folder_path_read)
> +        self.get_error_for_path(bool_path_read, folder_path_read)
> +
> +    # Function to check if the path is correct
> +    def check_existing_path(self, rs, folder_path):
> +        for one_rs in rs:
> +            # Print name of files
> +            props = one_rs.getProperties()
> +            if props['cmis:path'] != folder_path:
> +                bool = False
> +            else:
> +                bool = True
> +                break
> +        return bool
> +
> +    # Function to return following the boolean the right error message
> +    def get_error_for_path(self, bool, path):
> +        if bool:
> +            raise orm.except_orm(_('Cmis  Message'),
> +                                 _("Path is correct for : " + path))
> +        else:
> +            raise orm.except_orm(_('Cmis  Error!'),
> +                                 _("Error path for : " + path))
> +
> +    # Escape the name for characters not supported in filenames
> +    def sanitize_input(self, file_name):
> +        # for avoiding SQL Injection
> +        file_name = file_name.replace("'", "\\'")
> +        file_name = file_name.replace("%", "\%")
> +        file_name = file_name.replace("_", "\_")
> +        return file_name
> +
> +    def safe_query(self, query, file_name, repo):
> +        args = map(self.sanitize_input, file_name)
> +        return repo.query(query % ''.join(args))
> +
> +    _columns = {
> +        'version': fields.selection(
> +            _select_versions,
> +            string='Version',
> +            required=True),
> +        'location': fields.char('Location', size=128, required=True,
> +                                help="Location."),
> +        'username': fields.char('Username', size=64, required=True,
> +                                help="Username."),
> +        'password': fields.char('Password', size=64, required=True,
> +                                help="Password."),
> +        'initial_directory_read': fields.char(
> +            'Initial directory of read',
> +            size=128,
> +            required=True,
> +            help="Initial directory of read."),
> +        'initial_directory_write': fields.char(
> +            'Initial directory of write',
> +            size=128,
> +            required=True,
> +            help="Initial directory of write."),
> +        'browsing_ok': fields.boolean('Allow browsing this backend',
> +                                      help="Allow browsing this backend."),
> +        'storing_ok': fields.boolean('Allow storing in this backend',
> +                                     help="Allow storing in this backend."),
> +    }
> +    _defaults = {
> +        'initial_directory_read': '/',
> +        'initial_directory_write': '/',
> +    }
> +
> +# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added file 'cmis/cmis_model_view.xml'
> --- cmis/cmis_model_view.xml	1970-01-01 00:00:00 +0000
> +++ cmis/cmis_model_view.xml	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,74 @@
> +<?xml version="1.0" encoding="utf-8"?>
> +<openerp>
> +    <data>
> +
> +      <record id="view_cmis_backend_form" model="ir.ui.view">
> +        <field name="name">cmis.backend.form</field>
> +        <field name="model">cmis.backend</field>
> +        <field name="arch" type="xml">
> +          <form string="CMIS Backend" version="7.0">
> +            <sheet>
> +              <label for="name" class="oe_edit_only"/>
> +              <h1>
> +                <field name="name" class="oe_inline" />
> +              </h1>
> +              <group name="cmis" string="Cmis Configuration">
> +                <group colspan="4" col="4">
> +                  <field name="version" colspan="4"/>
> +                  <field name="location" placeholder="e.g. http://localhost:8081/alfresco/s/cmis";
> +                      colspan="4"/>
> +                  <field name="username" colspan="2"/>
> +                  <field name="password" colspan="2" password="True"/>
> +                </group>
> +              </group>
> +              <group name="directory_conf" string="Directory Configuration">
> +                <group >
> +                  <field name="browsing_ok"/>
> +                  <newline/>
> +                  <group attrs="{'invisible':[('browsing_ok','=',False)]}"
> +                         colspan="4" col="4">
> +                    <field name="initial_directory_read"/>
> +                    <button name="check_directory_of_read"
> +                          type="object"
> +                          class="oe_highlight"
> +                          string="Test Directory of read"/>
> +                  </group>
> +                  <newline/>
> +                  <field name="storing_ok"/>
> +                  <newline/>
> +                  <group attrs="{'invisible':[('storing_ok','=',False)]}"
> +                         colspan="4" col="4">
> +                    <field name="initial_directory_write"/>
> +                    <button name="check_directory_of_write"
> +                          type="object"
> +                          class="oe_highlight"
> +                          string="Test Directory of write"/>
> +                   </group>
> +                </group>
> +              </group>
> +            </sheet>
> +          </form>
> +        </field>
> +      </record>
> +
> +      <record id="view_cmis_backend_tree" model="ir.ui.view">
> +          <field name="name">cmis.backend.tree</field>
> +          <field name="model">cmis.backend</field>
> +          <field name="arch" type="xml">
> +            <tree string="CMIS Backend" version="7.0">
> +              <field name="name"/>
> +              <field name="username"/>
> +              <field name="location"/>
> +            </tree>
> +          </field>
> +      </record>
> +
> +      <record id="action_cmis_backend" model="ir.actions.act_window">
> +        <field name="name">CMIS Backends</field>
> +        <field name="res_model">cmis.backend</field>
> +        <field name="view_type">form</field>
> +        <field name="view_mode">tree,form</field>
> +        <field name="view_id" ref="view_cmis_backend_tree"/>
> +      </record>
> +    </data>
> +</openerp>
> 
> === added file 'cmis/connector.py'
> --- cmis/connector.py	1970-01-01 00:00:00 +0000
> +++ cmis/connector.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,38 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +from openerp.addons.connector.connector import (Environment,
> +                                                install_in_connector)
> +
> +install_in_connector()
> +
> +
> +def get_environment(session, model_name, backend_id):
> +    """ Create an environment to work with.  """
> +    backend_record = session.browse('cmis.backend', backend_id)
> +    env = Environment(backend_record, session, model_name)
> +    lang = backend_record.default_lang_id
> +    lang_code = lang.code if lang else 'en_US'
> +    env.set_lang(code=lang_code)
> +    return env
> +
> +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added directory 'cmis/security'
> === added file 'cmis/security/ir.model.access.csv'
> --- cmis/security/ir.model.access.csv	1970-01-01 00:00:00 +0000
> +++ cmis/security/ir.model.access.csv	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,2 @@
> +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
> +access_cmis_backend_user,access_cmis_backend_user,model_cmis_backend,base.group_user,1,0,0,0
> 
> === added directory 'cmis/tests'
> === added file 'cmis/tests/__init__.py'
> --- cmis/tests/__init__.py	1970-01-01 00:00:00 +0000
> +++ cmis/tests/__init__.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,29 @@
> +# -*- encoding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2013-2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +##############################################################################
> +
> +from . import (
> +    test_model,
> +)
> +
> +checks = [
> +    test_model,
> +]
> 
> === added file 'cmis/tests/test_model.py'
> --- cmis/tests/test_model.py	1970-01-01 00:00:00 +0000
> +++ cmis/tests/test_model.py	2014-06-12 19:47:23 +0000
> @@ -0,0 +1,53 @@
> +# -*- encoding: utf-8 -*-
> +###############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
> +#    (<http://www.savoirfairelinux.com>).
> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU Affero General Public License as
> +#    published by the Free Software Foundation, either version 3 of the
> +#    License, or (at your option) any later version.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU Affero General Public License for more details.
> +#
> +#    You should have received a copy of the GNU Affero General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +###############################################################################
> +
> +from openerp.tests.common import TransactionCase
> +
> +
> +class test_model(TransactionCase):
> +
> +    def setUp(self):
> +        super(test_model, self).setUp()
> +        # Clean up registries
> +        self.registry('ir.model').clear_caches()
> +        self.registry('ir.model.data').clear_caches()
> +        self.user_model = self.registry("res.users")
> +
> +        # Get registries
> +        self.model = self.registry("cmis.backend")
> +        # Get context
> +        self.context = self.user_model.context_get(self.cr, self.uid)
> +
> +        self.vals = {
> +            'name': "Test cmis",
> +            'version': '1.0',
> +            'location': "http://localhost:8081/alfresco/s/cmis";,
> +            'username': 'admin',
> +            'password': 'admin',
> +            'initial_directory_read': '/',
> +            'initial_directory_write': '/',
> +        }
> +
> +    def test_create_model(self):
> +        model_id = self.model.create(
> +            self.cr, self.uid, self.vals, context=self.context)
> +        self.assertTrue(model_id)
> 


-- 
https://code.launchpad.net/~savoirfairelinux-openerp/knowledge-addons/cmis/+merge/212258
Your team Savoir-faire Linux' OpenERP is subscribed to branch lp:~savoirfairelinux-openerp/knowledge-addons/cmis.


References