You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.5 KiB

11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import pooler
  22. from openerp.osv import orm, fields
  23. from openerp.modules.module import get_module_path
  24. from openerp.tools.translate import _
  25. class CleanupPurgeLineModule(orm.TransientModel):
  26. _inherit = 'cleanup.purge.line'
  27. _name = 'cleanup.purge.line.module'
  28. _columns = {
  29. 'wizard_id': fields.many2one(
  30. 'cleanup.purge.wizard.module', 'Purge Wizard', readonly=True),
  31. }
  32. def purge(self, cr, uid, ids, context=None):
  33. """
  34. Uninstall modules upon manual confirmation, then reload
  35. the database.
  36. """
  37. module_pool = self.pool['ir.module.module']
  38. lines = self.browse(cr, uid, ids, context=context)
  39. module_names = [line.name for line in lines if not line.purged]
  40. module_ids = module_pool.search(
  41. cr, uid, [('name', 'in', module_names)], context=context)
  42. if not module_ids:
  43. return True
  44. self.logger.info('Purging modules %s', ', '.join(module_names))
  45. module_pool.write(
  46. cr, uid, module_ids, {'state': 'to remove'}, context=context)
  47. cr.commit()
  48. _db, _pool = pooler.restart_pool(cr.dbname, update_module=True)
  49. module_pool.unlink(cr, uid, module_ids, context=context)
  50. return self.write(cr, uid, ids, {'purged': True}, context=context)
  51. class CleanupPurgeWizardModule(orm.TransientModel):
  52. _inherit = 'cleanup.purge.wizard'
  53. _name = 'cleanup.purge.wizard.module'
  54. def default_get(self, cr, uid, fields, context=None):
  55. res = super(CleanupPurgeWizardModule, self).default_get(
  56. cr, uid, fields, context=context)
  57. if 'name' in fields:
  58. res['name'] = _('Purge modules')
  59. return res
  60. def find(self, cr, uid, context=None):
  61. module_pool = self.pool['ir.module.module']
  62. module_ids = module_pool.search(cr, uid, [], context=context)
  63. res = []
  64. for module in module_pool.browse(cr, uid, module_ids, context=context):
  65. if get_module_path(module.name):
  66. continue
  67. if module.state == 'uninstalled':
  68. module_pool.unlink(cr, uid, module.id, context=context)
  69. continue
  70. res.append((0, 0, {'name': module.name}))
  71. if not res:
  72. raise orm.except_orm(
  73. _('Nothing to do'),
  74. _('No modules found to purge'))
  75. return res
  76. _columns = {
  77. 'purge_line_ids': fields.one2many(
  78. 'cleanup.purge.line.module',
  79. 'wizard_id', 'Modules to purge'),
  80. }