~ubuntu-branches/ubuntu/natty/tryton-server/natty-security

« back to all changes in this revision

Viewing changes to trytond/ir/module/module.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann, Daniel Baumann, Mathias Behrle
  • Date: 2009-04-21 19:27:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090421192700-hmiosex03jt5qf01
Tags: 1.2.0-1
[ Daniel Baumann ]
* Merging upstream version 1.2.0.
* Tidy rules files.
* Updating version information in manpage.
* Updating copyright file for new upstream release.
* Including TODO file in docs.

[ Mathias Behrle ]
* Updating application description.

[ Daniel Baumann ]
* Correcting wrapping of control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import zipfile
7
7
import urllib
8
8
import zipimport
9
 
from trytond.osv import fields, OSV
 
9
from trytond.model import ModelView, ModelSQL, fields
10
10
import trytond.tools as tools
11
11
from trytond.modules import MODULES_PATH, create_graph, get_module_list
12
 
from trytond.wizard import Wizard, WizardOSV
13
 
from trytond.pooler import get_db, restart_pool
 
12
from trytond.wizard import Wizard
 
13
from trytond.backend import Database
 
14
from trytond.pool import Pool
14
15
 
15
16
VER_REGEXP = re.compile(
16
17
    "^(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$")
123
124
    return revision1 - revision2
124
125
 
125
126
 
126
 
class Module(OSV):
 
127
class Module(ModelSQL, ModelView):
127
128
    "Module"
128
129
    _name = "ir.module.module"
129
130
    _description = __doc__
150
151
                'The name of the module must be unique!'),
151
152
        ]
152
153
        self._order.insert(0, ('name', 'ASC'))
153
 
        self._rpc_allowed += [
154
 
            'button_install',
155
 
            'button_install_cancel',
156
 
            'button_uninstall',
157
 
            'button_uninstall_cancel',
158
 
            'button_upgrade',
159
 
            'button_upgrade_cancel',
160
 
            'button_update_translations',
161
 
        ]
 
154
        self._rpc.update({
 
155
            'button_install': True,
 
156
            'button_install_cancel': True,
 
157
            'button_uninstall': True,
 
158
            'button_uninstall_cancel': True,
 
159
            'button_upgrade': True,
 
160
            'button_upgrade_cancel': True,
 
161
            'button_update_translations': True,
 
162
            'on_write': False,
 
163
        })
