Exemplo n.º 1
0
    def update_list(self, cr, uid, context={}):
        res = [0, 0] # [update, add]

        # iterate through installed modules and mark them as being so
        for mod_name in addons.get_modules():
            ids = self.search(cr, uid, [('name','=',mod_name)])
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if ids:
                id = ids[0]
                mod = self.browse(cr, uid, id)
                if terp.get('installable', True) and mod.state == 'uninstallable':
                    self.write(cr, uid, id, {'state': 'uninstalled'})
                if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''):
                    self.write(cr, uid, id, {'url': ''})
                    res[0] += 1
                self.write(cr, uid, id, values)
                cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (id,))
            else:
                mod_path = addons.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get('installable', True):
                    continue

                ids = self.search(cr, uid, [('name','=',mod_name)])
                id = self.create(cr, uid, dict(name=mod_name, state='uninstalled', **values))
                res[1] += 1
            self._update_dependencies(cr, uid, id, terp.get('depends', []))
            self._update_web_dependencies(cr, uid, id, terp.get('web_depends', []))
            self._update_category(cr, uid, id, terp.get('category', 'Uncategorized'))

        return res
Exemplo n.º 2
0
    def update_list(self, cr, uid, context={}):
        res = [0, 0]  # [update, add]

        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 addons.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 not old == updated:
                        updated_values[key] = values[key]
                if terp.get('installable',
                            True) and mod.state == 'uninstallable':
                    updated_values['state'] = 'uninstalled'
                if parse_version(terp.get('version', '')) > parse_version(
                        mod.latest_version or ''):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = addons.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
Exemplo n.º 3
0
    def update_list(self, cr, uid, context={}):
        res = [0, 0]  # [update, add]

        # iterate through installed modules and mark them as being so
        for mod_name in addons.get_modules():
            ids = self.search(cr, uid, [('name', '=', mod_name)])
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if ids:
                id = ids[0]
                mod = self.browse(cr, uid, id)
                if terp.get('installable',
                            True) and mod.state == 'uninstallable':
                    self.write(cr, uid, id, {'state': 'uninstalled'})
                if parse_version(terp.get('version', '')) > parse_version(
                        mod.latest_version or ''):
                    self.write(cr, uid, id, {'url': ''})
                    res[0] += 1
                self.write(cr, uid, id, values)
                cr.execute(
                    'DELETE FROM ir_module_module_dependency WHERE module_id = %s',
                    (id, ))
            else:
                mod_path = addons.get_module_path(mod_name)
                if not mod_path:
                    continue
                if not terp or not terp.get('installable', True):
                    continue

                ids = self.search(cr, uid, [('name', '=', mod_name)])
                id = self.create(
                    cr, uid, dict(name=mod_name, state='uninstalled',
                                  **values))
                res[1] += 1
            self._update_dependencies(cr, uid, id, terp.get('depends', []))
            self._update_web_dependencies(cr, uid, id,
                                          terp.get('web_depends', []))
            self._update_category(cr, uid, id,
                                  terp.get('category', 'Uncategorized'))

        return res
Exemplo n.º 4
0
    def update_list(self, cr, uid, context={}):
        res = [0, 0] # [update, add]

        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 addons.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 not old == updated:
                        updated_values[key] = values[key]
                if terp.get('installable', True) and mod.state == 'uninstallable':
                    updated_values['state'] = 'uninstalled'
                if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''):
                    res[0] += 1
                if updated_values:
                    self.write(cr, uid, mod.id, updated_values)
            else:
                mod_path = addons.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
