Ejemplo n.º 1
0
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 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.activateResult(result)
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 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)
Ejemplo n.º 5
0
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
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
Ejemplo n.º 7
0
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)
packet_size = search_kw.pop('packet_size', 30)
limit = packet_size * search_kw.pop('activity_count', 100)

r = sub.getDocumentIdList(limit=limit, **search_kw)

result_count = len(r)
if result_count:
  if result_count == limit:
    # Recursive call to prevent too many activity generation
    next_kw = dict(activate_kw, priority=1+activate_kw.get('priority', 1))
    kw["min_id"] = r[-1].getId()
    sub.activate(**next_kw).SynchronizationTool_activateCheckPointFixe(
      callback, method_kw, activate_kw, **kw)

  r = [x.getId() for x in r]
  callback_method = getattr(sub.activate(**activate_kw), callback)
  for i in xrange(0, result_count, packet_size):
    callback_method(id_list=r[i:i+packet_size],
                    **method_kw)

if result_count < limit:
  # Register end of point fixe
  from Products.CMFActivity.ActiveResult import ActiveResult
  active_result = ActiveResult()
  active_result.edit(summary='Info',
                   severity=0,
                   detail="Point fixe check ended at %r" % (DateTime().strftime("%d/%m/%Y %H:%M"),))
  sub.activate(active_process=method_kw["active_process"],
              activity='SQLQueue', 
              priority=2,).ERP5Site_saveCheckCatalogTableResult(active_result)
Ejemplo n.º 9
0
active_result = ActiveResult()

bt5_list = bt5.split()
bt5_list.extend(template_tool.getInstalledBusinessTemplateTitleList())

try:
  message_list = template_tool.upgradeSite(bt5_list, dry_run=True,
                                 update_catalog=CATALOG_UPDATABLE)
  severity = len(message_list)
except BusinessTemplateUnknownError, error:
  severity = -1
  detail = str(error)

if severity == -1:
  severity = 5
  summary = "Unable to resolve bt5 dependencies"
elif severity == 0:
  summary = "Nothing to do."
  detail = ""
else:
  summary = "Upgrade needed."
  detail = "Information: %s" % ",".join(message_list)


active_result.edit(
  summary=summary, 
  severity=severity,
  detail=detail)

context.newActiveProcess().postResult(active_result)
Ejemplo n.º 10
0
from Products.CMFActivity.ActiveResult import ActiveResult

portal = context.getPortalObject()
promise_url = portal.getPromiseParameter('external_service', 'kumofs_url')

if promise_url is None:
  return

plugin = portal.portal_memcached.restrictedTraverse("persistent_memcached_plugin", None)
if plugin is None:
  return

url = "memcached://%s/" % plugin.getUrlString()

active_result = ActiveResult()

if promise_url != url:
  severity = 1
  summary = "Kumofs not configured as expected"
else:
  severity = 0
  summary = "Nothing to do."

active_result.edit(
  summary=summary, 
  severity=severity, 
  detail="Expect %s\nGot %s" % (promise_url, url))

context.newActiveProcess().postResult(active_result)
    try:
        sub_xml = getattr(sub_object,
                          sub_xml_method_id)(context_document=subscription)
    except TypeError:
        sub_xml = getattr(sub_object, sub_xml_method_id)()
    if pub_object:
        try:
            pub_xml = getattr(pub_object,
                              pub_xml_method_id)(context_document=publication)
        except TypeError:
            pub_xml = getattr(pub_object, pub_xml_method_id)()
    else:
        pub_xml = ""
    diff = portal.diffXML(xml_plugin=sub_xml, xml_erp5=pub_xml, html=False)
    context.log("Got diff for GID %s" % (gid, ))
    if diff != "No diff":
        append(diff)

