Browse Source

Ask for old CouchPotato database in the wizard. closes #144

tags/build/2.0.0.pre1
Ruud 13 years ago
parent
commit
2d61a31005
  1. 4
      couchpotato/api.py
  2. 4
      couchpotato/core/plugins/movie/main.py
  3. 6
      couchpotato/core/plugins/v1importer/__init__.py
  4. 30
      couchpotato/core/plugins/v1importer/form.html
  5. 56
      couchpotato/core/plugins/v1importer/main.py
  6. 29
      couchpotato/core/plugins/wizard/static/wizard.js

4
couchpotato/api.py

@ -6,8 +6,8 @@ api = Blueprint('api', __name__)
api_docs = {}
api_docs_missing = []
def addApiView(route, func, static = False, docs = None):
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func)
def addApiView(route, func, static = False, docs = None, **kwargs):
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func, **kwargs)
if docs:
api_docs[route[4:] if route[0:4] == 'api.' else route] = docs
else:

4
couchpotato/core/plugins/movie/main.py

@ -270,7 +270,7 @@ class MoviePlugin(Plugin):
'movies': movies,
})
def add(self, params = {}, force_readd = True):
def add(self, params = {}, force_readd = True, search_after = True):
library = fireEvent('library.add', single = True, attrs = params, update_after = False)
@ -316,7 +316,7 @@ class MoviePlugin(Plugin):
movie_dict = m.to_dict(self.default_dict)
if force_readd or do_search:
if (force_readd or do_search) and search_after:
fireEventAsync('searcher.single', movie_dict)
return movie_dict

6
couchpotato/core/plugins/v1importer/__init__.py

@ -0,0 +1,6 @@
from .main import V1Importer
def start():
return V1Importer()
config = []

30
couchpotato/core/plugins/v1importer/form.html

@ -0,0 +1,30 @@
<html>
<head>
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/main.css') }}" type="text/css">
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/uniform.generic.css') }}" type="text/css">
<link rel="stylesheet" href="{{ url_for('web.static', filename='style/uniform.css') }}" type="text/css">
<script type="text/javascript" src="{{ url_for('web.static', filename='scripts/library/mootools.js') }}"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
if($('old_db'))
$('old_db').addEvent('change', function(){
$('form').submit();
});
});
</script>
</head>
<body>
{% if message: %}
{{ message }}
{% else: %}
<form id="form" method="post" enctype="multipart/form-data">
<input type="file" name="old_db" id="old_db" />
</form>
{% endif %}
</body>
</html>

56
couchpotato/core/plugins/v1importer/main.py

@ -0,0 +1,56 @@
from couchpotato.api import addApiView
from couchpotato.core.event import fireEventAsync
from couchpotato.core.helpers.variable import getImdb
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask.globals import request
from flask.helpers import url_for
import os
log = CPLog(__name__)
class V1Importer(Plugin):
def __init__(self):
addApiView('v1.import', self.fromOld, methods = ['GET', 'POST'])
def fromOld(self):
if request.method != 'POST':
return self.renderTemplate(__file__, 'form.html', url_for = url_for)
file = request.files['old_db']
uploaded_file = os.path.join(Env.get('cache_dir'), 'v1_database.db')
if os.path.isfile(uploaded_file):
os.remove(uploaded_file)
file.save(uploaded_file)
try:
import sqlite3
conn = sqlite3.connect(uploaded_file)
wanted = []
t = ('want',)
cur = conn.execute('SELECT status, imdb FROM Movie WHERE status=?', t)
for row in cur:
status, imdb = row
if getImdb(imdb):
wanted.append(imdb)
conn.close()
wanted = set(wanted)
for imdb in wanted:
fireEventAsync('movie.add', {'identifier': imdb}, search_after = False)
message = 'Successfully imported %s movie(s)' % len(wanted)
except Exception, e:
message = 'Failed: %s' % e
return self.renderTemplate(__file__, 'form.html', url_for = url_for, message = message)

29
couchpotato/core/plugins/wizard/static/wizard.js

@ -8,8 +8,28 @@ Page.Wizard = new Class({
headers: {
'welcome': {
'title': 'Welcome to CouchPotato',
'description': 'To get started, fill in each of the following settings as much as your can.'
'title': 'Welcome to the new CouchPotato',
'description': 'To get started, fill in each of the following settings as much as your can. <br />Maybe first start with importing your movies from the previous CouchPotato',
'content': new Element('div', {
'styles': {
'margin': '0 0 0 30px'
}
}).adopt(
new Element('div', {
'html': 'Select the <strong>data.db</strong>. It should be in your CouchPotato root directory.'
}),
self.import_iframe = new Element('iframe', {
'styles': {
'height': 40,
'width': 300,
'border': 0,
'overflow': 'hidden'
}
})
),
'event': function(){
self.import_iframe.set('src', Api.createUrl('v1.import'))
}
},
'general': {
'title': 'General',
@ -105,7 +125,7 @@ Page.Wizard = new Class({
'text': self.headers[group].title
}),
self.headers[group].description ? new Element('span.description', {
'text': self.headers[group].description
'html': self.headers[group].description
}) : null,
self.headers[group].content ? self.headers[group].content : null
).inject(form);
@ -132,6 +152,9 @@ Page.Wizard = new Class({
})
).inject(tabs);
}
if(self.headers[group] && self.headers[group].event)
self.headers[group].event.call()
});
// Remove toggle

Loading…
Cancel
Save