More nosql

This commit is contained in:
Ruud
2014-02-02 20:41:14 +01:00
parent 63743dd2b6
commit 99252074be
82 changed files with 643 additions and 715 deletions
+6 -7
View File
@@ -1,16 +1,15 @@
from CodernityDB.hash_index import HashIndex
from hashlib import md5
from CodernityDB.tree_index import TreeBasedIndex
class ProfileIndex(HashIndex):
class ProfileIndex(TreeBasedIndex):
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '16s'
kwargs['key_format'] = 'i'
super(ProfileIndex, self).__init__(*args, **kwargs)
def make_key(self, key):
return md5(key).digest()
return key
def make_key_value(self, data):
if data.get('type') == 'profile' and data.get('identifier'):
return md5(data.get('identifier')).digest(), None
if data.get('_t') == 'profile':
return data.get('order', 99), None
+7 -13
View File
@@ -1,13 +1,12 @@
import traceback
from couchpotato import get_session, get_db
from couchpotato.api import addApiView
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.event import addEvent
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from .index import ProfileIndex
from couchpotato.core.settings.model import Profile, ProfileType, Media
from sqlalchemy.orm import joinedload_all
from couchpotato.core.settings.model import Profile, ProfileType
log = CPLog(__name__)
@@ -34,7 +33,7 @@ class ProfilePlugin(Plugin):
addEvent('database.setup', self.databaseSetup)
addEvent('app.initialize', self.fill, priority = 90)
addEvent('app.load2', self.forceDefaults)
addEvent('app.load', self.forceDefaults)
def databaseSetup(self):
@@ -46,7 +45,6 @@ class ProfilePlugin(Plugin):
log.debug('Index already exists')
db.edit_index(ProfileIndex(db.path, 'profile'))
def forceDefaults(self):
# Get all active movies without profile
@@ -57,7 +55,7 @@ class ProfilePlugin(Plugin):
profile_ids = [x.get('_id') for x in self.all()]
for media in medias:
if media['profile_id'] not in profile_ids:
if media.get('profile_id') not in profile_ids:
default_profile = self.default()
media['profile_id'] = default_profile.get('id')
db.update(media)
@@ -76,7 +74,7 @@ class ProfilePlugin(Plugin):
db = get_db()
profiles = db.all('profile', with_doc = True)
return list(profiles)
return [x['doc'] for x in profiles]
def save(self, **kwargs):
@@ -127,7 +125,7 @@ class ProfilePlugin(Plugin):
def default(self):
db = get_db()
return db.get_many('profile', limit = 1, with_doc = True)[0]
return list(db.all('profile', limit = 1, with_doc = True))[0]['doc']
def saveOrder(self, **kwargs):
@@ -213,8 +211,7 @@ class ProfilePlugin(Plugin):
log.info('Creating default profile: %s', profile.get('label'))
pro = {
'type': 'profile',
'identifier': profile.get('label').lower(),
'_t': 'profile',
'label': toUnicode(profile.get('label')),
'order': order,
'qualities': profile.get('qualities'),
@@ -229,9 +226,6 @@ class ProfilePlugin(Plugin):
db.insert(pro)
order += 1
for x in db.all('profile', with_doc = True):
log.info(x)
return True
except:
log.error('Failed: %s', traceback.format_exc())
@@ -324,4 +324,4 @@ Profile.Type = new Class({
return this.el;
}
})
})