Exemplo n.º 5
0
    def update_list(self, cr, uid, context=None):
        if context is None:
            context = {}
        res = [0, 0] # [update, add]

        all_mod_ids = self.search(cr, uid, [], context=context)
        known_module_names = addons.get_modules()
        
        def ifustr(var):
            """ Auto-convert all strings to unicode"""
            if isinstance(var, basestring):
                return tools.ustr(var)
            else:
                return var
        
        for old_mod in self.browse(cr, uid, all_mod_ids, context=context):
            if old_mod.name in known_module_names:
                known_module_names.remove(old_mod.name)

                terp = self.get_module_info(old_mod.name)
                if not terp or not terp.get('installable', True):
                    if old_mod.state != 'uninstallable':
                        self.write(cr, uid, old_mod.id, {'state': 'uninstallable'})
                    continue
                
                values = self.get_values_from_terp(terp)
                new_values = { }
                
                for key in values:
                    if getattr(old_mod, key) != ifustr(values[key]):
                        new_values[key] = ifustr(values[key])
                
                if new_values:
                    self.write(cr, uid, old_mod.id, new_values)
                
                old_depends = [ x.name for x in old_mod.dependencies_id ]
                old_depends.sort()
                new_depends = terp.get('depends', [])
                new_depends.sort()
                if old_depends != new_depends:
                    cr.execute('DELETE FROM ir_module_module_dependency '
                                'WHERE module_id = %s', (old_mod.id,), debug=self._debug)
                    self._update_dependencies(cr, uid, old_mod.id, new_depends)
        
                self._update_category(cr, uid, old_mod.id, terp.get('category', 'Uncategorized'),
                                old_cat=old_mod.category_id)

            else:
                # This module is no longer in the file tree
                if old_mod.state != 'uninstallable':
                    self.write(cr, uid, old_mod.id, {'state': 'uninstallable'})
                # TODO: clear dependencies or even module data, RFC

        # Now, we are left with names of modules that are not in the db,
        # the new modules:

        for mod_name in known_module_names:
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            mod_path = addons.get_module_path(mod_name)
            # Addons shouldn't ever tell us names of non-existing modules
            assert mod_path, "No module path for %s" % mod_name
            if not terp or not terp.get('installable', True):
                continue

            values['state'] = 'uninstalled'
            values['name'] = mod_name
            id = self.create(cr, uid, values, context=context)
            res[1] += 1
            self._update_dependencies(cr, uid, id, terp.get('depends', []))
            self._update_category(cr, uid, id, terp.get('category', 'Uncategorized'), old_cat=False)

        return res
Exemplo n.º 6
0
    def update_list(self, cr, uid, context={}):
        robj = self.pool.get('ir.module.repository')
        res = [0, 0] # [update, add]

        # iterate through installed modules and mark them as being so
        for mod_name in addons.get_modules():
            ids = self.search(cr, uid, [('name','=',mod_name)])
            if ids:
                id = ids[0]
                mod = self.browse(cr, uid, id)
                terp = self.get_module_info(mod_name)
                if terp.get('installable', True) and mod.state == 'uninstallable':
                    self.write(cr, uid, id, {'state': 'uninstalled'})
                if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''):
                    self.write(cr, uid, id, { 'url': ''})
                    res[0] += 1
                self.write(cr, uid, id, {
                    'description': terp.get('description', ''),
                    'shortdesc': terp.get('name', ''),
                    'author': terp.get('author', 'Unknown'),
                    'website': terp.get('website', ''),
                    'license': terp.get('license', 'GPL-2'),
                    'certificate': terp.get('certificate') or None,
                    })
                cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (id,))
                self._update_dependencies(cr, uid, ids[0], terp.get('depends', []))
                self._update_category(cr, uid, ids[0], terp.get('category', 'Uncategorized'))
                continue
            mod_path = addons.get_module_path(mod_name)
            if mod_path:
                terp = self.get_module_info(mod_name)
                if not terp or not terp.get('installable', True):
                    continue

                id = self.create(cr, uid, {
                    'name': mod_name,
                    'state': 'uninstalled',
                    'description': terp.get('description', ''),
                    'shortdesc': terp.get('name', ''),
                    'author': terp.get('author', 'Unknown'),
                    'website': terp.get('website', ''),
                    'license': terp.get('license', 'GPL-2'),
                    'certificate': terp.get('certificate') or None,
                })
                res[1] += 1
                self._update_dependencies(cr, uid, id, terp.get('depends', []))
                self._update_category(cr, uid, id, terp.get('category', 'Uncategorized'))

        for repository in robj.browse(cr, uid, robj.search(cr, uid, [])):
            try:
                index_page = urllib.urlopen(repository.url).read()
            except IOError, e:
                if e.errno == 21:
                    raise orm.except_orm(_('Error'),
                            _("This url '%s' must provide an html file with links to zip modules") % (repository.url))
                else:
                    raise
            modules = re.findall(repository.filter, index_page, re.I+re.M)
            mod_sort = {}
            for m in modules:
                name, version, extension = m[0], m[1], m[-1]
                if not version or version == 'x': # 'x' version was a mistake
                    version = '0'
                if name in mod_sort:
                    if parse_version(version) <= parse_version(mod_sort[name][0]):
                        continue
                mod_sort[name] = [version, extension]
            for name in mod_sort.keys():
                version, extension = mod_sort[name]
                url = repository.url+'/'+name+'-'+version+extension
                ids = self.search(cr, uid, [('name','=',name)])
                if not ids:
                    self.create(cr, uid, {
                        'name': name,
                        'published_version': version,
                        'url': url,
                        'state': 'uninstalled',
                    })
                    res[1] += 1
                else:
                    id = ids[0]
                    installed_version = self.read(cr, uid, id, ['latest_version'])['latest_version']
                    if not installed_version or installed_version == 'x': # 'x' version was a mistake
                        installed_version = '0'
                    if parse_version(version) > parse_version(installed_version):
                        self.write(cr, uid, id, { 'url': url })
                        res[0] += 1
                    published_version = self.read(cr, uid, id, ['published_version'])['published_version']
                    if published_version == 'x' or not published_version:
                        published_version = '0'
                    if parse_version(version) > parse_version(published_version):
                        self.write(cr, uid, id, {'published_version': version})
