No Description
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.

sites_utils.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ##
  2. #@note in itself thos method should be implemented as custom methods
  3. #for Lodelsite leobject. The current state of the project do not allow
  4. #to do this easily. So you will found them here for the moment....
  5. import os.path
  6. from lodel import buildconf #safe even outside any context
  7. from lodel.context import LodelContext
  8. ##@brief Update the leapi_dyncode.py file for a given site
  9. #
  10. #Follows expectation of LodelContext :
  11. #The leapi_dyncode.py file will be stored in site's context dir
  12. #@param site_name str : site shortname
  13. #@param em_groups list : list of em groups to enable in the dyncode
  14. #@return Nothing
  15. def update_dyncode(site_name, em_groups):
  16. _, ctx_path = LodelContext.lodelsites_paths()
  17. dyncode_path = os.path.join(os.path.join(ctx_path, site_name),
  18. buildconf.MULTISITE_DYNCODE_MODULENAME+'.py')
  19. LodelContext.expose_module(globals(), {
  20. 'lodel.logger': 'logger',
  21. 'lodel.settings': ['Settings'],
  22. 'lodel.editorial_model.model': ['EditorialModel'],
  23. 'lodel.leapi.lefactory': 'lefactory'})
  24. EditorialModel._override_settings(False, em_groups)
  25. model = EditorialModel.load(
  26. Settings.lodelsites.sites_emtranslator,
  27. filename = Settings.lodelsites.sites_emfile)
  28. logger.info('EditorialModel loaded for handled site %s' % site_name)
  29. dyncode = lefactory.dyncode_from_em(model)
  30. with open(dyncode_path, 'w+') as dfp:
  31. dfp.write(dyncode)
  32. EditorialModel._override_settings() #Restoring safe values
  33. logger.info('Dyncode generated for handled site %s' % site_name)
  34. logger.debug('Dyncode for %s contains those groups : %s' % (
  35. site_name, em_groups))