More updates

bzr-revno: 263
This commit is contained in:
Tim Bentley 2009-01-02 20:20:33 +00:00
parent 03b5ae79ef
commit 0385a13773
7 changed files with 129 additions and 165 deletions

View File

@ -0,0 +1,17 @@
"""
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
"""

View File

@ -1,9 +1,21 @@
# -*- coding: utf-8 -*-
"""
Module implementing AuthorsForm.
"""
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
"""
from openlp.core.resources import *
from PyQt4 import QtGui, QtCore
@ -25,7 +37,8 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog):
self.AuthorListView.setColumnCount(2)
self.AuthorListView.setColumnHidden(0, True)
self.AuthorListView.setColumnWidth(1, 300)
self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
self.authorid = 0 # this is the selected authorid for updates and deletes
self.songmanager = songmanager
@ -90,4 +103,13 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog):
"""
Slot documentation goes here.
"""
print "alv ic " + str(item)
cr = self.AuthorListView.currentRow()
id = int(self.AuthorListView.item(cr, 0).text())
author = self.songmanager.get_author(id)
print author
self.authorid = author[0]
self.DisplayEdit.setText(author[1])
self.FirstNameEdit.setText(author[2])
self.LastNameEdit.setText(author[3])

View File

@ -53,21 +53,9 @@ class EditSongForm(QWidget, Ui_EditSongDialog):
def load_song(self, songid):
self.songid = songid
song = self.songmanager.get_song(songid)
print song
#print song[2].encode('hex')
#print song
lyrics = song[2]
if lyrics.find("\x0a0d0a0d"):
print "new line"
lyrics = lyrics.replace("\x0a0d0a0d","\x23200a0d")
if lyrics.find("\xa0"):
print "Alt"
lyrics = lyrics.replace("\xa0","\x20")
print lyrics
self.TitleEditItem.setText(song[1])
self.LyricsTextEdit.setText(lyrics)
self.LyricsTextEdit.setText(song[2])
self.CopyrightEditItem.setText(song[3])
@pyqtSignature("")

View File

@ -1,7 +1,20 @@
# -*- coding: utf-8 -*-
"""
Module implementing SongBookForm.
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
"""
from openlp.core.resources import *

View File

@ -1,9 +1,21 @@
# -*- coding: utf-8 -*-
"""
Module implementing TopicsForm.
"""
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
"""
from openlp.core.resources import *
from PyQt4 import QtGui, QtCore

View File

@ -22,10 +22,9 @@ import datetime
import logging
import string
#from sqlalchemy import *
#from sqlalchemy.sql import select
#from sqlalchemy.orm import sessionmaker, mapper
import sqlite3
from sqlalchemy import *
from sqlalchemy.sql import select
from sqlalchemy.orm import sessionmaker, mapper
from openlp.plugins.bibles.lib.biblecommon import BibleCommon
from openlp.core.utils import ConfigHelper
@ -37,7 +36,7 @@ class BibleDBException(Exception):
class BibleInvalidDatabaseError(Exception):
pass
#metadata = MetaData()
metadata = MetaData()
#authors = Table('authors', metadata, autoload=True)
class SongDBImpl(BibleCommon):
@ -49,27 +48,22 @@ class SongDBImpl(BibleCommon):
self.songfile = os.path.join(songpath, "songs."+suffix)
log.debug( "Load Song on path %s", self.songfile)
#c = conn.cursor()
if btype == 'sqlite':
self.db = sqlite3.connect(self.songfile)
#self.db = create_engine("sqlite:///"+self.songfile, convert_unicode=False)
#elif btype == 'mysql':
#self.db = create_engine("mysql://tim:@192.168.0.100:3306/openlp_rsv_bible")
self.db = create_engine("sqlite:///"+self.songfile, convert_unicode=True)
elif btype == 'mysql':
self.db = create_engine("mysql://tim:@192.168.0.100:3306/openlp_rsv_bible")
else:
raise BibleInvalidDatabaseError("Database not mysql or sqlite")
#c = conn.cursor()
self.db.text_factory = str
#self.db.echo = True
#self.db.convert_unicode=False
#self.metadata = metaData()
#metadata.bind = self.db
#metadata.bind.echo = False
#self.Session = sessionmaker()
#self.Session.configure(bind=self.db)
#self.authors = Table('authors', metadata, autoload=True)
#self.settings = Table('settings', metadata, autoload=True)
#self.songauthors = Table('songauthors', metadata, autoload=True)
#self.songs = Table('songs', metadata, autoload=True)
self.db.echo = True
self.db.convert_unicode=False
metadata.bind = self.db
metadata.bind.echo = False
self.Session = sessionmaker()
self.Session.configure(bind=self.db)
self.authors = Table('authors', metadata, autoload=True)
self.settings = Table('settings', metadata, autoload=True)
self.songauthors = Table('songauthors', metadata, autoload=True)
self.songs = Table('songs', metadata, autoload=True)
def create_tables(self):
log.debug( "createTables")
@ -89,28 +83,7 @@ class SongDBImpl(BibleCommon):
versemeta = Verse(book_id=int(bookid), chapter=int(chap), verse=int(verse), text=(text))
session.add(versemeta)
session.commit()
def create_chapter(self, bookid, chap, textlist):
log.debug( "create_chapter %s,%s,%s", bookid, chap, textlist)
metadata.bind.echo = False
session = self.Session()
#s = text (""" select id FROM book where book.name == :b """)
#data = self.db.execute(s, b=bookname).fetchone()
#id = data[0] # id is first record in list.
#log.debug( "id = " , id
for v , t in textlist.iteritems():
versemeta = Verse(book_id=bookid, chapter=int(chap), verse=int(v), text=(t))
session.add(versemeta)
session.commit()
def create_book(self, bookid, bookname, bookabbrev):
log.debug( "create_book %s,%s,%s", bookid, bookname, bookabbrev)
metadata.bind.echo = False
session = self.Session()
bookmeta = Book(int(5), bookname, bookabbrev)
session.add(bookmeta)
session.commit()
def save_meta(self, key, value):
metadata.bind.echo = False
session = self.Session()
@ -127,38 +100,29 @@ class SongDBImpl(BibleCommon):
s = text (""" delete FROM meta where key == :k """)
self.db.execute(s, k=key)
def _load_testaments(self):
log.debug("load_testaments")
metadata.bind.echo = False
session = self.Session()
testmeta = ONTestament(name="Old Testament")
session.add(testmeta)
testmeta = ONTestament(name="New Testament")
session.add(testmeta)
testmeta = ONTestament(name="Apocrypha")
session.add(testmeta)
session.commit()
def get_song(self, songid):
log.debug( "get_song ")
#metadata.bind.echo = False
#s = text (""" select * FROM songs where songid = :c """)
s = " select * FROM songs where songid = " +str(songid)
return self.db.cursor().execute(s).fetchone()
metadata.bind.echo = True
s = text (""" select * FROM songs where songid = :c """)
return self.db.execute(s, c=songid).fetchone()
def get_authors(self):
log.debug( "get_authors ")
#metadata.bind.echo = False
#s = text (""" select * FROM authors order by authorname """)
s = """ select * FROM authors order by authorname """
return self.db.cursor().execute(s).fetchall()
metadata.bind.echo = False
s = text (""" select authorid, authorname FROM authors order by authorname """)
return self.db.execute(s).fetchall()
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()
def get_song_authors(self, song):
log.debug( "get_song_authors ")
#metadata.bind.echo = False
#s = text (""" select * FROM songauthors where songid = ;c """)
s = """ select * FROM songauthors where songid = ;c """
return self.db.cursor().execute(s, c=songid).fetchall()
metadata.bind.echo = False
s = text (""" select * FROM songauthors where songid = ;c """)
return self.db.execute(s, c=songid).fetchall()
def get_max_bible_book_verses(self, bookname, chapter):

