Browse Source

Added api and front_end as Modules

pull/1/merge
Ruud 14 years ago
parent
commit
38a9ae2592
  1. 34
      CouchPotato.py
  2. 13
      couchpotato/__init__.py
  3. 7
      couchpotato/api/__init__.py
  4. 23
      couchpotato/cli.py
  5. 3
      couchpotato/core/__init__.py
  6. 0
      couchpotato/core/settings/__init__.py
  7. 0
      couchpotato/core/settings/db.py
  8. 0
      couchpotato/core/settings/loader.py
  9. 0
      couchpotato/core/settings/model.py
  10. 0
      couchpotato/static/style/main.css
  11. 14
      couchpotato/templates/_desktop.html
  12. 0
      couchpotato/templates/_mobile.html
  13. 6
      couchpotato/templates/index.html

34
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:

13
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')

7
couchpotato/api/__init__.py

@ -0,0 +1,7 @@
from flask import Module
api = Module(__name__)
@api.route('/')
def index():
return 'api'

23
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 + '/<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
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,
})

0
couchpotato/settings/__init__.py → couchpotato/core/settings/__init__.py

0
couchpotato/settings/db.py → couchpotato/core/settings/db.py

0
couchpotato/settings/loader.py → couchpotato/core/settings/loader.py

0
couchpotato/settings/model.py → couchpotato/core/settings/model.py

0
couchpotato/static/style/main.css

14
couchpotato/templates/_desktop.html

@ -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>

0
couchpotato/templates/_mobile.html

6
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 %}
Loading…
Cancel
Save