Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

utils.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. from loader import *
  3. import warnings
  4. def refreshdyn():
  5. import sys
  6. from EditorialModel.model import Model
  7. from leapi.lefactory import LeFactory
  8. from EditorialModel.backend.json_backend import EmBackendJson
  9. from DataSource.MySQL.leapidatasource import LeDataSourceSQL
  10. OUTPUT = Settings.dynamic_code_file
  11. EMJSON = Settings.em_file
  12. # Load editorial model
  13. em = Model(EmBackendJson(EMJSON))
  14. # Generate dynamic code
  15. fact = LeFactory(OUTPUT)
  16. # Create the python file
  17. fact.create_pyfile(em, LeDataSourceSQL, {})
  18. def db_init():
  19. from EditorialModel.backend.json_backend import EmBackendJson
  20. from EditorialModel.model import Model
  21. mh = getattr(migrationhandler,Settings.mh_classname)()
  22. em = Model(EmBackendJson(Settings.em_file))
  23. em.migrate_handler(mh)
  24. def em_graph(output_file = None, image_format = None):
  25. from EditorialModel.model import Model
  26. from EditorialModel.backend.json_backend import EmBackendJson
  27. from EditorialModel.backend.graphviz import EmBackendGraphviz
  28. import subprocess
  29. if image_format is None:
  30. if hasattr(Settings, 'em_graph_format'):
  31. image_format = Settings.em_graph_format
  32. else:
  33. image_format = 'png'
  34. if output_file is None:
  35. if hasattr(Settings, 'em_graph_output'):
  36. output_file = Settings.em_graph_output
  37. else:
  38. output_file = '/tmp/em_%s_graph.dot'
  39. image_format = image_format.lower()
  40. try:
  41. output_file = output_file%Settings.sitename
  42. except TypeError:
  43. warnings.warn("Bad filename for em_graph output. The filename should be in the form '/foo/bar/file_%s_name.png")
  44. pass
  45. dot_file = output_file+".dot"
  46. graphviz_bckend = EmBackendGraphviz(dot_file)
  47. edmod = Model(EmBackendJson(Settings.em_file))
  48. graphviz_bckend.save(edmod)
  49. dot_cmd = [
  50. "dot",
  51. "-T%s"%image_format,
  52. dot_file
  53. ]
  54. with open(output_file, "w+") as outfp:
  55. subprocess.check_call(dot_cmd, stdout=outfp)
  56. os.unlink(dot_file)
  57. print("Output image written in file : '%s'" % output_file)