def import_guest_xml(self, filename, picturepath): parser = GuestElementParser() parser.parse_file(filename) self.insert_guest_data(parser.main_row) firstname = parser.main_row['firstname'] lastname = parser.main_row['lastname'] guestid = self._get_guestid(firstname, lastname) for appearance in parser.appearances: appearance = datefromstring(appearance) m3u = self._wtprn_file(appearance, 'm3u') self.insert_new_appearance(guestid, m3u) for work in parser.works: self.insert_new_work(guestid, work) for picture in parser.pictures: self.insert_new_picture(guestid, dict(filename=picture['filename'])) filename = picturepath / picture['filename'] pfile = filename.open('w') pfile.write(picture['data']) pfile.close()
dbfile = 'test.db' if os.environ.has_key('UTDBFILE'): dbfile = os.environ['UTDBFILE'] conn = Connection(dbname=dbfile, autocommit=True, encoding='ascii') cursor = conn.stmtcursor() cursor.set_table('guests') picturepath = path(dbfile).dirname() g = Guests(conn) x = g.export_guest_xml(12, picturepath) from StringIO import StringIO xf = StringIO() data = x.toxml('utf-8') xf.write(data) xf.seek(0) gep = GuestElementParser() gep.parse_file(xf) # using this to make the html page for kma from utdoc import AllGuestsDoc # we need a fake app class to get the # doc object to work correctly class FakeApp(object): def __init__(self, conn): self.guests = Guests(conn) self.datadir = os.path.dirname(dbfile) def makedoc(): app = FakeApp(conn) guests = app.guests.get_guest_rows()