libsaria: Remove library export and import

Using export / import functions for library updates can be a pain.  I
don't plan on changing the library file format any time soon, so I don't
need to keep this code around.
This commit is contained in:
Bryan Schumaker 2011-05-23 10:04:05 -04:00
parent ae2fc30da8
commit 913ee9f931
1 changed files with 0 additions and 111 deletions

View File

@ -2,7 +2,6 @@
import libsaria
from libsaria import path
from libsaria.sources import oldlibrary
from libsaria.sources import playlist
from libsaria import version
from libsaria import callbacks
@ -72,108 +71,11 @@ def encode_xspf(doc, node, id):
location = add_child(doc, track, "location")
add_text(doc, location, "file://%s" % 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 #
#########################
def decode_sources_v1_2(node):
for child in xml_children(node):
source = xml_child(child).data.strip()
print "Scanning source: %s" % source
libsaria.sources.new_source(source)
def decode_track_v1_2(node):
for track in xml_children(node):
attrs = xml_attrs(track)
name, path = decode_attr(track)
id = file_id(path)
set_attr(id, "count", int(attrs["count"]))
def decode_v1_2(node):
children = xml_children(node)
sources = None
tracks = None
for node in children:
name = node.nodeName
if name == "sources":
sources = node
elif name == "tracks":
tracks = node
decode_sources_v1_2(sources)
decode_track_v1_2(tracks)
#########################
# v1.3 Decode functions #
#########################
def decode_track_v1_3(node):
for track in xml_children(node):
attrs = xml_attrs(track)
name, path = decode_attr(track)
id = file_id(path)
like = attrs["like"]
if like == "True":
like = True
elif like == "False":
like = False
elif like == "None":
like = None
set_attr(id, "count", int(attrs["count"]))
set_attr(id, "like", like)
def decode_v1_3(node):
children = xml_children(node)
sources = None
tracks = None
for node in children:
name = node.nodeName
if name == "sources":
sources = node
elif name == "tracks":
tracks = node
decode_sources_v1_2(sources)
decode_track_v1_3(tracks)
#############################################
# Control will enter the export module here #
#############################################
def export():
doc = xml.new()
child = add_child(doc, doc, "library", {"version":vers})
sources = add_child(doc, child, "sources")
tracks = add_child(doc, child, "tracks")
for path in oldlibrary.get_locations():
encode_attr(doc, sources, "source", path)
for id in oldlibrary.walk():
encode_track(doc, tracks, id)
fout = open(lib_file, 'w')
fout.write(doc.toprettyxml())
fout.close()
print "Wrote library to: %s" % lib_file
def save_playlist(filepath):
file, ext = path.splitext(filepath)
if ext != ".xml":
@ -197,16 +99,3 @@ def import_xml(file):
child = xml.child(doc)
if child.nodeName == "playlist":
decode_xspf(child)
elif child.nodeName == "library":
import_library(child)
def import_library(child):
attrs = xml.attributes(child)
version = float(attrs.get("version", "1.1"))
print "Decoding library version: %s" % version
if version == 1.1:
decode_v1_1(child)
elif version == 1.2:
decode_v1_2(child)
elif version >= 1.3:
decode_v1_3(child)