if len(diff_list):
    severity = len(diff_list)
    from Products.CMFActivity.ActiveResult import ActiveResult
    active_result = ActiveResult()
    active_result.edit(summary='Failed',
                       severity=severity,
                       detail='\n'.join(diff_list))
    subscription.activate(
        active_process=active_process,
        activity='SQLQueue',
        priority=2,
    ).ERP5Site_saveCheckCatalogTableResult(active_result)
  gid = subscription.getGidFromObject(sub_object)
  # Retrieve the corresponding document from the publication
  pub_object = publication.getDocumentFromGid(gid)
  # Compare their xml
  try:
    sub_xml = getattr(sub_object, sub_xml_method_id)(context_document=subscription)
  except TypeError:
    sub_xml = getattr(sub_object, sub_xml_method_id)()
  if pub_object:
    try:
      pub_xml = getattr(pub_object, pub_xml_method_id)(context_document=publication)
    except TypeError:
      pub_xml = getattr(pub_object, pub_xml_method_id)()
  else:
    pub_xml = ""
  diff = portal.diffXML(xml_plugin=sub_xml, xml_erp5=pub_xml, html=False)
  context.log("Got diff for GID %s" %(gid,))
  if diff != "No diff":
    append(diff)

if len(diff_list):
  severity = len(diff_list)
  from Products.CMFActivity.ActiveResult import ActiveResult
  active_result = ActiveResult()
  active_result.edit(summary='Failed',
                     severity=severity,
                     detail='\n'.join(diff_list))
  subscription.activate(active_process=active_process,
            activity='SQLQueue', 
            priority=2,).ERP5Site_saveCheckCatalogTableResult(active_result)
Ejemplo n.º 13
0
                            len(activity_catalog_uid_list)))
      activate(tag=worker_tag, **activity_kw) \
      .ERP5Site_checkCatalogTable(catalog_uid_list=activity_catalog_uid_list,
                                  catalog_kw=catalog_kw, **check_kw)
    else:
      result_list.append('Spawning an activity to fetch a new batch starting'
                         ' above uid %i' % uid_min)
      # For loop was not interrupted by a break, which means that all
      # activities got uids to process. Maybe there is another batch of uids
      # to check besides current one. Spawn an activity to process such batch.
      activate(after_tag=worker_tag, tag=tag, **activity_kw) \
      .ERP5Site_checkCatalogTable(uid_min=uid_min,
                                  catalog_kw=catalog_kw, **check_kw)
  else:
    result_list.append('Base_zGetAllFromcatalog found no more line to check.')
  active_result.edit(summary='Spawning activities', severity=0, detail='\n'.join(result_list))
  # Spawn an activity to save generated active result only if it's not the initial run
  if not first_run:
    activate(active_process=active_process, activity='SQLQueue', priority=2, tag=tag) \
    .ERP5Site_saveCheckCatalogTableResult(active_result)
else:
  # Process given uid list
  retry_uid_list = []
  restrictedTraverse = portal.restrictedTraverse
  catalog_line_list = portal.portal_catalog(uid=catalog_uid_list, **catalog_kw)
  attribute_id_list = catalog_line_list.names()
  attribute_id_list.remove('path')

  def error(message):
    if retry:
      retry_uid_list.append(catalog_line['uid'])
Ejemplo n.º 14
0
method_kw = {
    "publication_path": pub.getPath(),
    "subscription_path": sub.getPath(),
    "active_process": active_process_path,
}
activate_kw = {
    "priority": 3,
    "activity": "SQLQueue",
}

# Register start of point fixe
from Products.CMFActivity.ActiveResult import ActiveResult

active_result = ActiveResult()
active_result.edit(summary='Info',
                   severity=0,
                   detail="Point fixe check launched at %r" %
                   (DateTime().strftime("%d/%m/%Y %H:%M"), ))
sub.activate(
    active_process=active_process_path,
    activity='SQLQueue',
    priority=2,
).ERP5Site_saveCheckCatalogTableResult(active_result)

context.SynchronizationTool_activateCheckPointFixe(callback=callback,
                                                   method_kw=method_kw,
                                                   activate_kw=activate_kw)

qs = '?portal_status_message=%s' % "Point fixe running, active process path is %s" % (
    active_process_path, )
return request.RESPONSE.redirect(context.absolute_url() + '/' + form_id + qs)
Ejemplo n.º 15
0
from Products.CMFActivity.ActiveResult import ActiveResult
active_result = ActiveResult()
severity = len(error_list)
if severity == 0:
  summary = "No error"
else:
  summary = "Error"
active_result.edit(summary=summary, severity=severity, detail='\n'.join(error_list))
return active_result