Cleanup after database use
This commit is contained in:
@@ -65,6 +65,7 @@ class CoreNotifier(Notification):
|
||||
q.update({Notif.read: True})
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
return jsonified({
|
||||
'success': True
|
||||
@@ -90,6 +91,7 @@ class CoreNotifier(Notification):
|
||||
ndict['type'] = 'notification'
|
||||
notifications.append(ndict)
|
||||
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True,
|
||||
'empty': len(notifications) == 0,
|
||||
@@ -114,7 +116,8 @@ class CoreNotifier(Notification):
|
||||
ndict['time'] = time.time()
|
||||
self.messages.append(ndict)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return True
|
||||
|
||||
def frontend(self, type = 'notification', data = {}):
|
||||
self.messages.append({
|
||||
@@ -143,6 +146,8 @@ class CoreNotifier(Notification):
|
||||
ndict['type'] = 'notification'
|
||||
messages.append(ndict)
|
||||
|
||||
db.close()
|
||||
|
||||
self.messages = []
|
||||
return jsonified({
|
||||
'success': True,
|
||||
|
||||
@@ -22,3 +22,6 @@ class History(Notification):
|
||||
)
|
||||
db.add(history)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
return True
|
||||
|
||||
@@ -87,7 +87,7 @@ class FileManager(Plugin):
|
||||
db.commit()
|
||||
|
||||
type_dict = ft.to_dict()
|
||||
db.remove()
|
||||
db.close()
|
||||
return type_dict
|
||||
|
||||
def getTypes(self):
|
||||
@@ -100,4 +100,5 @@ class FileManager(Plugin):
|
||||
for type_object in results:
|
||||
types.append(type_object.to_dict())
|
||||
|
||||
db.close()
|
||||
return types
|
||||
|
||||
@@ -53,7 +53,7 @@ class LibraryPlugin(Plugin):
|
||||
|
||||
library_dict = l.to_dict(self.default_dict)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return library_dict
|
||||
|
||||
def update(self, identifier, default_title = '', force = False):
|
||||
@@ -130,7 +130,7 @@ class LibraryPlugin(Plugin):
|
||||
|
||||
fireEvent('library.update_finish', data = library_dict)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return library_dict
|
||||
|
||||
def updateReleaseDate(self, identifier):
|
||||
@@ -144,7 +144,7 @@ class LibraryPlugin(Plugin):
|
||||
db.commit()
|
||||
|
||||
dates = library.info.get('release_date', {})
|
||||
db.remove()
|
||||
db.close()
|
||||
|
||||
return dates
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from couchpotato.core.helpers.request import getParams, jsonified, getParam
|
||||
from couchpotato.core.helpers.variable import getImdb
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Movie, Library, LibraryTitle
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, Movie
|
||||
from couchpotato.environment import Env
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
from sqlalchemy.sql.expression import or_, asc, not_
|
||||
@@ -109,10 +109,12 @@ class MoviePlugin(Plugin):
|
||||
db = get_session()
|
||||
m = db.query(Movie).filter_by(id = movie_id).first()
|
||||
|
||||
results = None
|
||||
if m:
|
||||
return m.to_dict(self.default_dict)
|
||||
results = m.to_dict(self.default_dict)
|
||||
|
||||
return None
|
||||
db.close()
|
||||
return results
|
||||
|
||||
def list(self, status = ['active'], limit_offset = None, starts_with = None, search = None):
|
||||
|
||||
@@ -175,6 +177,7 @@ class MoviePlugin(Plugin):
|
||||
})
|
||||
movies.append(temp)
|
||||
|
||||
db.close()
|
||||
return movies
|
||||
|
||||
def availableChars(self, status = ['active']):
|
||||
@@ -200,6 +203,7 @@ class MoviePlugin(Plugin):
|
||||
if char not in chars:
|
||||
chars += char
|
||||
|
||||
db.close()
|
||||
return chars
|
||||
|
||||
def listView(self):
|
||||
@@ -246,6 +250,7 @@ class MoviePlugin(Plugin):
|
||||
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True)
|
||||
fireEventAsync('searcher.single', movie.to_dict(self.default_dict))
|
||||
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True,
|
||||
})
|
||||
@@ -319,6 +324,7 @@ class MoviePlugin(Plugin):
|
||||
if (force_readd or do_search) and search_after:
|
||||
fireEventAsync('searcher.single', movie_dict)
|
||||
|
||||
db.close()
|
||||
return movie_dict
|
||||
|
||||
|
||||
@@ -365,6 +371,7 @@ class MoviePlugin(Plugin):
|
||||
movie_dict = m.to_dict(self.default_dict)
|
||||
fireEventAsync('searcher.single', movie_dict)
|
||||
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True,
|
||||
})
|
||||
@@ -419,6 +426,7 @@ class MoviePlugin(Plugin):
|
||||
else:
|
||||
fireEvent('movie.restatus', movie.id, single = True)
|
||||
|
||||
db.close()
|
||||
return True
|
||||
|
||||
def restatus(self, movie_id):
|
||||
@@ -447,5 +455,6 @@ class MoviePlugin(Plugin):
|
||||
m.status_id = active_status.get('id') if move_to_wanted else done_status.get('id')
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
return True
|
||||
|
||||
@@ -47,6 +47,7 @@ class ProfilePlugin(Plugin):
|
||||
for profile in profiles:
|
||||
temp.append(profile.to_dict(self.to_dict))
|
||||
|
||||
db.close()
|
||||
return temp
|
||||
|
||||
def save(self):
|
||||
@@ -83,6 +84,7 @@ class ProfilePlugin(Plugin):
|
||||
|
||||
profile_dict = p.to_dict(self.to_dict)
|
||||
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True,
|
||||
'profile': profile_dict
|
||||
@@ -92,8 +94,10 @@ class ProfilePlugin(Plugin):
|
||||
|
||||
db = get_session()
|
||||
default = db.query(Profile).first()
|
||||
default_dict = default.to_dict(self.to_dict)
|
||||
db.close()
|
||||
|
||||
return default.to_dict(self.to_dict)
|
||||
return default_dict
|
||||
|
||||
def saveOrder(self):
|
||||
|
||||
@@ -109,6 +113,7 @@ class ProfilePlugin(Plugin):
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
return jsonified({
|
||||
'success': True
|
||||
@@ -133,6 +138,8 @@ class ProfilePlugin(Plugin):
|
||||
message = 'Failed deleting Profile: %s' % e
|
||||
log.error(message)
|
||||
|
||||
db.close()
|
||||
|
||||
return jsonified({
|
||||
'success': success,
|
||||
'message': message
|
||||
@@ -180,4 +187,5 @@ class ProfilePlugin(Plugin):
|
||||
|
||||
order += 1
|
||||
|
||||
db.close()
|
||||
return True
|
||||
|
||||
@@ -68,6 +68,7 @@ class QualityPlugin(Plugin):
|
||||
q = mergeDicts(self.getQuality(quality.identifier), quality.to_dict())
|
||||
temp.append(q)
|
||||
|
||||
db.close()
|
||||
return temp
|
||||
|
||||
def single(self, identifier = ''):
|
||||
@@ -79,6 +80,7 @@ class QualityPlugin(Plugin):
|
||||
if quality:
|
||||
quality_dict = dict(self.getQuality(quality.identifier), **quality.to_dict())
|
||||
|
||||
db.close()
|
||||
return quality_dict
|
||||
|
||||
def getQuality(self, identifier):
|
||||
@@ -98,6 +100,7 @@ class QualityPlugin(Plugin):
|
||||
setattr(quality, params.get('value_type'), params.get('value'))
|
||||
db.commit()
|
||||
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
@@ -149,6 +152,7 @@ class QualityPlugin(Plugin):
|
||||
order += 1
|
||||
db.commit()
|
||||
|
||||
db.close()
|
||||
return True
|
||||
|
||||
def guess(self, files, extra = {}):
|
||||
|
||||
@@ -83,7 +83,7 @@ class Release(Plugin):
|
||||
|
||||
fireEvent('movie.restatus', movie.id)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
|
||||
return True
|
||||
|
||||
@@ -109,7 +109,7 @@ class Release(Plugin):
|
||||
rel.delete()
|
||||
db.commit()
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
@@ -126,7 +126,7 @@ class Release(Plugin):
|
||||
rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id')
|
||||
db.commit()
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
@@ -153,14 +153,14 @@ class Release(Plugin):
|
||||
'files': {}
|
||||
}), manual = True)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': True
|
||||
})
|
||||
else:
|
||||
log.error('Couldn\'t find release with id: %s' % id)
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return jsonified({
|
||||
'success': False
|
||||
})
|
||||
|
||||
@@ -378,6 +378,7 @@ class Renamer(Plugin):
|
||||
if self.shuttingDown():
|
||||
break
|
||||
|
||||
db.close()
|
||||
self.renaming_started = False
|
||||
|
||||
def getRenameExtras(self, extra_type = '', replacements = {}, folder_name = '', file_name = '', destination = '', group = {}, current_file = ''):
|
||||
|
||||
@@ -8,9 +8,8 @@ from couchpotato.core.settings.model import File
|
||||
from couchpotato.environment import Env
|
||||
from enzyme.exceptions import NoParserError, ParseError
|
||||
from guessit import guess_movie_info
|
||||
from subliminal.videos import scan
|
||||
from subliminal.videos import scan, Video
|
||||
import enzyme
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
@@ -102,12 +101,12 @@ class Scanner(Plugin):
|
||||
if group['library']:
|
||||
fireEvent('release.add', group = group)
|
||||
|
||||
def scanFolderToLibrary(self, folder = None, newer_than = None):
|
||||
def scanFolderToLibrary(self, folder = None, newer_than = None, simple = True):
|
||||
|
||||
if not os.path.isdir(folder):
|
||||
return
|
||||
|
||||
groups = self.scan(folder = folder)
|
||||
groups = self.scan(folder = folder, simple = simple)
|
||||
|
||||
added_identifier = []
|
||||
while True and not self.shuttingDown():
|
||||
@@ -128,7 +127,7 @@ class Scanner(Plugin):
|
||||
return added_identifier
|
||||
|
||||
|
||||
def scan(self, folder = None, files = []):
|
||||
def scan(self, folder = None, files = [], simple = False):
|
||||
|
||||
if not folder or not os.path.isdir(folder):
|
||||
log.error('Folder doesn\'t exists: %s' % folder)
|
||||
@@ -292,7 +291,7 @@ class Scanner(Plugin):
|
||||
group['meta_data'] = self.getMetaData(group)
|
||||
|
||||
# Subtitle meta
|
||||
group['subtitle_language'] = self.getSubtitleLanguage(group)
|
||||
group['subtitle_language'] = self.getSubtitleLanguage(group) if not simple else {}
|
||||
|
||||
# Get parent dir from movie files
|
||||
for movie_file in group['files']['movie']:
|
||||
@@ -393,7 +392,9 @@ class Scanner(Plugin):
|
||||
scan_result = []
|
||||
for p in paths:
|
||||
if not group['is_dvd']:
|
||||
scan_result.extend(scan(p))
|
||||
video = Video.from_path(p)
|
||||
video_result = [(video, video.scan())]
|
||||
scan_result.extend(video_result)
|
||||
|
||||
for video, detected_subtitles in scan_result:
|
||||
for s in detected_subtitles:
|
||||
@@ -454,7 +455,7 @@ class Scanner(Plugin):
|
||||
break
|
||||
except:
|
||||
pass
|
||||
db.remove()
|
||||
db.close()
|
||||
|
||||
# Search based on OpenSubtitleHash
|
||||
if not imdb_id and not group['is_dvd']:
|
||||
|
||||
@@ -61,6 +61,7 @@ class Searcher(Plugin):
|
||||
if self.shuttingDown():
|
||||
break
|
||||
|
||||
db.close()
|
||||
self.in_progress = False
|
||||
|
||||
def single(self, movie):
|
||||
@@ -147,7 +148,7 @@ class Searcher(Plugin):
|
||||
if self.shuttingDown():
|
||||
break
|
||||
|
||||
db.remove()
|
||||
db.close()
|
||||
return False
|
||||
|
||||
def download(self, data, movie, manual = False):
|
||||
@@ -190,6 +191,7 @@ class Searcher(Plugin):
|
||||
except Exception, e:
|
||||
log.error('Failed marking movie finished: %s %s' % (e, traceback.format_exc()))
|
||||
|
||||
db.close()
|
||||
return True
|
||||
|
||||
log.info('Tried to download, but none of the downloaders are enabled')
|
||||
|
||||
@@ -48,7 +48,10 @@ class StatusPlugin(Plugin):
|
||||
def getById(self, id):
|
||||
db = get_session()
|
||||
status = db.query(Status).filter_by(id = id).first()
|
||||
return status.to_dict()
|
||||
status_dict = status.to_dict()
|
||||
db.close()
|
||||
|
||||
return status_dict
|
||||
|
||||
def all(self):
|
||||
|
||||
@@ -61,6 +64,7 @@ class StatusPlugin(Plugin):
|
||||
s = status.to_dict()
|
||||
temp.append(s)
|
||||
|
||||
db.close()
|
||||
return temp
|
||||
|
||||
def add(self, identifier):
|
||||
@@ -78,6 +82,7 @@ class StatusPlugin(Plugin):
|
||||
|
||||
status_dict = s.to_dict()
|
||||
|
||||
db.close()
|
||||
return status_dict
|
||||
|
||||
def fill(self):
|
||||
@@ -97,3 +102,5 @@ class StatusPlugin(Plugin):
|
||||
s.label = toUnicode(label)
|
||||
db.commit()
|
||||
|
||||
db.close()
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ class Subtitle(Plugin):
|
||||
# get subtitles for those files
|
||||
subliminal.list_subtitles(files, cache_dir = Env.get('cache_dir'), multi = True, languages = self.getLanguages(), services = self.services)
|
||||
|
||||
db.close()
|
||||
|
||||
def searchSingle(self, group):
|
||||
|
||||
if self.isDisabled(): return
|
||||
|
||||
@@ -44,8 +44,8 @@ class MovieResultModifier(Plugin):
|
||||
}
|
||||
|
||||
# Add release info from current library
|
||||
db = get_session()
|
||||
try:
|
||||
db = get_session()
|
||||
l = db.query(Library).filter_by(identifier = imdb).first()
|
||||
if l:
|
||||
|
||||
@@ -63,6 +63,7 @@ class MovieResultModifier(Plugin):
|
||||
except:
|
||||
log.error('Tried getting more info on searched movies: %s' % traceback.format_exc())
|
||||
|
||||
db.close()
|
||||
return temp
|
||||
|
||||
def checkLibrary(self, result):
|
||||
|
||||
@@ -59,6 +59,7 @@ class CouchPotatoApi(MovieProvider):
|
||||
db = get_session()
|
||||
active_movies = db.query(Movie).filter(Movie.status.has(identifier = 'active')).all()
|
||||
movies = [x.library.identifier for x in active_movies]
|
||||
db.close()
|
||||
|
||||
suggestions = self.suggest(movies, ignore)
|
||||
|
||||
|
||||
@@ -197,11 +197,15 @@ class Settings(object):
|
||||
from couchpotato import get_session
|
||||
|
||||
db = get_session()
|
||||
prop = None
|
||||
try:
|
||||
prop = db.query(Properties).filter_by(identifier = identifier).first()
|
||||
return prop.value if prop else None
|
||||
propert = db.query(Properties).filter_by(identifier = identifier).first()
|
||||
prop = propert.value
|
||||
except:
|
||||
return None
|
||||
pass
|
||||
|
||||
db.close()
|
||||
return prop
|
||||
|
||||
def setProperty(self, identifier, value = ''):
|
||||
from couchpotato import get_session
|
||||
@@ -217,3 +221,4 @@ class Settings(object):
|
||||
p.value = toUnicode(value)
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user