diff --git a/CouchPotato.py b/CouchPotato.py index 87ed21fb..f828192a 100755 --- a/CouchPotato.py +++ b/CouchPotato.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -"""Wrapper for the command line interface.""" +# -*- coding: utf-8 -*- +'''Wrapper for the command line interface.''' from os.path import dirname, isfile import os @@ -19,42 +20,35 @@ log = CPLog(__name__) try: from couchpotato import cli except ImportError, e: - print "Checking local dependencies..." + log.info('Checking local dependencies...') if isfile(__file__): cwd = dirname(__file__) - print "Updating libraries..." - stdout, stderr = subprocess.Popen(["git", "submodule", "init"], + log.info('Updating libraries...') + stdout, stderr = subprocess.Popen(['git', 'submodule', 'init'], stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate() if stderr: - print "[WARNING] Git is complaining:" - print "=" * 78 - print stderr - print "=" * 78 - stdout, stderr = subprocess.Popen(["git", "submodule", "update"], + log.info('[WARNING] Git is complaining:') + log.info(stderr) + stdout, stderr = subprocess.Popen(['git', 'submodule', 'update'], stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate() if stderr: - print "[WARNING] Git is complaining:" - print "=" * 78 - print stderr - print "=" * 78 + log.info('[WARNING] Git is complaining:') + log.info(stderr) - print "Passing execution to couchpotato..." + log.info('Passing execution to couchpotato...') try: from couchpotato import cli except ImportError: - print "[ERROR]: Something's seriously wrong." - print "=" * 78 - traceback.print_exc() - print "=" * 78 - print "Aborting..." + log.error("[ERROR]: Something's seriously wrong.") + log.error(traceback.print_exc()) sys.exit(1) else: # Running from Titanium raise NotImplementedError("Don't know how to do that.") -if __name__ == "__main__": +if __name__ == '__main__': try: cli.cmd_couchpotato(base_path) except Exception, e: diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index d57b5747..42529ffc 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -1,4 +1,13 @@ -"""Couchpotato.""" -from flask import Flask +from couchpotato.core.logger import CPLog +from flask import Flask, Module +from flask.helpers import url_for +from flask.templating import render_template app = Flask(__name__) +log = CPLog(__name__) +web = Module(__name__, 'web') + + +@web.route('/') +def index(): + return render_template('index.html') diff --git a/couchpotato/api/__init__.py b/couchpotato/api/__init__.py new file mode 100644 index 00000000..bf04eb8b --- /dev/null +++ b/couchpotato/api/__init__.py @@ -0,0 +1,7 @@ +from flask import Module + +api = Module(__name__) + +@api.route('/') +def index(): + return 'api' diff --git a/couchpotato/cli.py b/couchpotato/cli.py index e3b86455..1644d920 100644 --- a/couchpotato/cli.py +++ b/couchpotato/cli.py @@ -1,6 +1,8 @@ from couchpotato import app +from couchpotato.api import api from couchpotato.core.logger import CPLog -from couchpotato.settings import Settings +from couchpotato.core.settings import Settings +from couchpotato import web from logging import handlers from optparse import OptionParser import logging @@ -60,14 +62,31 @@ def cmd_couchpotato(base_path): # Load configs - from couchpotato.settings.loader import SettingsLoader + from couchpotato.core.settings.loader import SettingsLoader sl = SettingsLoader(root = base_path) sl.addConfig('couchpotato', 'core') sl.run() # Create app + api_key = settings.get('api_key') + url_base = '/%s/' % settings.get('url_base') + + # Basic config app.host = settings.get('host', default = '0.0.0.0') app.port = settings.get('port', default = 5000) app.debug = debug + app.secret_key = api_key + app.static_path = url_base + 'static' + + # Add static url with url_base + app.add_url_rule(app.static_path + '/', + endpoint = 'static', + view_func = app.send_static_file) + + # Register modules + app.register_module(web, url_prefix = url_base) + app.register_module(api, url_prefix = '%sapi/%s' % (url_base, api_key)) + + # Go go go! app.run() diff --git a/couchpotato/core/__init__.py b/couchpotato/core/__init__.py index c2933335..81fce1ff 100644 --- a/couchpotato/core/__init__.py +++ b/couchpotato/core/__init__.py @@ -1,3 +1,5 @@ +from uuid import uuid4 + config = ('global', { 'debug': False, 'host': '0.0.0.0', @@ -6,4 +8,5 @@ config = ('global', { 'password': '', 'launch_browser': True, 'url_base': '', + 'api_key': uuid4().hex, }) diff --git a/couchpotato/settings/__init__.py b/couchpotato/core/settings/__init__.py similarity index 100% rename from couchpotato/settings/__init__.py rename to couchpotato/core/settings/__init__.py diff --git a/couchpotato/settings/db.py b/couchpotato/core/settings/db.py similarity index 100% rename from couchpotato/settings/db.py rename to couchpotato/core/settings/db.py diff --git a/couchpotato/settings/loader.py b/couchpotato/core/settings/loader.py similarity index 100% rename from couchpotato/settings/loader.py rename to couchpotato/core/settings/loader.py diff --git a/couchpotato/settings/model.py b/couchpotato/core/settings/model.py similarity index 100% rename from couchpotato/settings/model.py rename to couchpotato/core/settings/model.py diff --git a/couchpotato/static/style/main.css b/couchpotato/static/style/main.css new file mode 100644 index 00000000..e69de29b diff --git a/couchpotato/templates/_desktop.html b/couchpotato/templates/_desktop.html new file mode 100644 index 00000000..f68ef762 --- /dev/null +++ b/couchpotato/templates/_desktop.html @@ -0,0 +1,14 @@ + + + + + CouchPotato + + +
{% block content %}{% endblock %}
+ + \ No newline at end of file diff --git a/couchpotato/templates/_mobile.html b/couchpotato/templates/_mobile.html new file mode 100644 index 00000000..e69de29b diff --git a/couchpotato/templates/index.html b/couchpotato/templates/index.html new file mode 100644 index 00000000..b10a8cc5 --- /dev/null +++ b/couchpotato/templates/index.html @@ -0,0 +1,6 @@ +{% extends "_desktop.html" %} + +{% block content %} +{{ url_for('.static', filename='style/main.css') }} +{{ url_for('api.index') }} +{% endblock %} \ No newline at end of file