forked from openlp/openlp
Removed unnecessary files.
bzr-revno: 285
This commit is contained in:
parent
11bede8fd8
commit
b7b594ac49
@ -21,7 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
import os, os.path
|
import os, os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from sqlalchemy.orm import asc, desc, like
|
from sqlalchemy import asc, desc
|
||||||
from openlp.plugins.songs.lib.models import init_models, metadata, session, \
|
from openlp.plugins.songs.lib.models import init_models, metadata, session, \
|
||||||
songs_table, Song, Author, Topic
|
songs_table, Song, Author, Topic
|
||||||
|
|
||||||
@ -45,17 +45,17 @@ class SongManager():
|
|||||||
self.config = config
|
self.config = config
|
||||||
log.debug( "Song Initialising")
|
log.debug( "Song Initialising")
|
||||||
self.db_url = u''
|
self.db_url = u''
|
||||||
db_type = self.config.get_db_type()
|
db_type = self.config.get_config(u'db type')
|
||||||
if db_type == u'sqlite':
|
if db_type == u'sqlite':
|
||||||
self.db_url = u'sqlite://' + self.config.get_data_path() + \
|
self.db_url = u'sqlite://' + self.config.get_data_path() + \
|
||||||
u'songs.sqlite'
|
u'/songs.sqlite'
|
||||||
else:
|
else:
|
||||||
self.db_url = self.config.get_db_type + 'u://' + \
|
self.db_url = db_type + 'u://' + \
|
||||||
self.config.get_db_username + u':' + \
|
self.config.get_config(u'db username') + u':' + \
|
||||||
self.config.get_db_password + u'@' + \
|
self.config.get_config(u'db password') + u'@' + \
|
||||||
self.config.get_db_hostname + u'/' + \
|
self.config.get_config(u'db hostname') + u'/' + \
|
||||||
self.config.get_db_database
|
self.config.get_config(u'db database')
|
||||||
ini_models(self.db_url)
|
init_models(self.db_url)
|
||||||
if not songs_table.exists():
|
if not songs_table.exists():
|
||||||
metadata.create_all()
|
metadata.create_all()
|
||||||
log.debug( "Song Initialised")
|
log.debug( "Song Initialised")
|
||||||
@ -81,11 +81,14 @@ class SongManager():
|
|||||||
"""
|
"""
|
||||||
return session.query(Song).filter(search_lyrics.like(u'%' + keywords + u'%'))
|
return session.query(Song).filter(search_lyrics.like(u'%' + keywords + u'%'))
|
||||||
|
|
||||||
def get_song(self, id):
|
def get_song(self, id=None):
|
||||||
"""
|
"""
|
||||||
Returns the details of a song
|
Returns the details of a song
|
||||||
"""
|
"""
|
||||||
return session.query(Song).get(id)
|
if id is None:
|
||||||
|
return Song()
|
||||||
|
else:
|
||||||
|
return session.query(Song).get(id)
|
||||||
|
|
||||||
def save_song(self, song):
|
def save_song(self, song):
|
||||||
"""
|
"""
|
@ -1,173 +0,0 @@
|
|||||||
"""
|
|
||||||
OpenLP - Open Source Lyrics Projection
|
|
||||||
Copyright (c) 2008 Raoul Snyman
|
|
||||||
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
|
||||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import datetime
|
|
||||||
import logging
|
|
||||||
import string
|
|
||||||
|
|
||||||
from sqlalchemy import *
|
|
||||||
from sqlalchemy.sql import select
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
|
||||||
|
|
||||||
from openlp.plugins.songs.lib.songtables import *
|
|
||||||
from openlp.plugins.songs.lib.songclasses import *
|
|
||||||
|
|
||||||
from openlp.core.utils import ConfigHelper
|
|
||||||
|
|
||||||
class SongDBException(Exception):
|
|
||||||
pass
|
|
||||||
class SongInvalidDatabaseError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class SongDBImpl():
|
|
||||||
global log
|
|
||||||
log=logging.getLogger("SongDBImpl")
|
|
||||||
log.info("SongDBImpl loaded")
|
|
||||||
def __init__(self, songpath , songname, suffix, btype = 'sqlite'):
|
|
||||||
# Connect to database
|
|
||||||
self.songfile = os.path.join(songpath, songname)
|
|
||||||
log.debug( "Load Song on path %s", self.songfile)
|
|
||||||
|
|
||||||
if btype == 'sqlite':
|
|
||||||
self.db = create_engine("sqlite:///"+self.songfile, encoding='utf-8' , convert_unicode=False, assert_unicode=False)
|
|
||||||
elif btype == 'mysql':
|
|
||||||
self.db = create_engine("mysql://tim:@192.168.0.100:3306/openlp_song")
|
|
||||||
else:
|
|
||||||
raise SongInvalidDatabaseError("Database not mysql or sqlite")
|
|
||||||
self.db.echo = True
|
|
||||||
metadata.bind = self.db
|
|
||||||
metadata.bind.echo = False
|
|
||||||
self.Session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
|
|
||||||
self.Session.configure(bind=self.db)
|
|
||||||
|
|
||||||
def save_author(self, author):
|
|
||||||
log.debug( "add_author %s,%s,%s", author.display_name, author.first_name, author.last_name)
|
|
||||||
metadata.bind.echo = True
|
|
||||||
session = self.Session()
|
|
||||||
session.save_or_update(author)
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
def save_meta(self, key, value):
|
|
||||||
metadata.bind.echo = False
|
|
||||||
session = self.Session()
|
|
||||||
bmeta= BibleMeta(key, value)
|
|
||||||
session.add(bmeta)
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
def get_meta(self, key):
|
|
||||||
s = text (""" select value FROM metadata where key == :k """)
|
|
||||||
return self.db.execute(s, k=key).fetchone()
|
|
||||||
|
|
||||||
def delete_meta(self, key):
|
|
||||||
metadata.bind.echo = False
|
|
||||||
s = text (""" delete FROM meta where key == :k """)
|
|
||||||
self.db.execute(s, k=key)
|
|
||||||
|
|
||||||
def get_song(self, songid):
|
|
||||||
log.debug( "get_song ")
|
|
||||||
# metadata.bind.echo = True
|
|
||||||
# s = text (""" select * FROM songs where songid = :c """)
|
|
||||||
# return self.db.execute(s, c=songid).fetchone()
|
|
||||||
metadata.bind.echo = False
|
|
||||||
session = self.Session()
|
|
||||||
return session.query(Song).get(songid)
|
|
||||||
|
|
||||||
def get_authors(self):
|
|
||||||
log.debug( "get_authors ")
|
|
||||||
metadata.bind.echo = False
|
|
||||||
session = self.Session()
|
|
||||||
return session.query(Author).order_by(Author.display_name).all()
|
|
||||||
|
|
||||||
def get_author(self, authorid):
|
|
||||||
log.debug( "get_author %s" , authorid)
|
|
||||||
# metadata.bind.echo = True
|
|
||||||
# s = text (""" select * FROM authors where authorid = :i """)
|
|
||||||
# return self.db.execute(s, i=authorid).fetchone()
|
|
||||||
session = self.Session()
|
|
||||||
return session.query(Author).get(authorid)
|
|
||||||
|
|
||||||
|
|
||||||
def delete_author(self, authorid):
|
|
||||||
log.debug( "delete_author %s" , authorid)
|
|
||||||
metadata.bind.echo = True
|
|
||||||
# s = text (""" delete FROM authors where authorid = :i """)
|
|
||||||
# return self.db.execute(s, i=authorid)
|
|
||||||
session = self.Session()
|
|
||||||
author = session.query(Author).get(authorid)
|
|
||||||
session.delete(author)
|
|
||||||
session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def update_author(self, authorid, author_name, first_name, last_name):
|
|
||||||
log.debug( "update_author %s,%s,%s,%s" , authorid, author_name, first_name, last_name)
|
|
||||||
metadata.bind.echo = True
|
|
||||||
s = text (""" update authors set authorname= :an ,first_name = :fn,last_name = :ln where authorid = :i """)
|
|
||||||
return self.db.execute(s, an=author_name, fn=first_name, ln=last_name, i=authorid)
|
|
||||||
|
|
||||||
def get_song_authors_for_author(self, authorid):
|
|
||||||
log.debug( "get_song_authors for author %s ", authorid)
|
|
||||||
metadata.bind.echo = False
|
|
||||||
s = text (""" select * FROM authors_songs where author_id = :c """)
|
|
||||||
return self.db.execute(s, c=authorid).fetchall()
|
|
||||||
|
|
||||||
def get_song_authors_for_song(self, songid):
|
|
||||||
log.debug( "get_song_authors for song %s ", songid)
|
|
||||||
metadata.bind.echo = False
|
|
||||||
s = text (""" select * FROM songauthors where songid = :c """)
|
|
||||||
return self.db.execute(s, c=songid).fetchall()
|
|
||||||
|
|
||||||
def get_song_from_lyrics(self,searchtext):
|
|
||||||
log.debug( "get_song_from_lyrics %s",searchtext)
|
|
||||||
metadata.bind.echo = False
|
|
||||||
searchtext = unicode("%"+searchtext+"%")
|
|
||||||
# s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.lyrics LIKE :t ORDER BY s.songtitle ASC """)
|
|
||||||
# log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
|
|
||||||
# return self.db.execute(s, t=searchtext).fetchall()
|
|
||||||
metadata.bind.echo = False
|
|
||||||
session = self.Session()
|
|
||||||
return session.query(Song).filter(Song.search_lyrics.like(searchtext)).order_by(Song.title).all()
|
|
||||||
|
|
||||||
def get_song_from_title(self,searchtext):
|
|
||||||
log.debug( "get_song_from_title %s",searchtext)
|
|
||||||
# metadata.bind.echo = False
|
|
||||||
searchtext = unicode("%"+searchtext+"%")
|
|
||||||
# s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.songtitle LIKE :t ORDER BY s.songtitle ASC """)
|
|
||||||
# log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
|
|
||||||
# return self.db.execute(s, t=searchtext).fetchall()
|
|
||||||
metadata.bind.echo = False
|
|
||||||
session = self.Session()
|
|
||||||
return session.query(Song).filter(Song.search_title.like(searchtext)).order_by(Song.title).all()
|
|
||||||
|
|
||||||
def get_song_from_author(self,searchtext):
|
|
||||||
log.debug( "get_song_from_author %s",searchtext)
|
|
||||||
metadata.bind.echo = False
|
|
||||||
searchtext = "%"+searchtext+"%"
|
|
||||||
s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE a.authorname LIKE :t ORDER BY s.songtitle ASC """)
|
|
||||||
log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
|
|
||||||
return self.db.execute(s, t=searchtext).fetchall()
|
|
||||||
|
|
||||||
|
|
||||||
def dump_songs(self):
|
|
||||||
log.debug( ".........Dumping Songs Database")
|
|
||||||
log.debug( "...............................Books ")
|
|
||||||
s = text (""" select * FROM authors """)
|
|
||||||
log.debug( self.db.execute(s).fetchall())
|
|
@ -1,52 +0,0 @@
|
|||||||
# -*- coding:iso-8859-1 -*-
|
|
||||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
||||||
"""
|
|
||||||
OpenLP - Open Source Lyrics Projection
|
|
||||||
Copyright (c) 2008 Raoul Snyman
|
|
||||||
Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
|
||||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from songxml import *
|
|
||||||
|
|
||||||
|
|
||||||
class SongFile(object):
|
|
||||||
"""Class for handling the song file"""
|
|
||||||
|
|
||||||
def __init__(self, fileUrl):
|
|
||||||
"""Initialize the song file
|
|
||||||
|
|
||||||
fileUrl -- full path and name to the song file
|
|
||||||
"""
|
|
||||||
self.filename = fileUrl
|
|
||||||
|
|
||||||
|
|
||||||
class SongFileVersion1(object):
|
|
||||||
"""Class for handling OpenLP 1.xx olp file
|
|
||||||
|
|
||||||
The SQLite file contains these tables:
|
|
||||||
authors(authorid, authorname) # unique author list
|
|
||||||
songauthors(authorid, songid) # m-to-m relation
|
|
||||||
songs(songid, songtitle, lyrics, copyrightinfo, settingsid) # unique song list
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, fileUrl):
|
|
||||||
"""Initialize the song file
|
|
||||||
|
|
||||||
fileUrl -- full path and name to the song file
|
|
||||||
"""
|
|
||||||
self.filename = fileUrl
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
# -*- coding:iso-8859-1 -*-
|
|
||||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
||||||
"""
|
|
||||||
OpenLP - Open Source Lyrics Projection
|
|
||||||
Copyright (c) 2008 Raoul Snyman
|
|
||||||
Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Carsten Tinggaard
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it under
|
|
||||||
the terms of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
|
||||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from songxml import *
|
|
||||||
from songfile import SongFile
|
|
||||||
|
|
||||||
class SongInterface(object):
|
|
||||||
"""Handle the interface functionality between UI, SongFile and Songs"""
|
|
||||||
|
|
||||||
def __init__(self, fileUrl):
|
|
||||||
"""Initialize with needed paths, files and forms
|
|
||||||
|
|
||||||
fileUrl -- full path and name to the song file
|
|
||||||
"""
|
|
||||||
self.songfile = SongFile(fileUrl)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user