def reset(cls): if not DatabaseManager.reset('main', db, 'invalid-schema'): # Unable to reset database return False # Build migration router router = cls._build_router() if not router: return False # Run migrations router.run() # Log message to channel menu from plugin.managers.message import MessageManager from plugin.models import Message MessageManager.get.from_message( logging.WARNING, message="Plugin database has been reset due to schema corruption", description="Your corrupted database is available at: " "\"Plug-in Support\\Data\\com.plexapp.plugins.Stats\\Backups\\main.bgr\"", code=Message.Code.DatabaseSchemaCorruptionReset) return True
def flush(self): with elapsed.clock(SyncStateTrakt, 'flush:collections'): # Flush trakt collections to disk self.cache.collections.flush() with elapsed.clock(SyncStateTrakt, 'flush:stores'): # Flush trakt stores to disk for key, store in self.cache.stores.items(): log.debug('[%-38s] Flushing collection...', '/'.join(key)) store.flush() # Store backup of trakt data group = os.path.join('trakt', str(self.task.account.id)) BackupManager.database.backup(group, DatabaseManager.cache('trakt'), self.task.id, { 'account': { 'id': self.task.account.id, 'name': self.task.account.name, 'trakt': { 'username': self.task.account.trakt.username } } })
def reset(cls): if not DatabaseManager.reset('main', db, 'invalid-schema'): # Unable to reset database return False # Build migration router router = cls._build_router() if not router: return False # Run migrations router.run() # Log message to channel menu from plugin.managers.message import MessageManager from plugin.models import Message MessageManager.get.from_message(logging.WARNING, message="Plugin database has been reset due to schema corruption", description="Your corrupted database is available at: " "\"Plug-in Support\\Data\\com.plexapp.plugins.trakttv\\Backups\\main.bgr\"", code=Message.Code.DatabaseSchemaCorruptionReset ) return True
def _construct(key, serializer=DEFAULT_SERIALIZER): # Parse `key` fragments = key.split('.') if len(fragments) != 2: raise ValueError('Invalid "key" format') database, table = tuple(fragments) # Construct cache return Stash( ApswArchive(DatabaseManager.cache(database), table), 'lru:///?capacity=500&compact_threshold=1500', serializer=serializer, key_transform=(lambda k: str(k), lambda k: k) )
def reset(cls): if not DatabaseManager.reset('main', db, 'invalid-schema'): # Unable to reset database return False # Build migration router router = cls._build_router() if not router: return False # Run migrations router.run() # Log message to channel menu from plugin.managers.message import MessageManager from plugin.models import Message MessageManager.get.from_message(logging.WARNING, "Plugin database has been automatically reset due to schema corruption, see http://bit.ly/TFPx90101 for more details", code=Message.Code.DatabaseSchemaCorruptionReset ) return True
from plugin.core.database.manager import DatabaseManager import os migrations_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'migrations')) # Connect to database db = DatabaseManager.main()
def storage(name): return StashBackend( ApswArchive(DatabaseManager.cache('trakt'), name), 'lru:///?capacity=500&compact_threshold=1500', 'pickle:///?protocol=2' )