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.

dbupdate.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/env python
  2. # File: dbupdate.py
  3. # Version: 0.1
  4. # Description: a script for updating the XEP database
  5. # Last Modified: 2006-12-07
  6. # Author: Peter Saint-Andre (stpeter@jabber.org)
  7. # License: public domain
  8. # HowTo: ./dbupdate.py dbuser dbpw xepnum
  9. ## LICENSE ##
  10. #
  11. # Copyright (c) 1999 - 2010 XMPP Standards Foundation
  12. #
  13. # Permission is hereby granted, free of charge, to any person obtaining a copy
  14. # of this software and associated documentation files (the "Software"), to deal
  15. # in the Software without restriction, including without limitation the rights
  16. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. # copies of the Software, and to permit persons to whom the Software is
  18. # furnished to do so, subject to the following conditions:
  19. #
  20. # The above copyright notice and this permission notice shall be included in
  21. # all copies or substantial portions of the Software.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. # THE SOFTWARE.
  30. #
  31. ## END LICENSE ##
  32. # IMPORTS:
  33. #
  34. import glob
  35. import MySQLdb
  36. import os
  37. from select import select
  38. import socket
  39. from string import split,strip,join,find
  40. import sys
  41. import time
  42. from xml.dom.minidom import parse,parseString,Document
  43. def getText(nodelist):
  44. thisText = ""
  45. for node in nodelist:
  46. if node.nodeType == node.TEXT_NODE:
  47. thisText = thisText + node.data
  48. return thisText
  49. # get the seconds in the Unix era
  50. now = int(time.time())
  51. # READ IN ARGS:
  52. #
  53. # 1. XEP number
  54. # 2. database user
  55. # 3. database password
  56. dbuser = sys.argv[1];
  57. dbpw = sys.argv[2];
  58. xepnum = sys.argv[3];
  59. xepfile = 'xep-' + xepnum + '.xml'
  60. # PARSE XEP HEADERS:
  61. #
  62. # - title
  63. # - abstract
  64. # - version
  65. # - date
  66. # - initials
  67. # - remark
  68. thexep = parse(xepfile)
  69. xepNode = (thexep.getElementsByTagName("xep")[0])
  70. headerNode = (xepNode.getElementsByTagName("header")[0])
  71. titleNode = (headerNode.getElementsByTagName("title")[0])
  72. title = getText(titleNode.childNodes)
  73. abstractNode = (headerNode.getElementsByTagName("abstract")[0])
  74. abstract = getText(abstractNode.childNodes)
  75. statusNode = (headerNode.getElementsByTagName("status")[0])
  76. xepstatus = getText(statusNode.childNodes)
  77. typeNode = (headerNode.getElementsByTagName("type")[0])
  78. xeptype = getText(typeNode.childNodes)
  79. revNode = (headerNode.getElementsByTagName("revision")[0])
  80. versionNode = (revNode.getElementsByTagName("version")[0])
  81. version = getText(versionNode.childNodes)
  82. dateNode = (revNode.getElementsByTagName("date")[0])
  83. date = getText(dateNode.childNodes)
  84. initialsNode = (revNode.getElementsByTagName("initials")[0])
  85. initials = getText(initialsNode.childNodes)
  86. remNode = (revNode.getElementsByTagName("remark")[0])
  87. # could be <p> or <ul>
  88. testRemarkNode = remNode.firstChild.nodeName
  89. # print testRemarkNode
  90. if (testRemarkNode == "p"):
  91. remarkNode = (remNode.getElementsByTagName("p")[0])
  92. remark = getText(remarkNode.childNodes)
  93. else:
  94. remark = "[See revision history]"
  95. # what kind of action are we taking?
  96. xepflag = ""
  97. if (version == "0.1"):
  98. xepflag = "new"
  99. elif ((version == "1.0") & (xeptype == "Standards Track")):
  100. xepflag = "draft"
  101. elif ((version == "1.0") & (xeptype != "Standards Track")):
  102. xepflag = "active"
  103. elif (version == "2.0"):
  104. xepflag = "final"
  105. elif (xepstatus == "Retracted"):
  106. xepflag = "retract"
  107. elif (xepstatus == "Deferred"):
  108. xepflag = "defer"
  109. # UPDATE DATABASE:
  110. #
  111. # number is $xepnum
  112. # name is $title
  113. # type is $xeptype
  114. # status is $xepstatus
  115. # notes is "Version $version of XEP-$xepnum released $date."
  116. # version is $version
  117. # last_modified is $now
  118. # abstract is $abstract
  119. # changelog is "$remark ($initials)"
  120. db = MySQLdb.connect("localhost", dbuser, dbpw, "foundation")
  121. cursor = db.cursor()
  122. theNotes = "Version " + version + " of XEP-" + xepnum + " released " + date + "."
  123. theLog = remark + " (" + initials + ")"
  124. if xepflag == "new":
  125. theStatement = "INSERT INTO jeps VALUES ('" + str(xepnum) + "', '" + title + "', '" + xeptype + "', '" + xepstatus + "', '" + theNotes + "', '" + str(version) + "', '" + str(now) + "', '" + abstract + "', '" + theLog + "', '0', '5', 'Proposed', 'none');"
  126. cursor.execute(theStatement)
  127. else:
  128. theStatement = "UPDATE jeps SET name='" + title + "', type='" + xeptype + "', status='" + xepstatus + "', notes='" + theNotes + "', version='" + str(version) + "', last_modified='" + str(now) + "', abstract='" + abstract + "', changelog='" + theLog + "' WHERE number='" + str(xepnum) + "';"
  129. cursor.execute(theStatement)
  130. result = cursor.fetchall()
  131. # END