def test_inotify(self): from Products.ERP5.Tool.InotifyTool import IN_CREATE, IN_MODIFY, IN_DELETE addERP5Tool(self.portal, 'portal_inotify', 'Inotify Tool') inotify_tool = self.portal.portal_inotify for inotify in inotify_tool.objectValues(): inotify._setEnabled(False) inotify_tool._p_changed = 1 self.commit() def checkCache(notify_list): self.assertEqual(notify_list, getattr(aq_base(inotify_tool), '_v_notify_list', None)) checkCache(None) tmp_dir = tempfile.mkdtemp() try: inotify_tool.process_timer(None, None) self.commit() checkCache([]) inotify = inotify_tool.newContent(inode_path='string:'+tmp_dir, sense_method_id='Inotify_test', node=inotify_tool.getCurrentNode()) inotify_id = inotify.getId() checkCache(None) inotify_tool.process_timer(None, None) self.commit() checkCache([]) event_list = [] inotify.__class__.Inotify_test = lambda self, events: \ event_list.extend(events) try: inotify.setEnabled(True) self.commit() checkCache(None) inotify_tool.process_timer(None, None) self.commit() checkCache([inotify_id]) self.assertEqual(event_list, []) p = os.path.join(tmp_dir, '1') with open(p, 'w') as f: inotify_tool.process_timer(None, None) self.commit() self.assertEqual(event_list, [{'path': p, 'mask': IN_CREATE}]) del event_list[:] f.write('foo') inotify_tool.process_timer(None, None) self.commit() self.assertEqual(event_list, [{'path': p, 'mask': IN_MODIFY}]) del event_list[:] p2 = os.path.join(tmp_dir, '2') os.rename(p, p2) inotify_tool.process_timer(None, None) self.commit() expected = [{'path': p, 'mask': IN_DELETE}, {'path': p2, 'mask': IN_CREATE}] expected.remove(event_list.pop()) self.assertEqual(event_list, expected) finally: del inotify.__class__.Inotify_test finally: shutil.rmtree(tmp_dir)
def WorkflowTool_bootstrap(self): """ Migrate portal_workflow from CMFCore to ERP5 Workflow. Also migrate Workflow Chains not defined anymore on portal_workflow but on the Portal Type. Like other Tools migrations (ERP5CatalogTool...), this is called at startup by synchronizeDynamicModules(), thus Workflows are *not* migrated from DCWorkflow to ERP5 Workflow (ERP5 Workflow portal_workflow can work with both DCWorkflows and ERP5 Workflows), because this is not needed at this stage (handled by bt5 upgrade) and avoid making bootstrap more complicated than it already is. """ from Products.ERP5Type.Tool.WorkflowTool import WorkflowTool if not isinstance(self, WorkflowTool): LOG('WorkflowTool', 0, 'Migrating portal_workflow') portal = self.getPortalObject() # CMFCore portal_workflow -> ERP5 Workflow portal_workflow from Products.ERP5.ERP5Site import addERP5Tool addERP5Tool(portal, 'portal_workflow_new', 'Workflow Tool') new_tool = portal._getOb("portal_workflow_new") new_tool._chains_by_type = self._chains_by_type for workflow_id, workflow in self.objectItems(): workflow_copy = workflow._getCopy(new_tool) workflow_copy._setId(workflow_id) new_tool._setObject(workflow_id, workflow_copy) workflow_copy = new_tool._getOb(workflow_id) workflow_copy._postCopy(new_tool, op=0) workflow_copy.wl_clearLocks() portal.portal_workflow = new_tool portal.portal_workflow.id = 'portal_workflow' portal._delObject('portal_workflow_new') # Migrate Workflow Chains to Portal Types if getattr(new_tool, '_chains_by_type', None) is not None: new_tool.reassignWorkflowWithoutConversion()
def ERP5Site_deleteVifibAccounting(self): portal = self.getPortalObject() delIt(portal, 'portal_simulation') addERP5Tool(portal, 'portal_simulation', 'Simulation Tool') module_id_list = ('accounting_module', 'internal_packing_list_module', 'open_sale_order_module', 'purchase_packing_list_module', 'sale_order_module', 'sale_packing_list_module', 'sale_trade_condition_module', 'system_event_module') for module_id in module_id_list: module = getattr(portal, module_id) portal_type = module.getPortalType() title = module.getTitle() id_generator = module.getIdGenerator() delIt(portal, module_id) portal.newContent(portal_type=portal_type, title=title, id=module_id, id_generator=id_generator) bt5_id_list = ['slapos_accounting', 'slapos_payzen'] for bt5_id in bt5_id_list: bt5 = [q for q in portal.portal_templates.contentValues() if q.getTitle() == bt5_id and q.getInstallationState() == 'installed' ][0].Base_createCloneDocument(batch_mode=1) bt5.activate().install(force=1, update_catalog=0) return 'Done.'