def checkConversionToolAvailability(self): """ Check conversion tool (oood) is available for erp5. This script convert an odt document into HTML and try to read the returned string and find out expected string """ portal = self.getPortalObject() document_id = 'P-ERP5-TEST.Conversion.Tool.Availability-001-en.odt' document_path = 'portal_skins/erp5_administration/%s' % (document_id,) document_file = portal.restrictedTraverse(document_path) message = None severity = 0 try: temp_document = newTempOOoDocument(self, document_id, data=document_file.data, source_reference=document_id) temp_document.convertToBaseFormat() _, html_result = temp_document.convert(format='html') except ConflictError: raise except: #Which Errors should we catch ? #Transformation failed message = 'Conversion tool got unexpected error:\n%s' % ''.join(ExceptionFormatter.format_exception(*sys.exc_info())) else: #Everything goes fine, Check that expected string is present in HTML conversion if 'AZERTYUIOPMQ' not in html_result: message = 'Conversion to HTML Failed:\n%s' % (html_result,) active_process = self.newActiveProcess() result = ActiveResult() if message: severity = 1 result.edit(detail=message) result.edit(severity=severity) active_process.postResult(result)
def example_random_forest_function(self, active_process_path): digits = load_digits() X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target, random_state=0) # Create an active process active_process = self.portal_activities.unrestrictedTraverse( active_process_path) # Use CMFActivity as a backend for joblib with parallel_backend('CMFActivity', n_jobs=2, active_process=active_process): final_model = grow_ensemble(RandomForestClassifier(), X_train, y_train, n_estimators=10, n_jobs=2, random_state=42) score = final_model.score(X_test, y_test) # Set result value and an id to the active result and post it result = ActiveResult(result=score, signature=123) active_process.postResult(result) log('ok', len(final_model.estimators_)) return 'ok', len(final_model.estimators_), score
def check(node_uid, section_uid, mirror_section_uid): precision = precision_by_section_uid[section_uid] if mirror_section_uid is None: mirror_section_uid = SimpleQuery(mirror_section_uid=None) line_list = portal.portal_simulation.getMovementHistoryList( portal_type=portal.getPortalAccountingMovementTypeList(), grouping_reference=context.getGroupingReference(), node_uid=node_uid, section_uid=section_uid, mirror_section_uid=mirror_section_uid) if not line_list: return total = round(sum([(l.total_price or 0) for l in line_list]), precision) if total != 0: # XXX if n transactions that do not match are grouped together, the same # problem will be reported n times. portal.restrictedTraverse(active_process).postResult( ActiveResult(summary=script.getId(), detail='%s has wrong grouping (%s)' % (context.getRelativeUrl(), total), result='', severity=100)) # XXX we could check this as well """
def ERP5Site_clearActivities(self): """ This method is used to recreated the activities keeping the previous activities from one activity. The issue related to recreate the Activity tables from one activity is that the activity (this method) is also recreated, so it is kept for ever. This method use a flag to define if the portal already recreated the activities table. If yes, the flag is removed and the recreation will be ignored. This method should be run into a single activity to prevent some action be excetured many times other parts. """ instance_home = getConfiguration().instancehome flag_fs_path = instance_home + "/ACTIVITY_RECREATE_FLAG" log("Start to Clear activities.") if not os.path.exists(flag_fs_path): try: flag = open(flag_fs_path, 'w+') log("Clear Activities") self.getPortalObject().portal_activities.manageClearActivities( keep=1) active_result = ActiveResult() active_result.edit( summary="Activities Recreated", severity=0, detail="Activities Tables was recreated Sucessfully.") return active_result except: os.remove(flag_fs_path) raise os.remove(flag_fs_path) return
def example_simple_function(self, active_process_path): """ simple function to calculate sqrt """ active_process = self.portal_activities.unrestrictedTraverse( active_process_path) # Use CMFActivity as a backend for joblob with parallel_backend('CMFActivity', active_process=active_process): result = Parallel(n_jobs=2, pre_dispatch='all', timeout=30, verbose=30)(delayed(sqrt)(i**2) for i in range(5)) # Set result value and an id to the active result and post it result = ActiveResult(result=result) active_process.postResult(result) log("joblib activity result", result) return result
def ERP5Site_restartZopeInstance(self): """ Zope must be restart after update the Products or Software But the restart into one activity, will make the activity always fail and with the server will be restart many times. This method use a flag to define if the server was already restarted. If yes, the flag is removed and the restart will be ignored. This method should be run into a single activity to prevent rollback other parts. """ import Lifetime Lifetime.shutdown(1, fast=1) log("Zope Restart was launched.") active_result = ActiveResult() active_result.edit(summary="Zope Restart", severity=0, detail="Zope was restart Sucessfully.") return active_result
from Products.CMFActivity.ActiveResult import ActiveResult portal = context.getPortalObject() portal_type = portal.portal_types[portal_type] active_process = portal.restrictedTraverse(active_process) this_portal_type_active_process = portal.restrictedTraverse(this_portal_type_active_process) # XXX we need proxy role for this result_list = this_portal_type_active_process.getResultList() if result_list: journal_fragment = context.AccountingTransactionModule_viewJournalAsFECXML( portal_type=portal_type, result_list=result_list) active_process.postResult(ActiveResult(detail=journal_fragment.encode('utf8').encode('zlib'))) # delete no longer needed active process this_portal_type_active_process.getParentValue().manage_delObjects(ids=[this_portal_type_active_process.getId()])
"amount": line.total_price or 0, "quantity": line.quantity or 0, "quantity_unit": translate(line.strict_quantity_unit_title) } } else: if not line_dict[product_title].has_key(period): line_dict[product_title][period] = { "amount": line.total_price or 0, "quantity": line.quantity or 0, "quantity_unit": translate(line.strict_quantity_unit_title) } else: line_dict[product_title][period]['amount'] = line_dict[ product_title][period]['amount'] + (line.total_price or 0) line_dict[product_title][period]['quantity'] = line_dict[ product_title][period]['quantity'] + (line.quantity or 0) active_process_value = portal.restrictedTraverse(active_process) active_process_value.postResult( ActiveResult(sevrity=1, detail=dumps({ 'type': "result", 'client_dict': client_dict, 'product_dict': product_dict, })))
def some(iterable, function): for v in iterable: if function(v): return True return False # Browse files and folders recursively def execute(skin): for o in skin.objectValues(): # browsing files oid = o.id # force oid to be a string if callable(oid): oid = oid() if o.meta_type in meta_type_checklist or \ some(file_extension_checklist, oid.endswith): # this file matches the cheklists requirements current_cache_manager_id = o.ZCacheable_getManagerId() if current_cache_manager_id is None: # the current file is not cached if fixit: o.ZCacheable_setManagerId(cache_manager_id) else: incorrect_file_absolute_url_list.append(o.absolute_url(relative=1)) elif o.meta_type == 'Folder': execute(o) for skin in context.portal_skins.objectValues(): execute(skin) if incorrect_file_absolute_url_list != []: return ActiveResult(severity=100, detail="There is no cache set for:\n" + "\n".join(incorrect_file_absolute_url_list)) return ActiveResult(severity=0, detail="OK")
from Products.CMFActivity.ActiveResult import ActiveResult portal = context.getPortalObject() mailhost = portal.MailHost if getattr(mailhost, 'getMessageList', None) is not None: context.newActiveProcess().postResult( ActiveResult( severity=1, summary="%s/MailHost is not real MailHost" % portal.getPath(), detail= "Possibly comes from DummyMailHost. The object has to be fixed by recreating it." )) return promise_url = portal.getPromiseParameter('external_service', 'smtp_url') if promise_url is None: return promise_url = promise_url.rstrip('/') if mailhost.force_tls: protocol = 'smtps' else: protocol = 'smtp' if mailhost.smtp_uid: auth = '%s:%s@' % (mailhost.smtp_uid, mailhost.smtp_pwd) else: auth = '' url = "%s://%s%s:%s" % (protocol, auth, mailhost.smtp_host, mailhost.smtp_port)
from Products.CMFActivity.ActiveResult import ActiveResult portal = context.getPortalObject() tracking_list = list( reversed( portal.portal_simulation.getCurrentTrackingList( aggregate_uid=context.getUid()))) if tracking_list: delivery_dict = { x.uid: x.getObject() for x in portal.portal_catalog( uid=[x.delivery_uid for x in tracking_list], ) } for previous_brain, next_brain in zip(tracking_list, tracking_list[1:]): if delivery_dict[previous_brain.delivery_uid].getDestination( ) != delivery_dict[next_brain.delivery_uid].getSource(): portal.restrictedTraverse(active_process).postResult( ActiveResult(summary=script.getId(), detail='%s has tracking error' % context.getRelativeUrl(), result='', severity=100))
'view', keep_items=dict(portal_status_message=N_( "You haven't defined your email address"))) parameter_dict, stat_columns, selection_columns = context.OrderModule_getOrderReportParameterDict( ) active_process = context.OrderModule_activateGetOrderStatList(tag=script.id, **parameter_dict) # Create a result to store computed parameter for later active_process.postResult( ActiveResult(sevrity=1, detail=dumps({ 'type': 'parameters', 'params': parameter_dict, 'stat_columns': stat_columns, 'selection_columns': selection_columns, }))) request = context.REQUEST context.getPortalObject().portal_skins.changeSkin("Deferred") request.set('portal_skin', "Deferred") assert deferred_portal_skin is not None, "No deferred portal skin found in parameters" request.set('deferred_portal_skin', deferred_portal_skin) kw['deferred_style'] = 1 kw['active_process'] = active_process.getPath() request.set('active_process', active_process.getPath()) kw.update(parameter_dict) kw.pop('format', None)
# it is not possible to checkConsistency of Constraint itself, as method # of this name implement consistency checking on object return constraint_message_list # this constraint is created as a temp object under portal_trash, because # portal_trash has no restriction on allowed content types. missing_category_document = portal.portal_trash.newContent( portal_type='Missing Category Document Constraint', id='missing_category_document_constraint', temp_object=True) property_type_validity = PropertyTypeValidity( id='type_check', description='Type Validity Check') if fixit: constraint_message_list.extend(context.fixConsistency()) constraint_message_list.extend( property_type_validity.fixConsistency(context)) constraint_message_list.extend( missing_category_document.fixConsistency(context)) else: constraint_message_list.extend(context.checkConsistency(fixit=fixit)) constraint_message_list.extend( property_type_validity.checkConsistency(context, fixit=fixit)) constraint_message_list.extend( missing_category_document.checkConsistency(context, fixit=fixit)) if constraint_message_list: portal.restrictedTraverse(active_process).postResult( ActiveResult(severity=100, constraint_message_list=constraint_message_list))
"""Produce an xml fragment for this accounting transaction and post it to the active result. We need a proxy role to post the result. """ from Products.CMFActivity.ActiveResult import ActiveResult portal = context.getPortalObject() active_process = portal.restrictedTraverse(active_process) accounting_line_list = context.contentValues( portal_type=portal.getPortalAccountingMovementTypeList()) if context.getSourceSectionUid() in section_uid_list: if any([ line.getSource(portal_type='Account') for line in accounting_line_list ]): source_xml = context.AccountingTransaction_viewAsSourceFECXML() active_process.postResult( ActiveResult(detail=source_xml.encode('utf8').encode('zlib'))) if context.getDestinationSectionUid() in section_uid_list: if any([ line.getDestination(portal_type='Account') for line in accounting_line_list ]): destination_xml = context.AccountingTransaction_viewAsDestinationFECXML( ) active_process.postResult( ActiveResult(detail=destination_xml.encode('utf8').encode('zlib')))
for brain in portal.portal_simulation.getInventoryList(**search_params): if round(brain.total_price, precision) == 0: print '%s has a 0 balance but some not grouped transactions.' % brain.mirror_section_relative_url if fixit: tr = brain.getObject().getParentValue() grouped_line_list = tr.AccountingTransaction_guessGroupedLines() if not grouped_line_list: # Group whatever can be grouped. XXX maybe we want to make this optional. grouped_line_list = tr.AccountingTransaction_guessGroupedLines( accounting_transaction_line_uid_list=[ line.uid for line in portal.portal_simulation.getMovementHistoryList( node_uid=brain.node_uid, mirror_section_uid=brain.mirror_section_uid, section_uid=section_uid_list, simulation_state=('stopped', 'delivered'), portal_type=portal.getPortalAccountingMovementTypeList(), grouping_reference=None,) if not line.getObject().getGroupingReference()]) if grouped_line_list: print 'FIXED', grouped_line_list else: print 'NOT FIXED' active_result = ActiveResult( summary=context.getTitle(), severity=str(printed) and 100 or 0, detail=printed,) active_process.postResult(active_result)
portal = context.getPortalObject() promise_repository = portal.getPromiseParameter('portal_templates', 'repository') if promise_repository is None: return if promise_repository: promise_repository_list = promise_repository.split() promise_repository_list.sort() else: promise_repository_list = [] repository_list = portal.portal_templates.getRepositoryList() repository_list.sort() active_result = ActiveResult() if repository_list != promise_repository_list: severity = 1 summary = "Template tool not configured as expected" detail = '\n'.join(promise_repository_list) else: severity = 0 summary = "Nothing to do." detail = "" active_result.edit(summary=summary, severity=severity, detail=detail) context.newActiveProcess().postResult(active_result)
from Products.ERP5Type.Constraint import PropertyTypeValidity from Products.CMFActivity.ActiveResult import ActiveResult portal = context.getPortalObject() constraint_message_list = [] if context.providesIConstraint(): # it is not possible to checkConsistency of Constraint itself, as method # of this name implement consistency checking on object return constraint_message_list missing_category_document = portal.portal_trash.newContent( portal_type='Missing Category Document Constraint', temp_object=True) property_type_validity = PropertyTypeValidity(id='type_check', description='Type Validity Check') if fixit: constraint_message_list.extend(context.fixConsistency()) constraint_message_list.extend(property_type_validity.fixConsistency(context)) constraint_message_list.extend(missing_category_document.fixConsistency(context)) else: constraint_message_list.extend(context.checkConsistency(fixit=fixit)) constraint_message_list.extend(property_type_validity.checkConsistency(context, fixit=fixit)) constraint_message_list.extend(missing_category_document.checkConsistency(context, fixit=fixit)) if constraint_message_list: portal.restrictedTraverse(active_process).postResult(ActiveResult(severity=100, constraint_message_list=constraint_message_list))