More reformatting and comments

This commit is contained in:
Bryan Schumaker 2010-12-18 14:49:35 -05:00
parent c49a39ad46
commit c08655c1fa
1 changed files with 27 additions and 20 deletions

View File

@ -21,15 +21,18 @@ xml_children = xml.children
xml_child = xml.child
xml_attrs = xml.attributes
def encode_attr(doc, node, attr, value):
child = add_child(doc, node, attr)
add_text(doc, child, value)
#######################################
# Generic encode and decode functions #
#######################################
def decode_attr(attr):
child = xml.child(attr)
return (attr.nodeName, child.data.strip())
def encode_attr(doc, node, attr, value):
child = add_child(doc, node, attr)
add_text(doc, child, value)
def encode_track(doc, node, id):
filepath, like, count = get_attrs(id, "filepath", "like", "count")
if (like == None) and (count == 0):
@ -38,6 +41,23 @@ def encode_track(doc, node, id):
add_text(doc, child, filepath)
#########################
# v1.1 Decode functions #
#########################
def decode_track_v1_1(node):
track = dict()
for child in xml_children(node):
key, value = decode_attr(child)
track[key] = value
id = file_id(track["filepath"])
set_attr(id, "count", int(track["count"]))
def decode_v1_1(node):
for track in xml_children(node):
decode_track_v1_1(track)
#########################
# v1.2 Decode functions #
#########################
@ -69,22 +89,9 @@ def decode_v1_2(node):
decode_track_v1_2(tracks)
#########################
# v1.1 Decode functions #
#########################
def decode_track_v1_1(node):
track = dict()
for child in xml_children(node):
key, value = decode_attr(child)
track[key] = value
id = file_id(track["filepath"])
set_attr(id, "count", int(track["count"]))
def decode_v1_1(node):
for track in xml_children(node):
decode_track_v1_1(track)
#############################################
# Control will enter the export module here #
#############################################
def backup():
doc = xml.new()