Public
Snippet $88 authored by Tristan Cavelier

osoe referenced document consistency checker

osoe_referenced_document_consistency_checker.py
import re
dry_run = True
portal = context.getPortalObject()
reference_list = [
  "osoe-Lecture.ERP.Configuration.Introduction",

  "CLOUDIA-Questionnaire-AnswerSet.Assign.Students.To.Answer.Sets",
  "CLOUDIA-Questionnaire-AnswerSet.Peer.Review.Check.List",
  "CLOUDIA-Questionnaire-Correction.HowTo",
  "P-CLOUDIA-Category.Spreadsheet.HowTo",
  "P-CLOUDIA-Configuration.Questionnaire",
  "P-CLOUDIA-Configuration.Questionnaire.HowTo.Evaluate.Answers",
  "P-CLOUDIA-Configuration.Questionnaire.HowTo.Fill.In.and.Improve",
  "P-CLOUDIA-Read.Or.You.Will.Die",
  "P-OSOE-Accounting.Mathematician",
  "P-OSOE-Career.Assigment",
  "P-OSOE-Configuration.Sample",
  "P-OSOE-Configuration.Template",
  "P-OSOE-ERP.Configuration.Introduction",
  "P-OSOE-ERP101",
  "P-OSOE-Event",
  "P-OSOE-Order",
  "P-OSOE-Packing.List",
  "P-OSOE-Questionnaire.CaseStudyZawee",
  "P-OSOE-Ticket",
  "P-OSOE-ZAWEE-Configuration",
  "erp5-HowTo.Fix.Erp5.Site.Consistencies.On.Initial.Setup",
  "erp5-HowTo.Process.Incoming.Event",
  "erp5-HowTo.Reset.Listbox.Filter",
  "erp5-HowTo.Try.Erp5.On.A.Virtual.Machine",
  "erp5-Zawee.Success.Case",
  "howto-Create.New.User",
  "osoe-Class.FAQ",
  "osoe-Configuration.Questionnaire",
  "osoe-ERP.Class.Planning.Telecom.Bretagne",
  "osoe-ERP.Configuration.Introduction.Planning",
  "osoe-Questionnaire.Graph",
  "user-Howto.Add.Partner.To.Answer.Set",
  "user-Howto.Conduct.Peer.Review.For.Answer.Set",
  "user-Howto.Configure.ERP5.for.SMB.With.Configurator",
  "user-Howto.Create.A.Payment",
  "user-Howto.Create.Bank.Account",
  "user-Howto.Create.Campaigns",
  "user-Howto.Create.Organisations",
  "user-Howto.Create.Outgoing.Events",
  "user-Howto.Create.Persons",
  "user-Howto.Create.Purchase.Transactions",
  "user-Howto.Create.Sale.Orders",
  "user-Howto.Create.Trade.Conditions",
  "user-Howto.Create.and.Manage.Products",
  "user-Howto.Generate.Report",
  "user-Howto.Link.Persons.and.Organisations",
  "user-Howto.Manage.Document.Versionning",
  "user-Howto.Manage.Invoices",
  "user-Howto.Manage.Packing.Lists",
  "user-Howto.Manage.Support.Request",
  "user-Howto.Post.Outgoing.Events",

  "faq-OSOE.Conditions",
  "news-ERP5.MOOC",
  "faq-User.Cannot.Login",
  "faq-Send.Email.Event",
  "faq-No.Related.Packing-List",
  "faq-No.Tax.Accountling.Line",
  "faq-Invoice.Line.Purchase.Price",
  "faq-Fake.Company",
  "faq-Questionnaire.URL",
  "faq-Questionnaire.Which",
  "faq-Configuration.HowToCreate",
  "P-CLOUDIA-Category-Spreadsheet.HowTo",

  # SVG

  "user-Howto.Create.Bank.Accounts.Organisation.View",
  "user-Howto.Create.New.User.Image",  # svg
  "user-Howto.Create.New.User.Image.Screenshot",  # png
  "user-Howto.Create.New.User.Create.Person",  # svg
  "user-Howto.Create.New.User.Create.Person.Screenshot",  # png
  "user-Howto.Create.New.User.Validate.Person",  # svg
  "user-Howto.Create.New.User.Validate.Person.Screenshot",  # png
  "user-Howto.Create.New.User.Add.Assignment",  # svg
  "user-Howto.Create.New.User.Add.Assignment.Screenshot",  # png
  "user-Howto.Create.New.User.Edit.Assignment",  # svg
  "user-Howto.Create.New.User.Edit.Assignment.Screenshot",  # png
  "user-Howto.Create.New.User.Start.Assignment",  # svg
  "user-Howto.Create.New.User.Start.Assignment.Screenshot",  # png
  "user-Howto.Create.New.User.Assignment.Started",  # svg
  "user-Howto.Create.New.User.Assignment.Started.Screenshot",  # png
  "user-Howto.Create.New.User.Create.User",  # svg
  "user-Howto.Create.New.User.Create.User.Screenshot",  # png
  "user-Howto.Create.New.User.Set.Login.Password",  # svg
  "user-Howto.Create.New.User.Set.Login.Password.Screenshot",  # png
  "user-Howto.Create.New.User.New.User.Login",  # svg
  "user-Howto.Create.New.User.New.User.Login.Screenshot",  # png

  "osoe-erp-101.cover",
  "osoe-erp.101.requirements-screenshot",
  "Pictures92277",
  "world.mouse",
  "user-OSOE.Erp.Facts",
  "user-OSOE.Erp.Facts.Pic",
  "osoe-who.needs.an.erp-screenshot",
  "User-Graphics-need-erp5",
  "osoe-who.dont.needs.an.erp-screenshot",
  "User-Graphics-not-need-erp5",
  "osoe-key.players",
  "osoe-key.players-screenshot",
  "osoe-the.erp.cost-screenshot",
  "graphic-ERP5.Logo",
  "graphic-SlapOS.logo",
  "osoe-how.mush.implementation-screenshot",
  "osoe-what.is.success.rate-screenshot",
  "osoe-are.there.alternatives-screenshot",
  "User-Graphics-alternatives",
  "osoe-what.is.an.erp-screenshot",
  "user-Howto.ERP5.Browse.Page.Screenshot",
  "osoe-unified.database-screenshot",
  "User-Graphics-Database",
  "osoe-singlesoftware.widecoverage-screenshot",
  "User-Graphics-Wide-Coverage",
  "osoe-everyone.must.use.it-screenshot",
  "User-Graphics-Everyonce-Use",
  "osoe-business.workflow-screenshot",
  "osoe-past.present.future-screenshot",
  "User-Graphics-Past.Present.Future",
  "osoe-what.makes.erp.different-screenshot",
  "User-Graphics-MRP",
  "osoe-mrp1.meterials-screenshot",
  "User-Graphics-CAR",
  "osoe-mrp2.resources.large-screenshot",
  "osoe-erp.extension-crm-screenshot",
  "User-Graphics-ERP-Extensio",
  "osoe-erp.extension-km-screenshot",
  "User-Graphics-ERP-Extension2",
  "osoe-erp..web-ebusiness-screenshot",
  "User-Graphics-ERP-Web",
  "user-OSOE.Website.Homepage",
  "user-OSOE.Website.Screenshot",

  # found with wget

  "CLOUDIA-Questionnaire-AnswerSet.Assign.Students.To.Answer.Sets",
  "CLOUDIA-Questionnaire-AnswerSet.Peer.Review.Check.List",
  "CLOUDIA-Questionnaire-Correction.HowTo",
  "developer-ERP5.Inventory.POS.View",
  "erp5-HowTo.Fix.Erp5.Site.Consistencies.On.Initial.Setup",
  "erp5-HowTo.Try.Erp5.On.A.Virtual.Machine",
  "erp5-release.information",
  "erp5-Zawee.Success.Case",
  "faq-Configuration.HowToCreate",
  "faq-Fake.Company",
  "faq-Invoice.Line.Purchase.Price",
  "graphic-ERP5.ECommerce.Screenshot",
  "graphic-OSOE.Banner",
  "howto-Create.New.User",
  "image-FISL12.Cloudooo.Presentation",
  "image-FISL12.ERP5.Configurator",
  "image-FISL12.Sanef.Tolling.UK",
  "image-FISL12.SlapOS.Presentation",
  "news-ERP5.MOOC",
  "news-osoe.classes.at.brazil",
  "news-OSOE.Debut",
  "news-slapos-reaction-patriot",
  "news-slapos-success",
  "osoe-Class.FAQ",
  "osoe-Configuration.Questionnaire",
  "osoe-documentation",
  "osoe-ERP.Class.Planning.Telecom.Bretagne",
  "osoe-ERP.Configuration.Introduction.Planning",
  "osoe-Lecture.Develop.ERP5.Application",
  "osoe-Lecture.ERP.Configuration.Introduction",
  "osoe-Lecture.ERP.Data.Mining.Introduction",
  "osoe-Lecture.ERP.Programming.Introduction",
  "osoe-Lecture.SlapOS.Extended",
  "osoe-Questionnaire.Graph",
  "osoe-summer.Camp.Natal.Brasil.Edition",
  "P-CLOUDIA-Category.Spreadsheet.HowTo",
  "P-CLOUDIA-Configuration.Questionnaire",
  "P-CLOUDIA-Configuration.Questionnaire.HowTo",
  "P-CLOUDIA-Configuration.Questionnaire.HowTo.Evaluate.Answers",
  "P-CLOUDIA-Configuration.Questionnaire.HowTo.Fill.In.and.Improve",
  "P-CLOUDIA-Read.Or.You.Will.Die",
  "P-OSOE-Accounting.Mathematician",
  "P-OSOE-Career.Assigment",
  "P-OSOE-Configuration.Sample",
  "P-OSOE-Configuration.Template",
  "P-OSOE-ERP.Configuration.Introduction",
  "P-OSOE-Event",
  "P-OSOE-One.Student.One.ERP",
  "P-OSOE-Order",
  "P-OSOE-Packing.List",
  "P-OSOE-Questionnaire.CaseStudyZawee",
  "P-OSOE-Ticket",
  "P-OSOE-ZAWEE-Configuration",
  "P-VIFIB-SlapOS.Early.Success",
  "user-Accounting.Guide",
  "user-Howto.Add.Partner.To.Answer.Set",
  "user-Howto.Conduct.Peer.Review.For.Answer.Set",
  "user-Howto.Configure.ERP5.for.SMB.With.Configurator",
  "user-Howto.Create.and.Manage.Products",
  "user-Howto.Create.A.Payment",
  "user-Howto.Create.Bank.Account",
  "user-Howto.Create.Campaigns",
  "user-Howto.Create.Organisations",
  "user-Howto.Create.Outgoing.Events",
  "user-Howto.Create.Persons",
  "user-Howto.Create.Purchase.Transactions",
  "user-Howto.Create.Sale.Orders",
  "user-Howto.Create.Trade.Conditions",
  "user-Howto.Generate.Report",
  "user-Howto.Link.Persons.and.Organisations",
  "user-Howto.Manage.Document.Versionning",
  "user-Howto.Manage.Invoices",
  "user-Howto.Manage.Packing.Lists",
  "user-Howto.Manage.Support.Request",
  "user-Howto.Post.Outgoing.Events",
]