View File

@ -57,77 +57,6 @@ class SongManager():
def process_dialog(self, dialogobject):
self.dialogobject = dialogobject
def register_HTTP_bible(self, biblename, biblesource, mode="lazy", proxyurl=None, proxyid=None, proxypass=None):
"""
Return a list of bibles from a given URL.
The selected Bible can then be registered and LazyLoaded into a database
"""
log.debug( "register_HTTP_bible %s,%s,%s,%s,%s", biblename, biblesource, proxyurl, proxyid, proxypass, mode)
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible
nhttp = BibleHTTPImpl()
nhttp.setBibleSource(biblesource)
self.bibleHTTPCache[biblename] = nhttp
nbible.save_meta("WEB", biblesource) # register a lazy loading interest
if proxyurl != None:
nbible.save_meta("proxy", proxyurl) # store the proxy URL
nhttp.setProxy(proxyurl)
if proxyid != None:
nbible.save_meta("proxyid", proxyid) # store the proxy userid
if proxypass != None:
nbible.save_meta("proxypass", proxypass) # store the proxy password
def register_CVS_file_bible(self, biblename, booksfile, versefile):
"""
Method to load a bible from a set of files into a database.
If the database exists it is deleted and the database is reloaded
from scratch.
"""
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later
bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database
bcsv.load_data(booksfile, versefile)
def register_OSIS_file_bible(self, biblename, osisfile):
"""
Method to load a bible from a osis xml file extracted from Sword bible viewer.
If the database exists it is deleted and the database is reloaded
from scratch.
"""
log.debug( "register_OSIS_file_bible %s , %s", biblename, osisfile)
if self._is_new_bible(biblename):
nbible = BibleDBImpl(self.biblePath, biblename, self.bibleSuffix) # Create new Bible
nbible.createTables() # Create Database
self.bibleDBCache[biblename] = nbible # cache the database for use later
bcsv = BibleOSISImpl(self.biblePath, nbible) # create the loader and pass in the database
bcsv.loadData(osisfile, self.dialogobject)
# def loadBible(self,biblename):
# """
# Downloads all the books of the bible
# and loads it into the database
# """
# log.debug( "loadBible %s", biblename)
# bookabbrev = ""
# for bookname in self.listOfBooks:
# cptrs = self.booksChapters[ self.booksOfBible[bookname]]
# log.debug( "book and chapter %s %s", bookname , self.booksChapters[ self.booksOfBible[bookname]] )
# for chptr in range(1 , int(cptrs)): # loop through all the chapters in book
# c = self.bibleDBCache[biblename].getBibleChapter(bookname, chptr) # check to see if book/chapter exists
# log.debug( "got chapter %s", c)
# if not c:
# bookid = self.booksOfBible[bookname] # convert to id ie Genesis --> 1 Revelation --> 73
# log.debug( "missing %s,%s", bookname, chptr)
# self._loadBook(biblename,bookid, bookname, bookabbrev)
# self._loadChapter(biblename,bookid, bookname, chptr)
def get_song(self, songid):
"""
Returns the details of a song
@ -136,10 +65,29 @@ class SongManager():
def get_authors(self):
"""
Returns a list of all the authos
Returns a list of all the authors
"""
return self.songDBCache.get_authors()
def get_author(self, authorid):
"""
Details of the Author
"""
return self.songDBCache.get_author(authorid)
def save_author(self, author_name, first_name, last_name):
"""
Details of the Author
"""
return self.songDBCache.get_author(authorid)
def delete_author(self, authorid):
"""
Details of the Author
"""
return self.songDBCache.get_author(authorid)
def get_song_authors(self, songid):
"""
Returns the details of a song