Ejemplo n.º 1
0
 def download(self, cr, uid, ids, download=True, context=None):
     res = []
     default_version = modules.adapt_version('1.0')
     for mod in self.browse(cr, uid, ids, context=context):
         if not mod.url:
             continue
         match = re.search('-([a-zA-Z0-9\._-]+)(\.zip)', mod.url, re.I)
         version = default_version
         if match:
             version = match.group(1)
         if parse_version(mod.installed_version) >= parse_version(version):
             continue
         res.append(mod.url)
         if not download:
             continue
         zip_content = urllib.urlopen(mod.url).read()
         fname = modules.get_module_path(str(mod.name) + '.zip', downloaded=True)
         try:
             with open(fname, 'wb') as fp:
                 fp.write(zip_content)
         except Exception:
             _logger.exception('Error when trying to create module '
                               'file %s', fname)
             raise orm.except_orm(_('Error'), _('Can not create the module file:\n %s') % (fname,))
         terp = self.get_module_info(mod.name)
         self.write(cr, uid, mod.id, self.get_values_from_terp(terp))
         cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (mod.id,))
         self._update_dependencies(cr, uid, mod, terp.get('depends', []))
         self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized'))
         # Import module
         zimp = zipimport.zipimporter(fname)
         zimp.load_module(mod.name)
     return res
Ejemplo n.º 2
0
 def download(self, cr, uid, ids, download=True, context=None):
     res = []
     default_version = modules.adapt_version('1.0')
     for mod in self.browse(cr, uid, ids, context=context):
         if not mod.url:
             continue
         match = re.search('-([a-zA-Z0-9\._-]+)(\.zip)', mod.url, re.I)
         version = default_version
         if match:
             version = match.group(1)
         if parse_version(mod.installed_version) >= parse_version(version):
             continue
         res.append(mod.url)
         if not download:
             continue
         zip_content = urllib.urlopen(mod.url).read()
         fname = modules.get_module_path(str(mod.name) + '.zip', downloaded=True)
         try:
             with open(fname, 'wb') as fp:
                 fp.write(zip_content)
         except Exception:
             _logger.exception('Error when trying to create module '
                               'file %s', fname)
             raise orm.except_orm(_('Error'), _('Can not create the module file:\n %s') % (fname,))
         terp = self.get_module_info(mod.name)
         self.write(cr, uid, mod.id, self.get_values_from_terp(terp))
         cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (mod.id,))
         self._update_dependencies(cr, uid, mod, terp.get('depends', []))
         self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized'))
         # Import module
         zimp = zipimport.zipimporter(fname)
         zimp.load_module(mod.name)
     return res
Ejemplo n.º 3
0
    def update_list(self, cr, uid, context=None):
        res = [0, 0]  # [update, add]

        default_version = modules.adapt_version('1.0')
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])

        # iterate through detected modules and update/create them in db
        for mod_name in modules.get_modules():
            mod = known_mods_names.get(mod_name)
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if mod:
                updated_values = {}
                for key in values:
                    old = getattr(mod, key)
                    updated = isinstance(values[key],
                                         basestring) and tools.ustr(
                                             values[key]) or values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                if terp.get('installable',
                            True) and mod.state == 'uninstallable':
                    updated_values['state'] = 'uninstalled'
                if parse_version(terp.get(
                        'version', default_version)) > parse_version(
                            mod.latest_version or default_version):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = modules.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get('installable', True):
                    continue
                id = self.create(
                    cr, uid, dict(name=mod_name, state='uninstalled',
                                  **values))
                mod = self.browse(cr, uid, id)
                res[1] += 1

            self._update_dependencies(cr, uid, mod, terp.get('depends', []))
            self._update_category(cr, uid, mod,
                                  terp.get('category', 'Uncategorized'))

        # Trigger load_addons if new module have been discovered it exists on
        # wsgi handlers, so they can react accordingly
        if tuple(res) != (0, 0):
            for handler in openerp.service.wsgi_server.module_handlers:
                if hasattr(handler, 'load_addons'):
                    handler.load_addons()

        return res
Ejemplo n.º 4
0
 def _get_latest_version(self,
                         cr,
                         uid,
                         ids,
                         field_name=None,
                         arg=None,
                         context=None):
     default_version = modules.adapt_version('1.0')
     res = dict.fromkeys(ids, default_version)
     for m in self.browse(cr, uid, ids):
         res[m.id] = self.get_module_info(m.name).get(
             'version', default_version)
     return res
Ejemplo n.º 5
0
    def update_list(self, cr, uid, context=None):
        res = [0, 0]  # [update, add]

        default_version = modules.adapt_version("1.0")
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])

        # iterate through detected modules and update/create them in db
        for mod_name in modules.get_modules():
            mod = known_mods_names.get(mod_name)
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if mod:
                updated_values = {}
                for key in values:
                    old = getattr(mod, key)
                    updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                if terp.get("installable", True) and mod.state == "uninstallable":
                    updated_values["state"] = "uninstalled"
                if parse_version(terp.get("version", default_version)) > parse_version(
                    mod.latest_version or default_version
                ):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = modules.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get("installable", True):
                    continue
                id = self.create(cr, uid, dict(name=mod_name, state="uninstalled", **values))
                mod = self.browse(cr, uid, id)
                res[1] += 1

            self._update_dependencies(cr, uid, mod, terp.get("depends", []))
            self._update_category(cr, uid, mod, terp.get("category", "Uncategorized"))

        # Trigger load_addons if new module have been discovered it exists on
        # wsgi handlers, so they can react accordingly
        if tuple(res) != (0, 0):
            for handler in openerp.service.wsgi_server.module_handlers:
                if hasattr(handler, "load_addons"):
                    handler.load_addons()

        return res