already_commited_id_list = [
  "developer-Test.Page.Sample",
  "user-HowTo.Change.Language-TESTONLY",
  "user-Howto.Create.and.Manage.Products",
  "user-Howto.Create.A.Payment",
  "user-Howto.Create.Bank.Account",
  "user-Howto.Create.Campaigns",
  "user-Howto.Create.Organisations",
  "user-Howto.Create.Outgoing.Events",
  "user-Howto.Create.Persons",
  "user-Howto.Create.Sale.Orders",
  "user-Howto.Create.Trade.Conditions.007.en",
  "user-Howto.Generate.Report",
  "user-Howto.Link.Persons.and.Organisations",
  "user-Howto.Manage.Invoices",
  "user-Howto.Manage.Packing.Lists",
  "user-Howto.Manage.Support.Request.007.en",
  "user-Howto.Post.Outgoing.Events",
  "user-HowTo.Use.FullText.Search-TESTONLY",

  "user-Howto.Configure.ERP5.for.SMB.With.Configurator",  # erp5_configurator_standard_ui_test
]

reference_list = list(set(reference_list))
for o in portal.portal_catalog(portal_type=portal.getPortalDocumentTypeList(), reference=reference_list, validation_state=("published", "published_alive")):
  try: reference_list.remove(o.getReference())
  except ValueError: pass
  already_commited = "already commited" if o.getId() in already_commited_id_list else ""
  related_object_list = portal.portal_catalog(**{"category.category_uid": o.getUid()})
  #related_object_list = [x for x in related_object_list if x.getRelativeUrl() != o.getRelativeUrl()]
  bound_by_category = len(related_object_list)
  bound_by_category = ("used by %d object(s) [%s]" % (bound_by_category, ", ".join([x.getRelativeUrl() for x in related_object_list]),) if bound_by_category else "")
  if re.match(r"[0-9]+$", o.getId()):
    new_id = "%s.%s.%s" % (o.getReference(), o.getVersion() or "001", o.getLanguage() or "en",)
    print "%s <a href=\"%s\">%s</a> <a href=\"http://www.osoe-project.org/%s\">&lt;/&gt;</a> %s <span style=\"color: green;\">%s</span> <span style=\"color: red;\">%s</span>" % (
      o.getPortalType(),
      o.absolute_url(),
      o.getId(),
      o.getReference(),
      new_id,
      already_commited,
      bound_by_category,
    )
    if not dry_run:
      o.edit(id=new_id)
  else:
    print "%s <a href=\"%s\">%s</a> <a href=\"http://www.osoe-project.org/%s\">&lt;/&gt;</a> <span style=\"color: green;\">%s</span> <span style=\"color: green;\">%s</span>" % (
      o.getPortalType(),
      o.absolute_url(),
      o.getId(),
      o.getReference(),
      already_commited,
      bound_by_category,
    )

if reference_list:
  print "and last:"
  for reference in reference_list:
    print reference, "not found"
return "<pre>" + printed + "</pre>" if printed else "none"