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.

xeputil.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # File: xeputil.py
  2. # Version: 0.2
  3. # Description: xep utility functions
  4. # Last Modified: 2010
  5. # Author: Tobias Markmann (tm@ayena.de)
  6. ## LICENSE ##
  7. #
  8. # Copyright (c) 1999 - 2009 XMPP Standards Foundation
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining a copy
  11. # of this software and associated documentation files (the "Software"), to deal
  12. # in the Software without restriction, including without limitation the rights
  13. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. # copies of the Software, and to permit persons to whom the Software is
  15. # furnished to do so, subject to the following conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be included in
  18. # all copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. # THE SOFTWARE.
  27. #
  28. ## END LICENSE ##
  29. import os
  30. import tempfile
  31. from xepinfo import XEPInfo
  32. from xml.dom.minidom import parse,parseString,Document,getDOMImplementation
  33. from mercurial import ui, hg
  34. from mercurial.node import hex
  35. def getText(nodelist):
  36. thisText = ""
  37. for node in nodelist:
  38. if node.nodeType == node.TEXT_NODE:
  39. thisText = thisText + node.data
  40. return thisText
  41. class XEP:
  42. def __init__(self, BASEDIR, nr):
  43. self.nr = nr
  44. self.BASEDIR = BASEDIR
  45. def revisions(self):
  46. repo = hg.repository(ui.ui(), self.BASEDIR)
  47. fctx = repo.filectx("xep-" + self.nr + ".xml", 'tip')
  48. revs = []
  49. for rev in fctx.filelog():
  50. revs.append(fctx.filectx(rev).rev())
  51. return sorted(revs)
  52. def contentOfRevision(self, revision):
  53. repo = hg.repository(ui.ui(), self.BASEDIR)
  54. fctx = repo.filectx("xep-" + self.nr + ".xml", revision)
  55. # load content for that revision
  56. file_text = fctx.data()
  57. return file_text
  58. def globalLatestRevison(self):
  59. repo = hg.repository(ui.ui(), self.BASEDIR)
  60. cctx = repo['tip']
  61. return cctx.rev()
  62. def getLatestXEPFilename(XEPDIR, nr, no_interim=True):
  63. try:
  64. xep = XEP(XEPDIR, nr)
  65. revs = xep.revisions()
  66. revs.reverse()
  67. content = ""
  68. if no_interim:
  69. for rev in revs:
  70. tmp_content = xep.contentOfRevision(rev)
  71. info = XEPInfo(tmp_content, " ")
  72. if not info.interim:
  73. content = tmp_content
  74. break;
  75. else:
  76. content = xep.contentOfRevision(revs[len(revs)-1])
  77. (fd, name) = tempfile.mkstemp();
  78. handle = os.fdopen(fd, "w+b")
  79. handle.write(content)
  80. handle.close()
  81. return name;
  82. except:
  83. return False;