Exemplo n.º 7
0
def init_db(cr):
    import addons
    f = addons.get_module_resource('base', 'base.sql')
    for line in file_open(f).read().split(';'):
        if (len(line)>0) and (not line.isspace()):
            cr.execute(line)
    cr.commit()

    for i in addons.get_modules():
        mod_path = addons.get_module_path(i)
        if not mod_path:
            continue

        info = addons.load_information_from_description_file(i)

        if not info:
            continue
        categs = info.get('category', 'Uncategorized').split('/')
        p_id = None
        while categs:
            if p_id is not None:
                cr.execute('select id \
                           from ir_module_category \
                           where name=%s and parent_id=%s', (categs[0], p_id))
            else:
                cr.execute('select id \
                           from ir_module_category \
                           where name=%s and parent_id is NULL', (categs[0],))
            c_id = cr.fetchone()
            if not c_id:
                cr.execute('select nextval(\'ir_module_category_id_seq\')')
                c_id = cr.fetchone()[0]
                cr.execute('insert into ir_module_category \
                        (id, name, parent_id) \
                        values (%s, %s, %s)', (c_id, categs[0], p_id))
            else:
                c_id = c_id[0]
            p_id = c_id
            categs = categs[1:]

        active = info.get('active', False)
        installable = info.get('installable', True)
        if installable:
            if active:
                state = 'to install'
            else:
                state = 'uninstalled'
        else:
            state = 'uninstallable'
        cr.execute('select nextval(\'ir_module_module_id_seq\')')
        id = cr.fetchone()[0]
        cr.execute('insert into ir_module_module \
                (id, author, website, name, shortdesc, description, \
                    category_id, state, certificate) \
                values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', (
            id, info.get('author', ''),
            info.get('website', ''), i, info.get('name', False),
            info.get('description', ''), p_id, state, info.get('certificate') or None))
        cr.execute('insert into ir_model_data \
            (name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', (
                'module_meta_information', 'ir.module.module', i, id, True))
        dependencies = info.get('depends', [])
        for d in dependencies:
            cr.execute('insert into ir_module_module_dependency \
                    (module_id,name) values (%s, %s)', (id, d))
        cr.commit()