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
15
16
VER_REGEXP = re.compile(
16
17
"^(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$")
150
151
'The name of the module must be unique!'),
152
153
self._order.insert(0, ('name', 'ASC'))
153
self._rpc_allowed += [
155
'button_install_cancel',
157
'button_uninstall_cancel',
159
'button_upgrade_cancel',
160
'button_update_translations',
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
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)
213
def on_write(self, cursor, user, ids, context=None):
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:
219
def get_parents(name, 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)
230
dependencies = get_parents(module.name, graph)
231
def get_childs(name, graph):
232
childs = [x.name for x in graph[name].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),
241
return list({}.fromkeys(res))
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:
355
if name[-4:] == '.zip':
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)
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,
455
485
state = fields.Function('get_state', type='selection',
457
487
('uninstalled','Not Installed'),
486
516
ModuleDependency()
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()
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__
516
548
ModuleConfigWizardFirst()
585
617
ModuleConfigWizard()
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)
592
626
ModuleInstallUpgradeInit()
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__
598
634
ModuleInstallUpgradeStart()
617
653
module_obj = self.pool.get('ir.module.module')
618
654
lang_obj = self.pool.get('ir.lang')
619
655
dbname = cursor.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']),
625
lang_ids = lang_obj.search(cursor, user, [
626
('translatable', '=', True),
628
lang = [x.code for x in lang_obj.browse(cursor, user, lang_ids,
659
module_ids = module_obj.search(cursor, user, [
660
('state', 'in', ['to upgrade', 'to remove', 'to install']),
662
lang_ids = lang_obj.search(cursor, user, [
663
('translatable', '=', True),
665
lang = [x.code for x in lang_obj.browse(cursor, user, lang_ids,
633
restart_pool(dbname, update_module=True, lang=lang)
672
pool.init(update=True, lang=lang)
673
new_wizard = pool.get('ir.module.module.install_upgrade',
675
new_wizard._lock.acquire()
676
new_wizard._datas[data['_wiz_id']] = self._datas[data['_wiz_id']]
677
new_wizard._lock.release()