convert.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import core.export.utils.py2xml
  20. import core.export.utils.py2txt
  21. def to_xml(data, root_name = None):
  22. serializer = core.export.utils.py2xml.Py2XML()
  23. return serializer.parse(data, objName=root_name)
  24. def to_python(data, root_name = None):
  25. prefix = ""
  26. postfix = ""
  27. if root_name != None:
  28. prefix = "{'" + root_name + ": "
  29. postfix = "}"
  30. return prefix + data.__repr__() + postfix
  31. def to_txt(data, root_name = None):
  32. serializer = core.export.utils.py2txt.Py2TXT()
  33. return serializer.parse(data, objName=root_name, indent = -1)