#!/usr/bin/python
+# Copyright 2009, Sean M. Graham (www.sean-graham.com)
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+# EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
import xml.dom.minidom
import os
import codecs
+import sys
+
from time import strptime, strftime
def getNodeText(doc, nodename):
parent.appendChild(element)
-def addEntryForId(outDoc, username, id):
+def addEntryForId(outDoc, element, username, id):
entryFile = open("%s/L-%s" % (username,id), "r")
inDoc = xml.dom.minidom.parse(entryFile)
# Create an entry element
entry = outDoc.createElement("entry")
- ljElement.appendChild(entry)
+ element.appendChild(entry)
# Create an itemid element
appendTextNode(outDoc, entry, "itemid", getNodeText(inDoc,"itemid"))
# Create an allowmask element (doesn't exist in pydump output if public)
maskText = getNodeText(inDoc, "allowmask")
+ # XXXSMG: consult L-1411 and L-976 for examples of security and
+ # allowmask use
if(maskText != ""):
appendTextNode(outDoc, entry, "allowmask", maskText)
else:
if(parentId != ""):
appendTextNode(outDoc, outComment, "parent_itemid", parentId)
+def main(argv):
+ username = ""
+ entryLimit = 250
+
+
+ if( len(argv) != 2 ):
+ print( "Usage: convertdump.py <username> <entrylimit>" )
+ return
+ else:
+ username = argv[0]
+ entryLimit = int(argv[1])
+ userDir = os.listdir(username)
+ highNum = -1
+ entryArray = []
-userDir = os.listdir("grahams")
+ # get the list of entries
+ for file in userDir:
+ if file.startswith("L-"):
+ entryNum = int(file.replace("L-",""))
-highNum = -1
-entryArray = []
+ entryArray.append(entryNum)
-# get the list of entries
-for file in userDir:
- if file.startswith("L-"):
- entryNum = int(file.replace("L-",""))
+ if( highNum < entryNum ):
+ highNum = entryNum
- entryArray.append(entryNum)
+ entryArray.sort()
- if( highNum < entryNum ):
- highNum = entryNum
-entryArray.sort()
+ # Create the minidom document
+ outDoc = xml.dom.minidom.Document()
+ # Create the <livejournal> base element
+ ljElement = outDoc.createElement("livejournal")
+ outDoc.appendChild(ljElement)
-# Create the minidom document
-outDoc = xml.dom.minidom.Document()
+ currentFileEntry = 0
-# Create the <livejournal> base element
-ljElement = outDoc.createElement("livejournal")
-outDoc.appendChild(ljElement)
+ # start processing entries
+ for entry in entryArray:
+ addEntryForId(outDoc, ljElement, username, entry)
-breakup = 250
-currentFileEntry = 0
+ currentFileEntry += 1
-# start processing entries
-for entry in entryArray:
- addEntryForId(outDoc, "grahams", entry)
+ if( currentFileEntry == entryLimit or entry == entryArray[-1] ):
- currentFileEntry += 1
+ f = open("%s - %s.xml" % (username, entry), "w")
+ tempXML = outDoc.toxml("UTF-8")
+ f.write(tempXML)
+
+ currentFileEntry = 0
- if( currentFileEntry == breakup ):
+ # Create the minidom document
+ outDoc = xml.dom.minidom.Document()
- f = open("grahams - %s.xml" % entry, "w")
- tempXML = outDoc.toxml("UTF-8")
- f.write(tempXML)
-
- currentFileEntry = 0
+ # Create the <livejournal> base element
+ ljElement = outDoc.createElement("livejournal")
+ outDoc.appendChild(ljElement)
- # Create the minidom document
- outDoc = xml.dom.minidom.Document()
+if __name__ == "__main__":
+ main(sys.argv[1:])
- # Create the <livejournal> base element
- ljElement = outDoc.createElement("livejournal")
- outDoc.appendChild(ljElement)