This commit is contained in:
Matthew Scragg 2014-09-02 09:29:04 -05:00
parent 86f0549e44
commit 564bde872d
9 changed files with 75 additions and 39 deletions

3
.gitignore vendored
View file

@ -1,5 +1,5 @@
.vagrant .vagrant
.virtualenvs .venv
.idea .idea
.webassets-cache .webassets-cache
*.pyc *.pyc
@ -8,3 +8,4 @@ config.sls
config.json config.json
realms/static/vendor realms/static/vendor
realms/static/assets/* realms/static/assets/*
wiki.db

9
README.md Normal file
View file

@ -0,0 +1,9 @@
# Realms Wiki
## Installation
### Ubuntu
```
sudo apt-get install -y python-dev build-essential git libpcre3-dev libevent-dev python-pip python-virtualenv curl libxml2-dev libxslt1-dev zlib1g-dev libffi-dev
```

10
Vagrantfile vendored
View file

@ -9,16 +9,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vb.cpus = 2 vb.cpus = 2
end end
config.vm.synced_folder "srv/", "/srv/" config.vm.provision "shell", path: "provision.sh"
config.vm.synced_folder ".", "/home/deploy/realms"
config.vm.synced_folder "~/.virtualenvs", "/home/deploy/virtualenvs"
config.vm.provision :salt do |salt|
salt.minion_config = "srv/minion"
salt.run_highstate = true
end
end end
Vagrant::Config.run do |config| Vagrant::Config.run do |config|
config.vm.forward_port 80, 8080 config.vm.forward_port 80, 8080
config.vm.forward_port 4567, 4567 config.vm.forward_port 5000, 5000
end end

44
provision.sh Normal file
View file

@ -0,0 +1,44 @@
#!/bin/bash
APP_DIR=/vagrant
echo "Provisioning..."
add-apt-repository -y ppa:chris-lea/node.js
apt-get update
apt-get install -y python build-essential git libpcre3-dev python-software-properties \
python-pip python-virtualenv python-dev pkg-config curl libxml2-dev libxslt1-dev zlib1g-dev \
libffi-dev nodejs screen
# Default cache is memoization
# Redis
# add-apt-repository -y chris-lea/redis-server
# add-apt-repository -y chris-lea/python-redis
# apt-get update
# apt-get install -y redis-server
# Default DB is sqlite
# Mysql
# apt-get install -y mysql-server mysql-client
# MariaDB
# apt-get install -y mariadb-server mariadb-client
# Postgres
# apt-get install -y postgresql postgresql-contrib
cd ${APP_DIR}
# Install frontend assets
npm install -g bower
bower install
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Dev server http://127.0.0.1:5000
# python realms.py runserver

View file

@ -2,7 +2,7 @@ from gevent import wsgi
from realms import config, app, manager from realms import config, app, manager
from flask.ext.script import Server from flask.ext.script import Server
manager.add_command("runserver", Server(host="0.0.0.0", port=config.PORT)) manager.add_command("runserver", Server(host="0.0.0.0", port=5000))
@manager.command @manager.command

View file

@ -9,41 +9,25 @@ reload(sys)
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8') sys.setdefaultencoding('utf-8')
# Silence Sentry and Requests.
import logging
logging.getLogger().setLevel(logging.INFO)
logging.getLogger('raven').setLevel(logging.WARNING)
logging.getLogger('requests').setLevel(logging.WARNING)
import time import time
import sys import sys
import json import json
import httplib import httplib
import traceback import traceback
from flask import Flask, request, render_template, url_for, redirect, g from flask import Flask, request, render_template, url_for, redirect, g
from flask.ctx import _AppCtxGlobals
from flask.ext.cache import Cache from flask.ext.cache import Cache
from flask.ext.script import Manager from flask.ext.script import Manager
from flask.ext.login import LoginManager, current_user from flask.ext.login import LoginManager, current_user
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.assets import Environment, Bundle from flask.ext.assets import Environment, Bundle
from werkzeug.routing import BaseConverter from werkzeug.routing import BaseConverter
from werkzeug.utils import cached_property
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from realms import config from realms import config
from realms.lib.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict from realms.lib.util import to_canonical, remove_ext, mkdir_safe, gravatar_url, to_dict
class AppCtxGlobals(_AppCtxGlobals):
@cached_property
def current_user(self):
return current_user
class Application(Flask): class Application(Flask):
app_ctx_globals_class = AppCtxGlobals
def __call__(self, environ, start_response): def __call__(self, environ, start_response):
path_info = environ.get('PATH_INFO') path_info = environ.get('PATH_INFO')
@ -104,7 +88,7 @@ class Application(Flask):
class Assets(Environment): class Assets(Environment):
default_filters = {'js': 'uglifyjs', 'css': 'cssmin'} default_filters = {'js': 'jsmin', 'css': 'cssmin'}
default_output = {'js': 'assets/%(version)s.js', 'css': 'assets/%(version)s.css'} default_output = {'js': 'assets/%(version)s.js', 'css': 'assets/%(version)s.css'}
def register(self, name, *args, **kwargs): def register(self, name, *args, **kwargs):
@ -139,7 +123,7 @@ def error_handler(e):
else: else:
status_code = httplib.INTERNAL_SERVER_ERROR status_code = httplib.INTERNAL_SERVER_ERROR
message = None message = None
tb = traceback.format_exc() if g.current_user.staff else None tb = traceback.format_exc() if current_user.staff else None
if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']: if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
response = { response = {

View file

@ -2,6 +2,9 @@ import os
import json import json
from urlparse import urlparse from urlparse import urlparse
APP_PATH = os.path.dirname(__file__) + "/../.."
USER_HOME = os.path.expanduser("~")
ENV = 'DEV' ENV = 'DEV'
DEBUG = True DEBUG = True
@ -12,7 +15,7 @@ SQLALCHEMY_ECHO = True
PORT = 80 PORT = 80
BASE_URL = 'http://realms.dev' BASE_URL = 'http://realms.dev'
DB_URI = 'sqlite:////home/deploy/wiki.db' DB_URI = 'sqlite:///%s/wiki.db' % USER_HOME
CACHE_TYPE = 'simple' CACHE_TYPE = 'simple'
@ -24,7 +27,7 @@ CACHE_REDIS_PORT = 6379
CACHE_REDIS_DB = '0' CACHE_REDIS_DB = '0'
""" """
RECAPTCHA_ENABLE = True RECAPTCHA_ENABLE = False
RECAPTCHA_USE_SSL = False RECAPTCHA_USE_SSL = False
RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao" RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao"
RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE" RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE"
@ -32,14 +35,14 @@ RECAPTCHA_OPTIONS = {}
SECRET_KEY = 'K3dRq1q9eN72GJDkgvyshFVwlqHHCyPI' SECRET_KEY = 'K3dRq1q9eN72GJDkgvyshFVwlqHHCyPI'
WIKI_PATH = '/home/deploy/wiki' WIKI_PATH = os.path.join(USER_HOME, 'wiki')
WIKI_HOME = 'home' WIKI_HOME = 'home'
ALLOW_ANON = True ALLOW_ANON = True
LOGIN_DISABLED = ALLOW_ANON LOGIN_DISABLED = ALLOW_ANON
ROOT_ENDPOINT = 'wiki.page' ROOT_ENDPOINT = 'wiki.page'
with open(os.path.join(os.path.dirname(__file__) + "/../../", 'config.json')) as f: with open(os.path.join(APP_PATH, 'config.json')) as f:
__settings = json.load(f) __settings = json.load(f)
globals().update(__settings) globals().update(__settings)
@ -54,5 +57,6 @@ RELATIVE_PATH = _url.path
if ENV != "DEV": if ENV != "DEV":
DEBUG = False DEBUG = False
ASSETS_DEBUG = False ASSETS_DEBUG = False
SQLALCHEMY_ECHO = False
MODULES = ['wiki', 'auth'] MODULES = ['wiki', 'auth']

View file

@ -33,7 +33,7 @@ def revert():
commit = request.form.get('commit') commit = request.form.get('commit')
cname = to_canonical(name) cname = to_canonical(name)
wiki.revert_page(name, commit, message="Reverting %s" % cname, wiki.revert_page(name, commit, message="Reverting %s" % cname,
username=g.current_user.username) username=current_user.username)
flash('Page reverted', 'success') flash('Page reverted', 'success')
return redirect(url_for('wiki.page', name=cname)) return redirect(url_for('wiki.page', name=cname))
@ -57,7 +57,7 @@ def edit(name):
wiki.write_page(edit_cname, wiki.write_page(edit_cname,
request.form['content'], request.form['content'],
message=request.form['message'], message=request.form['message'],
username=g.current_user.username) username=current_user.username)
else: else:
if data: if data:
name = remove_ext(data['name']) name = remove_ext(data['name'])
@ -83,7 +83,7 @@ def create(name):
request.form['content'], request.form['content'],
message=request.form['message'], message=request.form['message'],
create=True, create=True,
username=g.current_user.username) username=current_user.username)
else: else:
cname = to_canonical(name) if name else "" cname = to_canonical(name) if name else ""
if cname and wiki.get_page(cname): if cname and wiki.get_page(cname):

View file

@ -43,12 +43,12 @@
{% endif %} {% endif %}
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% if g.current_user.is_authenticated() %} {% if current_user.is_authenticated() %}
<li class="dropdown user-avatar"> <li class="dropdown user-avatar">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span> <span>
<img src="{{ g.current_user.avatar }}" class="menu-avatar"> <img src="{{ current_user.avatar }}" class="menu-avatar">
<span>{{ g.current_user.username }} <i class="icon-caret-down"></i></span> <span>{{ current_user.username }} <i class="icon-caret-down"></i></span>
</span> </span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">