Nessuna descrizione
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.

lodel_admin.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #-*- coding: utf-8 -*-
  2. import sys
  3. import os, os.path
  4. import loader
  5. from lodel.settings import Settings
  6. from lodel import logger
  7. ## @brief Utility method to generate python code given an emfile and a
  8. # translator
  9. # @param model_file str : An em file
  10. # @param translator str : a translator name
  11. # @return python code as string
  12. def generate_dyncode(model_file, translator):
  13. from lodel.editorial_model.model import EditorialModel
  14. from lodel.leapi import lefactory
  15. model = EditorialModel.load(translator, filename = model_file)
  16. dyncode = lefactory.dyncode_from_em(model)
  17. return dyncode
  18. ## @brief Utility method to generate a python file representing leapi dyncode
  19. # given an em file and the associated translator name
  20. #
  21. # @param model_file str : An em file
  22. # @param translator str : a translator name
  23. # @param output_filename str : the output file
  24. def create_dyncode(model_file, translator, output_filename):
  25. dyncode = generate_dyncode(model_file, translator)
  26. with open(output_filename, 'w+') as out_fd:
  27. out_fd.write(dyncode)
  28. out_fd.close()
  29. logger.info("Dynamic leapi code written in %s", output_filename)
  30. ## @brief Refresh dynamic leapi code from settings
  31. def refresh_dyncode():
  32. # EditorialModel update/refresh
  33. # TODO
  34. # Dyncode refresh
  35. create_dyncode( Settings.editorialmodel.emfile,
  36. Settings.editorialmodel.emtranslator,
  37. Settings.editorialmodel.dyncode)