database manage init

This commit is contained in:
Ruud
2014-02-11 22:19:55 +01:00
parent 8724076601
commit 96e8a909d8
26 changed files with 382 additions and 183 deletions
+18
View File
@@ -1,3 +1,4 @@
from couchpotato import get_db
from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.encoding import ss, toSafeString, \
toUnicode, sp
@@ -24,6 +25,7 @@ log = CPLog(__name__)
class Plugin(object):
_class_name = None
_database = None
plugin_path = None
enabled_option = 'enabled'
@@ -53,6 +55,22 @@ class Plugin(object):
if self.auto_register_static:
self.registerStatic(inspect.getfile(self.__class__))
# Setup database
if self._database:
addEvent('database.setup', self.databaseSetup)
def databaseSetup(self):
db = get_db()
for index_name in self._database:
klass = self._database[index_name]
fireEvent('database.setup_index', index_name, klass)
def afterDatabaseSetup(self):
print self._database_indexes
def conf(self, attr, value = None, default = None, section = None):
class_name = self.getName().lower().split(':')[0].lower()
return Env.setting(attr, section = section if section else class_name, value = value, default = default)
@@ -2,6 +2,7 @@ from CodernityDB.tree_index import TreeBasedIndex
class CategoryIndex(TreeBasedIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = 'i'
@@ -16,6 +17,7 @@ class CategoryIndex(TreeBasedIndex):
class CategoryMediaIndex(TreeBasedIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
+5 -19
View File
@@ -12,6 +12,11 @@ log = CPLog(__name__)
class CategoryPlugin(Plugin):
_database = {
'category': CategoryIndex,
'category_media': CategoryMediaIndex,
}
def __init__(self):
addApiView('category.save', self.save)
addApiView('category.save_order', self.saveOrder)
@@ -25,25 +30,6 @@ class CategoryPlugin(Plugin):
})
addEvent('category.all', self.all)
addEvent('database.setup', self.databaseSetup)
def databaseSetup(self):
db = get_db()
# Category index
try:
db.add_index(CategoryIndex(db.path, 'category'))
except:
log.debug('Index already exists')
db.edit_index(CategoryIndex(db.path, 'category'))
# Category media_id index
try:
db.add_index(CategoryMediaIndex(db.path, 'category_media'))
except:
log.debug('Index already exists')
db.edit_index(CategoryMediaIndex(db.path, 'category_media'))
def allView(self, **kwargs):
+3 -3
View File
@@ -47,9 +47,9 @@ class FileManager(Plugin):
for x in file_dict.keys():
files.extend(file_dict[x])
for file in scandir.scandir(cache_dir):
if os.path.splitext(file.name)[1] in ['.png', '.jpg', '.jpeg']:
file_path = os.path.join(cache_dir, file.name)
for f in scandir.scandir(cache_dir):
if os.path.splitext(f.name)[1] in ['.png', '.jpg', '.jpeg']:
file_path = os.path.join(cache_dir, f.name)
if toUnicode(file_path) not in files:
os.remove(file_path)
except:
@@ -2,6 +2,7 @@ from CodernityDB.tree_index import TreeBasedIndex
class ProfileIndex(TreeBasedIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = 'i'
+3 -13
View File
@@ -12,7 +12,9 @@ log = CPLog(__name__)
class ProfilePlugin(Plugin):
to_dict = {'types': {}}
_database = {
'profile': ProfileIndex
}
def __init__(self):
addEvent('profile.all', self.all)
@@ -29,21 +31,9 @@ class ProfilePlugin(Plugin):
}"""}
})
addEvent('database.setup', self.databaseSetup)
addEvent('app.initialize', self.fill, priority = 90)
addEvent('app.load', self.forceDefaults)
def databaseSetup(self):
db = get_db()
try:
db.add_index(ProfileIndex(db.path, 'profile'))
except:
log.debug('Index already exists')
db.edit_index(ProfileIndex(db.path, 'profile'))
def forceDefaults(self):
# Get all active movies without profile
@@ -3,6 +3,7 @@ from hashlib import md5
class QualityIndex(HashIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
+4 -12
View File
@@ -14,6 +14,10 @@ log = CPLog(__name__)
class QualityPlugin(Plugin):
_database = {
'quality': QualityIndex
}
qualities = [
{'identifier': 'bd50', 'hd': True, 'size': (15000, 60000), 'label': 'BR-Disk', 'alternative': ['bd25'], 'allow': ['1080p'], 'ext':[], 'tags': ['bdmv', 'certificate', ('complete', 'bluray')]},
{'identifier': '1080p', 'hd': True, 'size': (4000, 20000), 'label': '1080p', 'width': 1920, 'height': 1080, 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['m2ts', 'x264', 'h264']},
@@ -49,7 +53,6 @@ class QualityPlugin(Plugin):
})
addEvent('app.initialize', self.fill, priority = 10)
addEvent('database.setup', self.databaseSetup)
addEvent('app.test', self.doTest)
@@ -63,17 +66,6 @@ class QualityPlugin(Plugin):
def getOrder(self):
return self.order
def databaseSetup(self):
db = get_db()
# Quality index
try:
db.add_index(QualityIndex(db.path, 'quality'))
except:
log.debug('Index already exists')
db.edit_index(QualityIndex(db.path, 'quality'))
def preReleases(self):
return self.pre_releases
@@ -4,6 +4,7 @@ from CodernityDB.tree_index import TreeBasedIndex
class ReleaseIndex(TreeBasedIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
@@ -30,6 +31,7 @@ class ReleaseIndex(TreeBasedIndex):
class ReleaseStatusIndex(TreeBasedIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
@@ -44,6 +46,7 @@ class ReleaseStatusIndex(TreeBasedIndex):
class ReleaseIDIndex(HashIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
@@ -58,6 +61,7 @@ class ReleaseIDIndex(HashIndex):
class ReleaseDownloadIndex(HashIndex):
_version = 1
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '32s'
+7 -34
View File
@@ -17,6 +17,13 @@ log = CPLog(__name__)
class Release(Plugin):
_database = {
'release': ReleaseIndex,
'release_status': ReleaseStatusIndex,
'release_identifier': ReleaseIDIndex,
'release_download': ReleaseDownloadIndex
}
def __init__(self):
addApiView('release.manual_download', self.manualDownload, docs = {
'desc': 'Send a release manually to the downloaders',
@@ -45,44 +52,10 @@ class Release(Plugin):
addEvent('release.clean', self.clean)
addEvent('release.update_status', self.updateStatus)
addEvent('database.setup', self.databaseSetup)
# Clean releases that didn't have activity in the last week
addEvent('app.load', self.cleanDone)
fireEvent('schedule.interval', 'movie.clean_releases', self.cleanDone, hours = 4)
def databaseSetup(self):
db = get_db()
# Release media_id index
try:
db.add_index(ReleaseIndex(db.path, 'release'))
except:
log.debug('Index already exists')
db.edit_index(ReleaseIndex(db.path, 'release'))
# Release status index
try:
db.add_index(ReleaseStatusIndex(db.path, 'release_status'))
except:
log.debug('Index already exists')
db.edit_index(ReleaseStatusIndex(db.path, 'release_status'))
# Release identifier index
try:
db.add_index(ReleaseIDIndex(db.path, 'release_identifier'))
except:
log.debug('Index already exists')
db.edit_index(ReleaseIDIndex(db.path, 'release_identifier'))
# Release identifier index
try:
db.add_index(ReleaseDownloadIndex(db.path, 'release_download'))
except:
log.debug('Index already exists')
db.edit_index(ReleaseDownloadIndex(db.path, 'release_download'))
def cleanDone(self):
log.debug('Removing releases from dashboard')
@@ -141,4 +141,4 @@ if(document.location.href.indexOf(host) == -1)
else
setVersion();
}
}