162
164
        self._error_messages.update({
163
165
            'delete_state': 'You can not remove a module that is installed ' \
164
166
                    'or will be installed',
208
210
                self.raise_user_error(cursor, 'delete_state', context=context)
209
211
        return super(Module, self).delete(cursor, user, ids, context=context)
210
212
 
 
213
    def on_write(self, cursor, user, ids, context=None):
 
214
        res = []
 
215
        graph, packages, later = create_graph(get_module_list())
 
216
        for module in self.browse(cursor, user, ids, context=context):
 
217
            if module.name not in graph:
 
218
                continue
 
219
            def get_parents(name, graph):
 
220
                parents = []
 
221
                for node in graph:
 
222
                    if graph[name] in node.childs:
 
223
                        if node.name not in parents:
 
224
                            parents.append(node.name)
 
225
                for parent in parents:
 
226
                    for parent2 in get_parents(parent, graph):
 
227
                        if parent2 not in parents:
 
228
                            parents.append(parent2)
 
229
                return parents
 
230
            dependencies = get_parents(module.name, graph)
 
231
            def get_childs(name, graph):
 
232
                childs = [x.name for x in graph[name].childs]
 
233
                childs2 = []
 
234
                for child in childs:
 
235
                    childs2 += get_childs(child, graph)
 
236
                return childs + childs2
 
237
            dependencies += get_childs(module.name, graph)
 
238
            res += self.search(cursor, user, [
 
239
                ('name', 'in', dependencies),
 
240
                ], context=context)
 
241
        return list({}.fromkeys(res))
 
242
 
211
243
    def state_install(self, cursor, user, ids, context=None):
212
244
        graph, packages, later = create_graph(get_module_list())
213
245
        for module in self.browse(cursor, user, ids, context=context):
352
384
        # iterate through installed modules and mark them as being so
353
385
        for name in module_names:
354
386
            mod_name = name
355
 
            if name[-4:] == '.zip':
356
 
                mod_name = name[:-4]
357
387
            if mod_name in name2module.keys():
358
388
                mod = name2module[mod_name]['en_US']
359
389
                tryton = Module.get_module_info(mod_name)
445
475
Module()
446
476
 
447
477
 
448
 
class ModuleDependency(OSV):
 
478
class ModuleDependency(ModelSQL, ModelView):
449
479
    "Module dependency"
450
480
    _name = "ir.module.module.dependency"
451
481
    _description = __doc__
452
482
    name = fields.Char('Name')
453
483
    module = fields.Many2One('ir.module.module', 'Module', select=1,
454
 
       ondelete='cascade')
 
484
       ondelete='CASCADE')
455
485
    state = fields.Function('get_state', type='selection',
456
486
       selection=[
457
487
       ('uninstalled','Not Installed'),
486
516
ModuleDependency()
487
517
 
488
518
 
489
 
class ModuleConfigWizardItem(OSV):
 
519
class ModuleConfigWizardItem(ModelSQL, ModelView):
490
520
    "Config wizard to run after installing module"
491
521
    _name = 'ir.module.module.config_wizard.item'
492
522
    _description = __doc__
510
540
ModuleConfigWizardItem()
511
541
 
512
542
 
513
 
class ModuleConfigWizardFirst(WizardOSV):
 
543
class ModuleConfigWizardFirst(ModelView):
 
544
    'Module Config Wizard First'
514
545
    _name = 'ir.module.module.config_wizard.first'
 
546
    _description = __doc__
515
547
 
516
548
ModuleConfigWizardFirst()
517
549
 
585
617
ModuleConfigWizard()
586
618
 
587
619
 
588
 
class ModuleInstallUpgradeInit(WizardOSV):
 
620
class ModuleInstallUpgradeInit(ModelView):
 
621
    'Module Install Upgrade Init'
589
622
    _name = 'ir.module.module.install_upgrade.init'
 
623
    _description = __doc__
590
624
    module_info = fields.Text('Modules to update', readonly=True)
591
625
 
592
626
ModuleInstallUpgradeInit()
593
627
 
594
628
 
595
 
class ModuleInstallUpgradeStart(WizardOSV):
 
629
class ModuleInstallUpgradeStart(ModelView):
 
630
    'Module Install Upgrade Start'
596
631
    _name = 'ir.module.module.install_upgrade.start'
 
632
    _description = __doc__
597
633
 
598
634
ModuleInstallUpgradeStart()
599
635
 
617
653
        module_obj = self.pool.get('ir.module.module')
618
654
        lang_obj = self.pool.get('ir.lang')
619
655
        dbname = cursor.dbname
620
 
        db = get_db(dbname)
 
656
        db = Database(dbname).connect()
621
657
        cursor = db.cursor()
622
 
        module_ids = module_obj.search(cursor, user, [
623
 
            ('state', 'in', ['to upgrade', 'to remove', 'to install']),
624
 
            ], context=context)
625
 
        lang_ids = lang_obj.search(cursor, user, [
626
 
            ('translatable', '=', True),
627
 
            ], context=context)
628
 
        lang = [x.code for x in lang_obj.browse(cursor, user, lang_ids,
629
 
            context=context)]
630
 
        cursor.commit()
631
 
        cursor.close()
 
658
        try:
 
659
            module_ids = module_obj.search(cursor, user, [
 
660
                ('state', 'in', ['to upgrade', 'to remove', 'to install']),
 
661
                ], context=context)
 
662
            lang_ids = lang_obj.search(cursor, user, [
 
663
                ('translatable', '=', True),
 
664
                ], context=context)
 
665
            lang = [x.code for x in lang_obj.browse(cursor, user, lang_ids,
 
666
                context=context)]
 
667
        finally:
 
668
            cursor.commit()
 
669
            cursor.close()
632
670
        if module_ids:
633
 
            restart_pool(dbname, update_module=True, lang=lang)
 
671
            pool = Pool(dbname)
 
672
            pool.init(update=True, lang=lang)
 
673
            new_wizard = pool.get('ir.module.module.install_upgrade',
 
674
                    type='wizard')
 
675
            new_wizard._lock.acquire()
 
676
            new_wizard._datas[data['_wiz_id']] = self._datas[data['_wiz_id']]
 
677
            new_wizard._lock.release()
634
678
        return {}
635
679
 
636
680
    states = {