mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
parent
dd33e8da14
commit
a08689e8c0
@ -14,10 +14,9 @@ import getpass
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pony.orm import db_session
|
|
||||||
from pony.orm import ObjectNotFound
|
from pony.orm import ObjectNotFound
|
||||||
|
|
||||||
from .db import Folder, User
|
from .db import Folder, User, db_session
|
||||||
from .managers.folder import FolderManager
|
from .managers.folder import FolderManager
|
||||||
from .managers.user import UserManager
|
from .managers.user import UserManager
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
|
@ -17,6 +17,7 @@ from pony.orm import Database, Required, Optional, Set, PrimaryKey, LongStr
|
|||||||
from pony.orm import ObjectNotFound
|
from pony.orm import ObjectNotFound
|
||||||
from pony.orm import buffer
|
from pony.orm import buffer
|
||||||
from pony.orm import min, max, avg, sum, exists
|
from pony.orm import min, max, avg, sum, exists
|
||||||
|
from pony.orm import db_session as pony_session
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from .py23 import dict, strtype
|
from .py23 import dict, strtype
|
||||||
@ -469,6 +470,26 @@ class Playlist(db.Entity):
|
|||||||
|
|
||||||
self.tracks = ','.join(t for t in tracks if t)
|
self.tracks = ','.join(t for t in tracks if t)
|
||||||
|
|
||||||
|
class DBSessionContextWrapper(object):
|
||||||
|
def __ensure_sqlite_case_insensitive_like(self):
|
||||||
|
if db.provider.dialect == 'SQLite':
|
||||||
|
db.execute('PRAGMA case_sensitive_like = OFF')
|
||||||
|
|
||||||
|
def __call__(self, func, *args, **kwargs):
|
||||||
|
def new_func(*args, **kwargs):
|
||||||
|
self.__ensure_sqlite_case_insensitive_like()
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return pony_session(new_func, *args, **kwargs)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
pony_session.__enter__()
|
||||||
|
self.__ensure_sqlite_case_insensitive_like()
|
||||||
|
|
||||||
|
def __exit__(self, *args, **kwargs):
|
||||||
|
pony_session.__exit__(*args, **kwargs)
|
||||||
|
|
||||||
|
db_session = DBSessionContextWrapper()
|
||||||
|
|
||||||
def parse_uri(database_uri):
|
def parse_uri(database_uri):
|
||||||
if not isinstance(database_uri, strtype):
|
if not isinstance(database_uri, strtype):
|
||||||
raise TypeError('Expecting a string')
|
raise TypeError('Expecting a string')
|
||||||
|
@ -12,12 +12,11 @@ import mimetypes
|
|||||||
import mutagen
|
import mutagen
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from .covers import find_cover_in_folder
|
from .covers import find_cover_in_folder
|
||||||
from .db import Folder, Artist, Album, Track, User
|
from .db import Folder, Artist, Album, Track, User
|
||||||
from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
|
from .db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
|
||||||
from .db import RatingFolder, RatingTrack
|
from .db import RatingFolder, RatingTrack
|
||||||
|
from .db import db_session
|
||||||
from .py23 import strtype
|
from .py23 import strtype
|
||||||
|
|
||||||
class StatsDetails(object):
|
class StatsDetails(object):
|
||||||
|
@ -11,13 +11,12 @@ import logging
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
from pony.orm import db_session
|
|
||||||
from signal import signal, SIGTERM, SIGINT
|
from signal import signal, SIGTERM, SIGINT
|
||||||
from threading import Thread, Condition, Timer
|
from threading import Thread, Condition, Timer
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import PatternMatchingEventHandler
|
from watchdog.events import PatternMatchingEventHandler
|
||||||
|
|
||||||
from .db import init_database, release_database, Folder
|
from .db import init_database, release_database, db_session, Folder
|
||||||
from .py23 import dict
|
from .py23 import dict
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
|
|
||||||
|
@ -12,10 +12,9 @@ import mimetypes
|
|||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from os import makedirs, path
|
from os import makedirs, path
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from .config import IniConfig
|
from .config import IniConfig
|
||||||
from .db import init_database
|
from .db import init_database, db_session
|
||||||
|
|
||||||
def create_application(config = None):
|
def create_application(config = None):
|
||||||
global app
|
global app
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, Artist, Album, Track, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track
|
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, Artist, Album, Track, User, ClientPrefs, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track, User, ClientPrefs
|
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -12,9 +12,8 @@ import time
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track
|
from supysonic.db import Folder, Artist, Album, Track, db_session
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -13,9 +13,8 @@ import uuid
|
|||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track
|
from supysonic.db import Folder, Artist, Album, Track, db_session
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, Artist, Album, Track, Playlist, User, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track, Playlist, User
|
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pony.orm import db_session, commit
|
from pony.orm import commit
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track
|
from supysonic.db import Folder, Artist, Album, Track, db_session
|
||||||
|
|
||||||
from .apitestbase import ApiTestBase
|
from .apitestbase import ApiTestBase
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, Track, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder, Track
|
|
||||||
from supysonic.managers.folder import FolderManager
|
from supysonic.managers.folder import FolderManager
|
||||||
from supysonic.scanner import Scanner
|
from supysonic.scanner import Scanner
|
||||||
|
|
||||||
|
@ -15,14 +15,13 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
try: # Don't use io.StringIO on py2, it only accepts unicode and the CLI spits strs
|
try: # Don't use io.StringIO on py2, it only accepts unicode and the CLI spits strs
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from supysonic.db import Folder, User, init_database, release_database
|
from supysonic.db import Folder, User, init_database, release_database, db_session
|
||||||
from supysonic.cli import SupysonicCLI
|
from supysonic.cli import SupysonicCLI
|
||||||
|
|
||||||
from ..testbase import TestConfig
|
from ..testbase import TestConfig
|
||||||
|
@ -13,10 +13,10 @@ import unittest
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from supysonic import db
|
from supysonic import db
|
||||||
|
|
||||||
|
db_session = db.db_session
|
||||||
date_regex = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$')
|
date_regex = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$')
|
||||||
|
|
||||||
class DbTestCase(unittest.TestCase):
|
class DbTestCase(unittest.TestCase):
|
||||||
|
@ -15,12 +15,14 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pony.orm import db_session, commit
|
from pony.orm import commit
|
||||||
|
|
||||||
from supysonic import db
|
from supysonic import db
|
||||||
from supysonic.managers.folder import FolderManager
|
from supysonic.managers.folder import FolderManager
|
||||||
from supysonic.scanner import Scanner
|
from supysonic.scanner import Scanner
|
||||||
|
|
||||||
|
db_session = db.db_session
|
||||||
|
|
||||||
class ScannerTestCase(unittest.TestCase):
|
class ScannerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
db.init_database('sqlite:', True)
|
db.init_database('sqlite:', True)
|
||||||
|
@ -18,10 +18,9 @@ import unittest
|
|||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from pony.orm import db_session
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from supysonic.db import init_database, release_database, Track, Artist
|
from supysonic.db import init_database, release_database, db_session, Track, Artist
|
||||||
from supysonic.managers.folder import FolderManager
|
from supysonic.managers.folder import FolderManager
|
||||||
from supysonic.watcher import SupysonicWatcher
|
from supysonic.watcher import SupysonicWatcher
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder
|
|
||||||
|
|
||||||
from .frontendtestbase import FrontendTestBase
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
|
@ -11,9 +11,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import User, db_session
|
||||||
|
|
||||||
from supysonic.db import User
|
|
||||||
|
|
||||||
from .frontendtestbase import FrontendTestBase
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import Folder, Artist, Album, Track, Playlist, User, db_session
|
||||||
|
|
||||||
from supysonic.db import Folder, Artist, Album, Track, Playlist, User
|
|
||||||
|
|
||||||
from .frontendtestbase import FrontendTestBase
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
|
@ -11,9 +11,8 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from flask import escape
|
from flask import escape
|
||||||
from pony.orm import db_session
|
|
||||||
|
|
||||||
from supysonic.db import User, ClientPrefs
|
from supysonic.db import User, ClientPrefs, db_session
|
||||||
|
|
||||||
from .frontendtestbase import FrontendTestBase
|
from .frontendtestbase import FrontendTestBase
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import init_database, release_database, db_session
|
||||||
|
|
||||||
from supysonic.db import init_database, release_database
|
|
||||||
from supysonic.db import Folder
|
from supysonic.db import Folder
|
||||||
from supysonic.managers.folder import FolderManager
|
from supysonic.managers.folder import FolderManager
|
||||||
from supysonic.scanner import Scanner
|
from supysonic.scanner import Scanner
|
||||||
|
@ -18,7 +18,9 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session, ObjectNotFound
|
from pony.orm import ObjectNotFound
|
||||||
|
|
||||||
|
db_session = db.db_session
|
||||||
|
|
||||||
class FolderManagerTestCase(unittest.TestCase):
|
class FolderManagerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -17,9 +17,11 @@ import io
|
|||||||
import unittest
|
import unittest
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pony.orm import db_session, commit
|
from pony.orm import commit
|
||||||
from pony.orm import ObjectNotFound
|
from pony.orm import ObjectNotFound
|
||||||
|
|
||||||
|
db_session = db.db_session
|
||||||
|
|
||||||
class UserManagerTestCase(unittest.TestCase):
|
class UserManagerTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create an empty sqlite database in memory
|
# Create an empty sqlite database in memory
|
||||||
|
@ -14,9 +14,7 @@ import shutil
|
|||||||
import unittest
|
import unittest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from pony.orm import db_session
|
from supysonic.db import init_database, release_database, db_session
|
||||||
|
|
||||||
from supysonic.db import init_database, release_database
|
|
||||||
from supysonic.config import DefaultConfig
|
from supysonic.config import DefaultConfig
|
||||||
from supysonic.managers.user import UserManager
|
from supysonic.managers.user import UserManager
|
||||||
from supysonic.web import create_application
|
from supysonic.web import create_application
|
||||||
|
Loading…
Reference in New Issue
Block a user