Library backup
I can now backup the library to an xml file. This will be useful for library updates in the future. The plan is to eventually backport this feature to Ocarina 4.1 (To make the 4.1 -> 4.2 transition easier)
This commit is contained in:
parent
d35468ba19
commit
68bad792dc
|
@ -0,0 +1,54 @@
|
|||
# Bryan Schumaker (11/12/2010)
|
||||
|
||||
from libsaria import path
|
||||
from libsaria.collection import library
|
||||
import xm as xml
|
||||
|
||||
add_child = xml.add_child
|
||||
add_text = xml.add_text
|
||||
get_attrs = library.get_attrs
|
||||
lib_file = path.join(path.saria_dir(), "library.xml")
|
||||
|
||||
def encode_attr(doc, node, attr, value):
|
||||
child = add_child(doc, node, attr)
|
||||
add_text(doc, child, value)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def backup():
|
||||
doc = xml.new()
|
||||
child = add_child(doc, doc, "library")
|
||||
for id in library.walk():
|
||||
encode_track(doc, child, id)
|
||||
|
||||
fout = open(lib_file, 'w')
|
||||
fout.write(doc.toprettyxml())
|
||||
fout.close()
|
||||
print "Wrote library to: %s" % lib_file
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# Bryan Schumaker (11/12/2010)
|
||||
|
||||
import libsaria
|
||||
from libsaria import data
|
||||
from libsaria import collection
|
||||
from libsaria import backup
|
||||
library = libsaria.collection.library
|
||||
|
||||
library.load()
|
||||
backup.backup()
|
Loading…
Reference in New Issue