From 564bde872d2f86eb34909be21a4db7195b511425 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Tue, 2 Sep 2014 09:29:04 -0500 Subject: [PATCH] WIP --- .gitignore | 3 ++- README.md | 9 ++++++++ Vagrantfile | 12 +++------- provision.sh | 44 ++++++++++++++++++++++++++++++++++++ manage.py => realms.py | 2 +- realms/__init__.py | 20 ++-------------- realms/config/__init__.py | 12 ++++++---- realms/modules/wiki/views.py | 6 ++--- realms/templates/layout.html | 6 ++--- 9 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 README.md create mode 100644 provision.sh rename manage.py => realms.py (82%) diff --git a/.gitignore b/.gitignore index a2df53d..bcfd54f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .vagrant -.virtualenvs +.venv .idea .webassets-cache *.pyc @@ -8,3 +8,4 @@ config.sls config.json realms/static/vendor realms/static/assets/* +wiki.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a50252 --- /dev/null +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile index e6f98eb..a8debac 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,7 +1,7 @@ VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = "ubuntu/trusty64" + config.vm.box = "ubuntu/trusty64" config.vm.provider :virtualbox do |vb| vb.name = "realms-wiki" @@ -9,16 +9,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| vb.cpus = 2 end - config.vm.synced_folder "srv/", "/srv/" - 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 + config.vm.provision "shell", path: "provision.sh" end Vagrant::Config.run do |config| config.vm.forward_port 80, 8080 - config.vm.forward_port 4567, 4567 + config.vm.forward_port 5000, 5000 end diff --git a/provision.sh b/provision.sh new file mode 100644 index 0000000..ebd814e --- /dev/null +++ b/provision.sh @@ -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 diff --git a/manage.py b/realms.py similarity index 82% rename from manage.py rename to realms.py index 12203fc..69c5b25 100644 --- a/manage.py +++ b/realms.py @@ -2,7 +2,7 @@ from gevent import wsgi from realms import config, app, manager 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 diff --git a/realms/__init__.py b/realms/__init__.py index 03f1f55..f0d4ac7 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -9,41 +9,25 @@ reload(sys) # noinspection PyUnresolvedReferences 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 sys import json import httplib import traceback 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.script import Manager from flask.ext.login import LoginManager, current_user from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.assets import Environment, Bundle from werkzeug.routing import BaseConverter -from werkzeug.utils import cached_property from werkzeug.exceptions import HTTPException from realms import config 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): - app_ctx_globals_class = AppCtxGlobals def __call__(self, environ, start_response): path_info = environ.get('PATH_INFO') @@ -104,7 +88,7 @@ class Application(Flask): 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'} def register(self, name, *args, **kwargs): @@ -139,7 +123,7 @@ def error_handler(e): else: status_code = httplib.INTERNAL_SERVER_ERROR 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']: response = { diff --git a/realms/config/__init__.py b/realms/config/__init__.py index ed6f953..65e8306 100644 --- a/realms/config/__init__.py +++ b/realms/config/__init__.py @@ -2,6 +2,9 @@ import os import json from urlparse import urlparse +APP_PATH = os.path.dirname(__file__) + "/../.." +USER_HOME = os.path.expanduser("~") + ENV = 'DEV' DEBUG = True @@ -12,7 +15,7 @@ SQLALCHEMY_ECHO = True PORT = 80 BASE_URL = 'http://realms.dev' -DB_URI = 'sqlite:////home/deploy/wiki.db' +DB_URI = 'sqlite:///%s/wiki.db' % USER_HOME CACHE_TYPE = 'simple' @@ -24,7 +27,7 @@ CACHE_REDIS_PORT = 6379 CACHE_REDIS_DB = '0' """ -RECAPTCHA_ENABLE = True +RECAPTCHA_ENABLE = False RECAPTCHA_USE_SSL = False RECAPTCHA_PUBLIC_KEY = "6LfYbPkSAAAAAB4a2lG2Y_Yjik7MG9l4TDzyKUao" RECAPTCHA_PRIVATE_KEY = "6LfYbPkSAAAAAG-KlkwjZ8JLWgwc9T0ytkN7lWRE" @@ -32,14 +35,14 @@ RECAPTCHA_OPTIONS = {} SECRET_KEY = 'K3dRq1q9eN72GJDkgvyshFVwlqHHCyPI' -WIKI_PATH = '/home/deploy/wiki' +WIKI_PATH = os.path.join(USER_HOME, 'wiki') WIKI_HOME = 'home' ALLOW_ANON = True LOGIN_DISABLED = ALLOW_ANON 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) globals().update(__settings) @@ -54,5 +57,6 @@ RELATIVE_PATH = _url.path if ENV != "DEV": DEBUG = False ASSETS_DEBUG = False + SQLALCHEMY_ECHO = False MODULES = ['wiki', 'auth'] diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index 43128fa..8176654 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -33,7 +33,7 @@ def revert(): commit = request.form.get('commit') cname = to_canonical(name) wiki.revert_page(name, commit, message="Reverting %s" % cname, - username=g.current_user.username) + username=current_user.username) flash('Page reverted', 'success') return redirect(url_for('wiki.page', name=cname)) @@ -57,7 +57,7 @@ def edit(name): wiki.write_page(edit_cname, request.form['content'], message=request.form['message'], - username=g.current_user.username) + username=current_user.username) else: if data: name = remove_ext(data['name']) @@ -83,7 +83,7 @@ def create(name): request.form['content'], message=request.form['message'], create=True, - username=g.current_user.username) + username=current_user.username) else: cname = to_canonical(name) if name else "" if cname and wiki.get_page(cname): diff --git a/realms/templates/layout.html b/realms/templates/layout.html index 9a8a78d..e8a7789 100644 --- a/realms/templates/layout.html +++ b/realms/templates/layout.html @@ -43,12 +43,12 @@ {% endif %}