Added api and front_end as Modules

This commit is contained in:
Ruud
2011-02-13 01:58:56 +01:00
parent 09135e1738
commit 38a9ae2592
13 changed files with 76 additions and 24 deletions
+14 -20
View File
@@ -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:
+11 -2
View File
@@ -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')
+7
View File
@@ -0,0 +1,7 @@
from flask import Module
api = Module(__name__)
@api.route('/')
def index():
return 'api'
+21 -2
View File
@@ -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 + '/<path:filename>',
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()
+3
View File
@@ -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,
})
View File
+14
View File
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="{{ url_for('.static', filename='style/main.css') }}">
<title>CouchPotato</title>
</head>
<body>
<div id="content">{% block content %}{% endblock %}</div>
<div id="footer">
{% block footer %}
Footer
{% endblock %}
</div>
</body>
View File
+6
View File
@@ -0,0 +1,6 @@
{% extends "_desktop.html" %}
{% block content %}
{{ url_for('.static', filename='style/main.css') }}
{{ url_for('api.index') }}
{% endblock %}