Backup sources and improvements

I already have a "dumb import" (retag all files based on the filepath)
so there is no point in storing extra attributes when I am only going to
find them again during importing.  Instead, we should only store the
information we need: filepath, score, and playcount.

Additionally, I now store the list of sources in the library backup.
This commit is contained in:
Bryan Schumaker 2010-11-30 23:08:30 -05:00
parent a99ae4dfb4
commit b9117993e1
1 changed files with 14 additions and 25 deletions

View File

@ -11,11 +11,14 @@ get_attrs = library.get_attrs
set_attr = library.set_attr
file2id = library.file_to_id
lib_file = "library"
vers = "%s.%s" % (libsaria.__major__, libsaria.__minor__)
if libsaria.__dev__ == True:
lib_file = lib_file + "-dev"
vers = vers + "-dev"
lib_file += ".xml"
lib_file = path.join(path.saria_dir(), lib_file)
def encode_attr(doc, node, attr, value):
child = add_child(doc, node, attr)
add_text(doc, child, value)
@ -27,28 +30,9 @@ def decode_attr(attr):
def encode_track(doc, node, id):
child = add_child(doc, node, "track")
(artist, album, title, filepath, score, count, genre, track, year, rate,
channel, seconds, sample, lenstr) = get_attrs(
id, "artist", "album", "title", "filepath", "score",
"count", "genre", "track", "year", "rate", "channel",
"seconds", "sample", "lenstr")
encode_attr(doc, child, "id", id)
encode_attr(doc, child, "artist", artist)
encode_attr(doc, child, "album", album)
encode_attr(doc, child, "title", title)
encode_attr(doc, child, "filepath", filepath)
encode_attr(doc, child, "score", score)
encode_attr(doc, child, "count", count)
encode_attr(doc, child, "genre", genre)
encode_attr(doc, child, "track", track)
encode_attr(doc, child, "year", year)
encode_attr(doc, child, "rate", rate)
encode_attr(doc, child, "channel", channel)
encode_attr(doc, child, "seconds", seconds)
encode_attr(doc, child, "sample", sample)
encode_attr(doc, child, "lenstr", lenstr)
filepath, score, count = get_attrs(id, "filepath", "score", "count")
child = add_child(doc, node, "track", {"score":score, "count":count})
add_text(doc, child, filepath)
def decode_track(node):
@ -62,10 +46,15 @@ def decode_track(node):
def backup():
doc = xml.new()
child = add_child(doc, doc, "library")
doc = xml.new()
child = add_child(doc, doc, "library", {"version":vers})
sources = add_child(doc, child, "sources")
tracks = add_child(doc, child, "tracks")
for source in library.get_sources():
encode_attr(doc, sources, "source", source)
for id in library.walk():
encode_track(doc, child, id)
encode_track(doc, tracks, id)
fout = open(lib_file, 'w')
fout.write(doc.toprettyxml())