Ejemplo n.º 6
0
    def update_list(self, cr, uid, context=None):
        res = [0, 0]  # [update, add]

        default_version = modules.adapt_version('1.0')
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])

        # iterate through detected modules and update/create them in db
        for mod_name in modules.get_modules():
            mod = known_mods_names.get(mod_name)
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if mod:
                updated_values = {}
                for key in values:
                    old = getattr(mod, key)
                    updated = isinstance(values[key],
                                         basestring) and tools.ustr(
                                             values[key]) or values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                if terp.get('installable',
                            True) and mod.state == 'uninstallable':
                    updated_values['state'] = 'uninstalled'
                if parse_version(terp.get(
                        'version', default_version)) > parse_version(
                            mod.latest_version or default_version):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = modules.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get('installable', True):
                    continue
                id = self.create(
                    cr, uid, dict(name=mod_name, state='uninstalled',
                                  **values))
                mod = self.browse(cr, uid, id)
                res[1] += 1

            self._update_dependencies(cr, uid, mod, terp.get('depends', []))
            self._update_category(cr, uid, mod,
                                  terp.get('category', 'Uncategorized'))

        return res
Ejemplo n.º 7
0
    def update_list(self, cr, uid, context=None):
        res = [0, 0]  # [update, add]

        default_version = modules.adapt_version("1.0")
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])

        # iterate through detected modules and update/create them in db
        for mod_name in modules.get_modules():
            mod = known_mods_names.get(mod_name)
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if mod:
                updated_values = {}
                for key in values:
                    old = getattr(mod, key)
                    updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                if terp.get("installable", True) and mod.state == "uninstallable":
                    updated_values["state"] = "uninstalled"
                if parse_version(terp.get("version", default_version)) > parse_version(
                    mod.latest_version or default_version
                ):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = modules.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get("installable", True):
                    continue
                id = self.create(cr, uid, dict(name=mod_name, state="uninstalled", **values))
                mod = self.browse(cr, uid, id)
                res[1] += 1

            self._update_dependencies(cr, uid, mod, terp.get("depends", []))
            self._update_category(cr, uid, mod, terp.get("category", "Uncategorized"))

        return res
Ejemplo n.º 8
0
 def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context=None):
     default_version = modules.adapt_version('1.0')
     res = dict.fromkeys(ids, default_version)
     for m in self.browse(cr, uid, ids):
         res[m.id] = self.get_module_info(m.name).get('version', default_version)
     return res
    def scan_repository(self):
        self.ensure_one()
        _logger.info("Scaning repository %s" % (self.name))
        res = [0, 0]  # [update, add]
        errors = []

        default_version = modules.adapt_version('1.0')

        # iterate through detected modules and update/create them in db
        for module_path in self.get_modules_paths():
            # sacamos la ultima parte del path como nombre del modulo
            mod_name = os.path.basename(module_path)
            # search for modules of same name an odoo version
            mod = self.env['adhoc.module.module'].search(
                [('name', '=', mod_name),
                 ('repository_id.branch', '=', self.branch)],
                limit=1)
            module_info = self.get_module_info(module_path)
            values = self.get_module_vals(module_info)

            if mod:
                _logger.info('Updating data for module %s' % mod_name)
                if mod.repository_id.id != self.id:
                    msg = ('Module %s already exist in repository %s' %
                           (mod_name, mod.repository_id.name))
                    errors.append(msg)
                    _logger.warning(msg)
                    continue
                updated_values = {}
                # if mod alread y exist, we pop new_sequence value because
                # we dont want to update it
                values.pop('sequence')
                # values.pop('new_sequence')
                for key in values:
                    old = getattr(mod, key)
                    updated = isinstance(values[key],
                                         basestring) and tools.ustr(
                                             values[key]) or values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                # we do not use state
                # if module_info.get(
                #         'installable', True) and mod.state == 'uninstallable':
                #     updated_values['state'] = 'uninstalled'
                if parse_version(module_info.get(
                        'version', default_version)) > parse_version(
                            mod.latest_version or default_version):
                    res[0] += 1
                if updated_values:
                    mod.write(updated_values)
            else:
                _logger.info('Creating new module %s' % mod_name)
                # if not installable, we dont upload
                if not module_info or not module_info.get('installable', True):
                    continue
                mod = mod.create(
                    dict(name=mod_name, repository_id=self.id, **values))
                res[1] += 1
            mod._update_dependencies(module_info.get('depends', []))
        self.message_post(body="%s. Errors: %s" % (res, errors), subject=None)
        return res