forked from openlp/openlp
Media rather than Audio
This commit is contained in:
parent
a4bbb0ef28
commit
cb17897d47
@ -32,12 +32,6 @@ from sqlalchemy.orm import mapper, relation
|
||||
|
||||
from openlp.core.lib.db import BaseModel, init_db
|
||||
|
||||
class AudioFile(BaseModel):
|
||||
"""
|
||||
AudioFile model
|
||||
"""
|
||||
pass
|
||||
|
||||
class Author(BaseModel):
|
||||
"""
|
||||
Author model
|
||||
@ -52,6 +46,12 @@ class Book(BaseModel):
|
||||
return u'<Book id="%s" name="%s" publisher="%s" />' % (
|
||||
str(self.id), self.name, self.publisher)
|
||||
|
||||
class MediaFile(BaseModel):
|
||||
"""
|
||||
MediaFile model
|
||||
"""
|
||||
pass
|
||||
|
||||
class Song(BaseModel):
|
||||
"""
|
||||
Song model
|
||||
@ -73,12 +73,6 @@ def init_schema(url):
|
||||
"""
|
||||
session, metadata = init_db(url, auto_flush=False)
|
||||
|
||||
# Definition of the "audio_files" table
|
||||
audio_files_table = Table(u'audio_files', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
Column(u'file_name', types.Unicode(255), nullable=False)
|
||||
)
|
||||
|
||||
# Definition of the "authors" table
|
||||
authors_table = Table(u'authors', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
@ -87,6 +81,13 @@ def init_schema(url):
|
||||
Column(u'display_name', types.Unicode(255), nullable=False)
|
||||
)
|
||||
|
||||
# Definition of the "media_files" table
|
||||
media_files_table = Table(u'media_files', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
Column(u'file_name', types.Unicode(255), nullable=False),
|
||||
Column(u'type', types.Unicode(64), nullable=False, default=u'audio')
|
||||
)
|
||||
|
||||
# Definition of the "song_books" table
|
||||
song_books_table = Table(u'song_books', metadata,
|
||||
Column(u'id', types.Integer, primary_key=True),
|
||||
@ -118,14 +119,6 @@ def init_schema(url):
|
||||
Column(u'name', types.Unicode(128), nullable=False)
|
||||
)
|
||||
|
||||
# Definition of the "audio_files_songs" table
|
||||
audio_files_songs_table = Table(u'audio_files_songs', metadata,
|
||||
Column(u'audio_file_id', types.Integer,
|
||||
ForeignKey(u'audio_files.id'), primary_key=True),
|
||||
Column(u'song_id', types.Integer,
|
||||
ForeignKey(u'songs.id'), primary_key=True)
|
||||
)
|
||||
|
||||
# Definition of the "authors_songs" table
|
||||
authors_songs_table = Table(u'authors_songs', metadata,
|
||||
Column(u'author_id', types.Integer,
|
||||
@ -134,6 +127,14 @@ def init_schema(url):
|
||||
ForeignKey(u'songs.id'), primary_key=True)
|
||||
)
|
||||
|
||||
# Definition of the "media_files_songs" table
|
||||
media_files_songs_table = Table(u'media_files_songs', metadata,
|
||||
Column(u'media_file_id', types.Integer,
|
||||
ForeignKey(u'media_files.id'), primary_key=True),
|
||||
Column(u'song_id', types.Integer,
|
||||
ForeignKey(u'songs.id'), primary_key=True)
|
||||
)
|
||||
|
||||
# Definition of the "songs_topics" table
|
||||
songs_topics_table = Table(u'songs_topics', metadata,
|
||||
Column(u'song_id', types.Integer,
|
||||
@ -143,36 +144,36 @@ def init_schema(url):
|
||||
)
|
||||
|
||||
# Define table indexes
|
||||
Index(u'audio_files_id', audio_files_table.c.id)
|
||||
Index(u'authors_id', authors_table.c.id)
|
||||
Index(u'authors_display_name_id', authors_table.c.display_name,
|
||||
authors_table.c.id)
|
||||
Index(u'media_files_id', media_files_table.c.id)
|
||||
Index(u'song_books_id', song_books_table.c.id)
|
||||
Index(u'songs_id', songs_table.c.id)
|
||||
Index(u'topics_id', topics_table.c.id)
|
||||
Index(u'audio_files_songs_file', audio_files_songs_table.c.audio_file_id,
|
||||
audio_files_songs_table.c.song_id)
|
||||
Index(u'audio_files_songs_song', audio_files_songs_table.c.song_id,
|
||||
audio_files_songs_table.c.audio_file_id)
|
||||
Index(u'authors_songs_author', authors_songs_table.c.author_id,
|
||||
authors_songs_table.c.song_id)
|
||||
Index(u'authors_songs_song', authors_songs_table.c.song_id,
|
||||
authors_songs_table.c.author_id)
|
||||
Index(u'media_files_songs_file', media_files_songs_table.c.media_file_id,
|
||||
media_files_songs_table.c.song_id)
|
||||
Index(u'media_files_songs_song', media_files_songs_table.c.song_id,
|
||||
media_files_songs_table.c.media_file_id)
|
||||
Index(u'topics_song_topic', songs_topics_table.c.topic_id,
|
||||
songs_topics_table.c.song_id)
|
||||
Index(u'topics_song_song', songs_topics_table.c.song_id,
|
||||
songs_topics_table.c.topic_id)
|
||||
|
||||
mapper(AudioFile, audio_files_table)
|
||||
mapper(Author, authors_table)
|
||||
mapper(Book, song_books_table)
|
||||
mapper(MediaFile, media_files_table)
|
||||
mapper(Song, songs_table,
|
||||
properties={
|
||||
'audio_files': relation(AudioFile, backref='songs',
|
||||
secondary=audio_files_songs_table),
|
||||
'authors': relation(Author, backref='songs',
|
||||
secondary=authors_songs_table),
|
||||
'book': relation(Book, backref='songs'),
|
||||
'media_files': relation(MediaFile, backref='songs',
|
||||
secondary=media_files_songs_table),
|
||||
'topics': relation(Topic, backref='songs',
|
||||
secondary=songs_topics_table)
|
||||
})
|
||||
|
@ -34,16 +34,10 @@ from sqlalchemy.orm import class_mapper, mapper, relation, scoped_session, \
|
||||
from sqlalchemy.orm.exc import UnmappedClassError
|
||||
|
||||
from openlp.core.lib.db import BaseModel
|
||||
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic #, AudioFile
|
||||
from openlp.plugins.songs.lib.db import Author, Book, Song, Topic #, MediaFile
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class OldAudioFile(BaseModel):
|
||||
"""
|
||||
AudioFile model
|
||||
"""
|
||||
pass
|
||||
|
||||
class OldAuthor(BaseModel):
|
||||
"""
|
||||
Author model
|
||||
@ -56,6 +50,12 @@ class OldBook(BaseModel):
|
||||
"""
|
||||
pass
|
||||
|
||||
class OldMediaFile(BaseModel):
|
||||
"""
|
||||
MediaFile model
|
||||
"""
|
||||
pass
|
||||
|
||||
class OldSong(BaseModel):
|
||||
"""
|
||||
Song model
|
||||
@ -88,24 +88,24 @@ class OpenLPSongImport(object):
|
||||
source_meta = MetaData()
|
||||
source_meta.reflect(engine)
|
||||
self.source_session = scoped_session(sessionmaker(bind=engine))
|
||||
if u'audio_files' in source_meta.tables.keys():
|
||||
has_audio_files = True
|
||||
if u'media_files' in source_meta.tables.keys():
|
||||
has_media_files = True
|
||||
else:
|
||||
has_audio_files = False
|
||||
has_media_files = False
|
||||
source_authors_table = source_meta.tables[u'authors']
|
||||
source_song_books_table = source_meta.tables[u'song_books']
|
||||
source_songs_table = source_meta.tables[u'songs']
|
||||
source_topics_table = source_meta.tables[u'topics']
|
||||
source_authors_songs_table = source_meta.tables[u'authors_songs']
|
||||
source_songs_topics_table = source_meta.tables[u'songs_topics']
|
||||
if has_audio_files:
|
||||
source_audio_files_table = source_meta.tables[u'audio_files']
|
||||
source_audio_files_songs_table = \
|
||||
source_meta.tables[u'audio_files_songs']
|
||||
if has_media_files:
|
||||
source_media_files_table = source_meta.tables[u'media_files']
|
||||
source_media_files_songs_table = \
|
||||
source_meta.tables[u'media_files_songs']
|
||||
try:
|
||||
class_mapper(OldAudioFile)
|
||||
class_mapper(OldMediaFile)
|
||||
except UnmappedClassError:
|
||||
mapper(OldAudioFile, source_audio_files_table)
|
||||
mapper(OldMediaFile, source_media_files_table)
|
||||
song_props = {
|
||||
'authors': relation(OldAuthor, backref='songs',
|
||||
secondary=source_authors_songs_table),
|
||||
@ -113,9 +113,9 @@ class OpenLPSongImport(object):
|
||||
'topics': relation(OldTopic, backref='songs',
|
||||
secondary=source_songs_topics_table)
|
||||
}
|
||||
if has_audio_files:
|
||||
song_props['audio_files'] = relation(OldAudioFile, backref='songs',
|
||||
secondary=source_audio_files_songs_table)
|
||||
if has_media_files:
|
||||
song_props['media_files'] = relation(OldMediaFile, backref='songs',
|
||||
secondary=source_media_files_songs_table)
|
||||
try:
|
||||
class_mapper(OldAuthor)
|
||||
except UnmappedClassError:
|
||||
@ -137,7 +137,7 @@ class OpenLPSongImport(object):
|
||||
for song in source_songs:
|
||||
new_song = Song()
|
||||
new_song.title = song.title
|
||||
if has_audio_files:
|
||||
if has_media_files:
|
||||
new_song.alternate_title = song.alternate_title
|
||||
else:
|
||||
new_song.alternate_title = u''
|
||||
@ -185,14 +185,16 @@ class OpenLPSongImport(object):
|
||||
new_song.topics.append(existing_topic)
|
||||
else:
|
||||
new_song.topics.append(Topic.populate(name=topic.name))
|
||||
# if has_audio_files:
|
||||
# if song.audio_files:
|
||||
# for audio_file in song.audio_files:
|
||||
# existing_audio_file = \
|
||||
# self.master_manager.get_object_filtered(AudioFile,
|
||||
# AudioFile.file_name == audio_file.file_name)
|
||||
# if existing_audio_file:
|
||||
# new_song.audio_files.remove(audio_file)
|
||||
# new_song.audio_files.append(existing_audio_file)
|
||||
# if has_media_files:
|
||||
# if song.media_files:
|
||||
# for media_file in song.media_files:
|
||||
# existing_media_file = \
|
||||
# self.master_manager.get_object_filtered(MediaFile,
|
||||
# MediaFile.file_name == media_file.file_name)
|
||||
# if existing_media_file:
|
||||
# new_song.media_files.append(existing_media_file)
|
||||
# else:
|
||||
# new_song.media_files.append(MediaFile.populate(
|
||||
# file_name=media_file.file_name))
|
||||
self.master_manager.save_object(new_song)
|
||||
engine.dispose()
|
||||
|
Loading…
Reference in New Issue
Block a user