Updated eula, new license and updated Hatenatools to the newest version. preparing to add profiles
This commit is contained in:
1 parent
92177ddfb0
commit
23e198ccf0
22 files changed
+1479
-815
No files matched your search
+87
-35
@@ -1,6 +1,18 @@
|
||||
#UGO.py by pbsds
|
||||
#AGPL3 licensed
|
||||
#
|
||||
#This class reads and writes UGO files.
|
||||
#cal also export and import it in the xml format
|
||||
#Extended functionality added by PPM.py from http://pbsds.net/projects/ppm
|
||||
#It can also export and import it in a xml format
|
||||
#Extended functionality added by PPM.py
|
||||
#
|
||||
#Credits:
|
||||
#
|
||||
# -Jsafive for supplying .ugo files
|
||||
#
|
||||
#Note:
|
||||
# The current implentation can possibly mess up the files stored in Section #2, but will do for most needs
|
||||
# Next version will probably bring a big change in the ugoxml format
|
||||
#
|
||||
import sys, os
|
||||
from base64 import b64encode, b64decode
|
||||
import xml.etree.ElementTree as ET
|
||||
@@ -10,7 +22,6 @@ try:
|
||||
HasPPM = True
|
||||
except ImportError:
|
||||
HasPPM = False
|
||||
|
||||
|
||||
#helpers:
|
||||
def AscDec(ascii, LittleEndian=False):#Converts a ascii string into a decimal
|
||||
@@ -39,7 +50,7 @@ def DecAsc(dec, length=None, LittleEndian=False):#Converts a decimal into an asc
|
||||
return "".join(map(chr, out))
|
||||
def zipalign(length, r=4):
|
||||
return length + (4 - length % r) if length % r else length
|
||||
def indentXML(elem, level=0):#borrowed from: http://effbot.org/zone/element-lib.htm#prettyprint
|
||||
def indentXML(elem, level=0):#"borrowed" from: http://effbot.org/zone/element-lib.htm#prettyprint
|
||||
i = "\n" + level*"\t"
|
||||
if len(elem):
|
||||
if not elem.text or not elem.text.strip():
|
||||
@@ -97,8 +108,13 @@ class UGO:
|
||||
if Sections >= 2:
|
||||
ExtraData = data[zipalign(headerlength+self.TableLength) : zipalign(headerlength+self.TableLength)+self.ExtraLength]
|
||||
|
||||
#Read data:
|
||||
#Parse data:
|
||||
self.Items = []
|
||||
|
||||
#todo: implement this:
|
||||
self.Files = []#[i] = (filename, filecontent)
|
||||
#see todo.txt
|
||||
|
||||
pos = 0#Extra Data position
|
||||
tmbcount = 1#used if HasPPM is False
|
||||
ntftcount = 1#used if no label
|
||||
@@ -120,7 +136,7 @@ class UGO:
|
||||
self.Items.append(("topscreen text", labels, num))
|
||||
continue
|
||||
elif type == 2:#catogories(like "reccomended" and "new flipnotes" and "most popular")
|
||||
#this one may change greatly depending on what layout is set in type==0
|
||||
#this one may visually change greatly depending on what layout is set in type==0
|
||||
|
||||
link = i[1]
|
||||
label = b64decode(i[2]).decode("UTF-16LE")
|
||||
@@ -128,8 +144,12 @@ class UGO:
|
||||
|
||||
self.Items.append(("category", link, label, selected))
|
||||
continue
|
||||
elif type == 3:#POST button? "Post Flipnote"
|
||||
pass
|
||||
elif type == 3:#POST button/link to POST form. "Post Flipnote" uses this
|
||||
link = i[1]
|
||||
label = b64decode(i[2]).decode("UTF-16LE")
|
||||
|
||||
self.Items.append(("post", link, label))
|
||||
continue
|
||||
elif type == 4:#Button
|
||||
link = i[1]
|
||||
trait = int(i[2])
|
||||
@@ -250,9 +270,13 @@ class UGO:
|
||||
selected = str(1*selected)
|
||||
|
||||
TableOfContents.append("\t".join(("2", link, label, selected)))
|
||||
elif i[0] == "post":#not yet implented
|
||||
pass
|
||||
elif i[0] == "button":
|
||||
elif i[0] == "post":#3
|
||||
link, label = i[1:]
|
||||
|
||||
label = b64encode(label.encode("UTF-16LE"))
|
||||
|
||||
TableOfContents.append("\t".join(("3", link, label)))
|
||||
elif i[0] == "button":#4
|
||||
trait, label, link, other, file = i[1:]
|
||||
|
||||
trait = str(trait)
|
||||
@@ -297,7 +321,7 @@ class UGO:
|
||||
|
||||
for i in self.Items:
|
||||
if i[0] == "unknown":
|
||||
elem = ET.SubElement(ugo_xml, "unknown", type=i[1][0])
|
||||
elem = ET.SubElement(ugo_xml, "raw", type=i[1][0])
|
||||
for value in i[1][1:]:
|
||||
ET.SubElement(elem, "value").text = value
|
||||
continue
|
||||
@@ -323,7 +347,11 @@ class UGO:
|
||||
ET.SubElement(elem, "address").text = link
|
||||
ET.SubElement(elem, "selected").text = str(selected).lower()
|
||||
elif i[0] == "post":#3
|
||||
pass#not yet implented/parsed
|
||||
elem = ET.SubElement(ugo_xml, "post")
|
||||
link, label = i[1:]
|
||||
|
||||
ET.SubElement(elem, "label").text = label
|
||||
ET.SubElement(elem, "address").text = link
|
||||
elif i[0] == "button":#4
|
||||
elem = ET.SubElement(ugo_xml, "button")
|
||||
trait, label, link, other, file = i[1:]
|
||||
@@ -361,9 +389,9 @@ class UGO:
|
||||
|
||||
Items = []
|
||||
for elem in ugo_xml:
|
||||
if elem.tag == "unknown":
|
||||
if elem.tag == "raw":
|
||||
if "type" not in elem.attrib:
|
||||
if not silent: print "Invalid formatting. <unknown> without \"type\" attribute"
|
||||
if not silent: print "Invalid formatting. <raw> without \"type\" attribute"
|
||||
return False
|
||||
values = [elem.attrib["type"]]
|
||||
for value in elem:
|
||||
@@ -438,8 +466,27 @@ class UGO:
|
||||
selected = value.text[0].lower() in "t1"
|
||||
|
||||
Items.append(("category", link, label, selected))
|
||||
elif elem.tag == "post":#3 not yet implented
|
||||
pass
|
||||
elif elem.tag == "post":#3
|
||||
label = None
|
||||
link = None
|
||||
|
||||
for value in elem:
|
||||
if value.tag == "label":
|
||||
if isinstance(label, str):
|
||||
if not silent: print "Invalid formatting. Multible <label> within <post>"
|
||||
return False
|
||||
label = value.text if value.text else ""
|
||||
elif value.tag == "address":
|
||||
if isinstance(link, str):
|
||||
if not silent: print "Invalid formatting. Multible <address> within <post>"
|
||||
return False
|
||||
link = value.text if value.text else ""
|
||||
|
||||
if None in (link, label):
|
||||
if not silent: print "Invalid formatting. <button> lacks either a <address> or <label>"
|
||||
return False
|
||||
|
||||
Items.append(("post", link, label))
|
||||
elif elem.tag == "button":#4
|
||||
trait = None#todo: add names
|
||||
label = None
|
||||
@@ -504,12 +551,12 @@ class UGO:
|
||||
if __name__ == "__main__":
|
||||
print " == UGO.py =="
|
||||
print " == by pbsds =="
|
||||
print " == v0.90 =="
|
||||
print " == v0.92 =="
|
||||
print
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage:"
|
||||
print " UGO.py <mode> <input> [<output> [<foldername>]]"
|
||||
print " UGO.py [<mode>] <input> [<output> [<foldername>]]"
|
||||
print ""
|
||||
print " <Mode>:"
|
||||
print " -d: Converts the UGO file in <input> to a UGOXML file with the same"
|
||||
@@ -519,12 +566,28 @@ if __name__ == "__main__":
|
||||
print " <foldername> is relative to the XML."
|
||||
print " -e: Converts the UGOXML file in <input> to a UGO file with the same"
|
||||
print " name, unless <output> is specified."
|
||||
print " If mode is not specified, it will try to find out for itself"
|
||||
sys.exit()
|
||||
|
||||
mode = sys.argv[1]
|
||||
if mode not in ("-d", "-e"):
|
||||
print "Invalid <mode> given"
|
||||
sys.exit()
|
||||
if os.path.exists(mode):#the mode is actually the file
|
||||
f = open(mode, "rb")
|
||||
magic = f.read(4)
|
||||
f.close()
|
||||
|
||||
if magic == "UGAR":
|
||||
mode = "-d"
|
||||
print "No mode specified. UGO -> UGOXML chosen"
|
||||
else:
|
||||
mode = "-e"
|
||||
print "No mode specified. UGOXML -> UGO chosen"
|
||||
|
||||
sys.argv.insert(1, mode)
|
||||
else:
|
||||
print "Invalid <mode> given!"
|
||||
sys.exit()
|
||||
|
||||
if mode == "-d":
|
||||
input = sys.argv[2]
|
||||
output = sys.argv[3] if len(sys.argv) >= 4 else sys.argv[2]+"xml"
|
||||
@@ -549,7 +612,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
ugo = UGO().ReadXML(input, False)
|
||||
except EL.ParseError:
|
||||
print "Error!\nThe given file is not in the XML format"
|
||||
print "Error!\nThe given file is not in the XML format!"
|
||||
ugo = False
|
||||
if not ugo:
|
||||
#it prints sufficient errormessages
|
||||
@@ -559,15 +622,4 @@ if __name__ == "__main__":
|
||||
|
||||
print "Writing UGO..."
|
||||
ugo.WriteFile(output)
|
||||
print "Done"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print "Done"
|
||||
Reference in new issue
Block a user
