# Path: webapp/model.py
# class Song(SQLObject):
# class Songbook(SQLObject):
# class Visit(SQLObject):
#     class sqlmeta:
# class VisitIdentity(SQLObject):
# class Group(SQLObject):
#     class sqlmeta:
# class User(SQLObject):
#     class sqlmeta:
# class Permission(SQLObject):
#     def lookup_visit(cls, visit_key):
#     def _get_permissions(self):
#     def _set_password(self, cleartext_password):
#     def set_password_raw(self, password):
# def bootstrap_model(clean=False, user=None):
# def create_tables(drop_all=False):
# def create_default_user(user_name):


from webapp.model import Song, Songbook, hub
from posixpath import *
  import xml.etree.cElementTree as ET
  import xml.etree.ElementTree as ET
import xml.parsers.expat
import webapp.c_utilities as c
import turbogears
import glob
import sys
import os
import re
    categories = ''
    print 'MALFORMED:', path
  
  Song(title=c.fix_encoding(title), path=path, author=c.fix_encoding(author), 
      categories=c.fix_encoding(categories), content=c.fix_encoding(content), 
      copyright=c.fix_encoding(copyright))
  hub.commit() #commit song to database

# enter songbooks into database
for songbook in songbooklist:
  if songbook.endswith('.comment') or songbook.endswith('.comment.dat') or songbook.endswith('.comment.dir') or songbook.endswith('.bak'):
    continue  # .comment files are not songbooks
 
  print 'Songbook:', songbook

  path = songbook.replace('\\', '/')

  try:
    dom = ET.parse(path)

    if dom.find('title') != None:    #don't die if no title
      title = dom.find('title').text
    else:
      print 'NO TITLE:', path
      title = 'No title'

  except xml.parsers.expat.ExpatError:
    title = 'No title'
    print 'MALFORMED:', path


# Path: webapp/model.py
# class Song(SQLObject):
# class Songbook(SQLObject):
# class Visit(SQLObject):
#     class sqlmeta:
# class VisitIdentity(SQLObject):
# class Group(SQLObject):
#     class sqlmeta:
# class User(SQLObject):
#     class sqlmeta:
# class Permission(SQLObject):
#     def lookup_visit(cls, visit_key):
#     def _get_permissions(self):
#     def _set_password(self, cleartext_password):
#     def set_password_raw(self, password):
# def bootstrap_model(clean=False, user=None):
# def create_tables(drop_all=False):
# def create_default_user(user_name):


# Path: regen_db.py
from webapp.model import Song, Songbook, hub
from posixpath import *
  import xml.etree.cElementTree as ET
  import xml.etree.ElementTree as ET
import xml.parsers.expat
import webapp.c_utilities as c
import turbogears
import glob
import sys
import os
import re

    categories = ''
    print 'MALFORMED:', path
  
  Song(title=c.fix_encoding(title), path=path, author=c.fix_encoding(author), 
      categories=c.fix_encoding(categories), content=c.fix_encoding(content), 
      copyright=c.fix_encoding(copyright))
  hub.commit() #commit song to database

# enter songbooks into database
for songbook in songbooklist:
  if songbook.endswith('.comment') or songbook.endswith('.comment.dat') or songbook.endswith('.comment.dir') or songbook.endswith('.bak'):
    continue  # .comment files are not songbooks
 
  print 'Songbook:', songbook

  path = songbook.replace('\\', '/')

  try:
    dom = ET.parse(path)

    if dom.find('title') != None:    #don't die if no title
      title = dom.find('title').text
    else:
      print 'NO TITLE:', path
      title = 'No title'

  except xml.parsers.expat.ExpatError:
    title = 'No title'
    print 'MALFORMED:', path


  Songbook(title=c.fix_encoding(title), path=path)