]> www.wagner.pp.ru Git - oss/ljdump.git/commitdiff
added command line arguments and some comments and warnings
authorSean M. Graham <grahams@milgrim.local>
Sun, 25 Jan 2009 20:44:30 +0000 (15:44 -0500)
committerSean M. Graham <grahams@milgrim.local>
Sun, 25 Jan 2009 20:44:30 +0000 (15:44 -0500)
convertdump.py

index 9a796cbbf873fa8c519a6f567f622503bc7626a2..106b274d796e8d918882249d95f4b2ea2de18686 100755 (executable)
@@ -3,6 +3,8 @@
 import xml.dom.minidom 
 import os
 import codecs
+import sys
+
 from time import strptime, strftime
 
 def getNodeText(doc, nodename):
@@ -38,13 +40,13 @@ def appendTextNode(doc, parent, nodename, value):
     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"))
@@ -63,6 +65,8 @@ def addEntryForId(outDoc, username, id):
     # 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:
@@ -128,54 +132,67 @@ def addCommentsForId(outDoc, entry, username, id):
         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)
 
-userDir = os.listdir("grahams")
+    highNum = -1
+    entryArray = []
 
-highNum = -1
-entryArray = []
+    # get the list of entries
+    for file in userDir:
+        if file.startswith("L-"):
+            entryNum = int(file.replace("L-",""))
 
-# get the list of entries
-for file in userDir:
-    if file.startswith("L-"):
-        entryNum = int(file.replace("L-",""))
+            entryArray.append(entryNum)
 
-        entryArray.append(entryNum)
+            if( highNum < entryNum ):
+                highNum = entryNum
 
-        if( highNum < entryNum ):
-            highNum = entryNum
+    entryArray.sort()
 
-entryArray.sort()
 
+    # Create the minidom document
+    outDoc = xml.dom.minidom.Document()
 
-# Create the minidom document
-outDoc = xml.dom.minidom.Document()
+    # Create the <livejournal> base element
+    ljElement = outDoc.createElement("livejournal")
+    outDoc.appendChild(ljElement)
 
-# Create the <livejournal> base element
-ljElement = outDoc.createElement("livejournal")
-outDoc.appendChild(ljElement)
+    entryLimit = 250
+    currentFileEntry = 0
 
-breakup = 250
-currentFileEntry = 0
+    # start processing entries
+    for entry in entryArray:
+        addEntryForId(outDoc, ljElement, username, entry)
 
-# start processing entries
-for entry in entryArray:
-    addEntryForId(outDoc, "grahams", entry)
+        currentFileEntry += 1
 
-    currentFileEntry += 1
+        if( currentFileEntry == entryLimit ):
 
-    if( currentFileEntry == breakup ):
+            f = open("%s - %s.xml" % (username, entry), "w")
+            tempXML = outDoc.toxml("UTF-8")
+            f.write(tempXML)
+            
+            currentFileEntry = 0
 
-        f = open("grahams - %s.xml" % entry, "w")
-        tempXML = outDoc.toxml("UTF-8")
-        f.write(tempXML)
-        
-        currentFileEntry = 0
+            # 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()
+if __name__ == "__main__":
+    main(sys.argv[1:])
 
-        # Create the <livejournal> base element
-        ljElement = outDoc.createElement("livejournal")
-        outDoc.appendChild(ljElement)